code improvements, fix claymoreArrow cash, faster claymoreArrow despawn
This commit is contained in:
parent
4959e3e0fa
commit
57eb7e5442
@ -38,7 +38,7 @@ mod_name=Enhanced Explosives
|
||||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||
mod_license=All Rights Reserved
|
||||
# The mod version. See https://semver.org/
|
||||
mod_version=0.12.0
|
||||
mod_version=0.12.1
|
||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||
# This should match the base package used for the mod sources.
|
||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.jenny.enhancedexplosives;
|
||||
|
||||
import com.jenny.enhancedexplosives.blocks.blocks;
|
||||
import com.jenny.enhancedexplosives.config.ConfigCommon;
|
||||
import com.jenny.enhancedexplosives.particles.particles;
|
||||
import com.jenny.enhancedexplosives.config.ConfigClient;
|
||||
import com.jenny.enhancedexplosives.config.ConfigCommon;
|
||||
import com.jenny.enhancedexplosives.entities.entities;
|
||||
import com.jenny.enhancedexplosives.items.items;
|
||||
import com.jenny.enhancedexplosives.particles.particles;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
@ -27,6 +27,7 @@ public class EnhancedExplosives {
|
||||
public static final String MODID = "enhancedexplosives";
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
public EnhancedExplosives() {
|
||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
|
||||
@ -58,6 +59,7 @@ public class EnhancedExplosives {
|
||||
@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
|
||||
public static class ClientModEvents {
|
||||
|
||||
@SuppressWarnings("removal")
|
||||
@SubscribeEvent
|
||||
public static void onClientSetup(FMLClientSetupEvent event) {
|
||||
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ConfigClient.SPEC);
|
||||
|
@ -1,16 +1,19 @@
|
||||
package com.jenny.enhancedexplosives.datagen;
|
||||
|
||||
import com.jenny.enhancedexplosives.blocks.blocks;
|
||||
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.block.*;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraftforge.client.model.generators.BlockStateProvider;
|
||||
import net.minecraftforge.client.model.generators.ConfiguredModel;
|
||||
import net.minecraftforge.client.model.generators.ModelFile;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
import net.minecraftforge.client.model.generators.ModelFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.jenny.enhancedexplosives.EnhancedExplosives.MODID;
|
||||
|
||||
@ -37,20 +40,20 @@ public class ModBlockStateProvider extends BlockStateProvider {
|
||||
SideOnlyTNT(blocks.TNT_HOMING);
|
||||
}
|
||||
|
||||
private void blockWithItem(RegistryObject<Block> blockRegistryObject) {
|
||||
private void blockWithItem(@NotNull RegistryObject<Block> blockRegistryObject) {
|
||||
simpleBlockWithItem(blockRegistryObject.get(), cubeAll(blockRegistryObject.get()));
|
||||
}
|
||||
|
||||
private void SideTop(RegistryObject<Block> blockRegistryObject) {
|
||||
private void SideTop(@NotNull RegistryObject<Block> blockRegistryObject) {
|
||||
simpleBlockWithItem(blockRegistryObject.get(), topSide(blockRegistryObject.get()));
|
||||
}
|
||||
|
||||
private void blockItem(RegistryObject<Block> blockRegistryObject) {
|
||||
private void blockItem(@NotNull RegistryObject<Block> blockRegistryObject) {
|
||||
simpleBlockItem(blockRegistryObject.get(), new ModelFile.UncheckedModelFile(MODID +
|
||||
":block/" + ForgeRegistries.BLOCKS.getKey(blockRegistryObject.get()).getPath()));
|
||||
":block/" + Objects.requireNonNull(ForgeRegistries.BLOCKS.getKey(blockRegistryObject.get())).getPath()));
|
||||
}
|
||||
|
||||
private void topBottom2Sides(RegistryObject<Block> blockRegistryObject) {
|
||||
private void topBottom2Sides(@NotNull RegistryObject<Block> blockRegistryObject) {
|
||||
simpleBlockWithItem(blockRegistryObject.get(), northEastTopBottom(blockRegistryObject.get()));
|
||||
}
|
||||
|
||||
@ -58,22 +61,22 @@ public class ModBlockStateProvider extends BlockStateProvider {
|
||||
return ForgeRegistries.BLOCKS.getKey(block);
|
||||
}
|
||||
|
||||
private String name(Block block) {
|
||||
private @NotNull String name(Block block) {
|
||||
return key(block).getPath();
|
||||
}
|
||||
|
||||
private ResourceLocation extend(ResourceLocation rl, String suffix) {
|
||||
private ResourceLocation extend(@NotNull ResourceLocation rl, String suffix) {
|
||||
return new ResourceLocation(rl.getNamespace(), rl.getPath() + suffix);
|
||||
}
|
||||
|
||||
public void sideTopBottom(RegistryObject<Block> blockRegistryObject) {
|
||||
public void sideTopBottom(@NotNull RegistryObject<Block> blockRegistryObject) {
|
||||
Block block = blockRegistryObject.get();
|
||||
ModelFile model = models().cubeBottomTop(name(block), extend(blockTexture(block), "_side"), extend(blockTexture(block), "_bottom"), extend(blockTexture(block), "_top"));
|
||||
this.getVariantBuilder(block).forAllStates(blockState -> ConfiguredModel.builder().modelFile(model).build());
|
||||
simpleBlockItem(block, model);
|
||||
}
|
||||
|
||||
public void SideOnlyTNT(RegistryObject<Block> blockRegistryObject) {
|
||||
public void SideOnlyTNT(@NotNull RegistryObject<Block> blockRegistryObject) {
|
||||
Block block = blockRegistryObject.get();
|
||||
ModelFile model = models().cubeBottomTop(name(block), extend(blockTexture(block), "_side"), extend(blockTexture(Blocks.TNT), "_bottom"), extend(blockTexture(Blocks.TNT), "_top"));
|
||||
this.getVariantBuilder(block).forAllStates(blockState -> ConfiguredModel.builder().modelFile(model).build());
|
||||
|
@ -1,11 +1,9 @@
|
||||
package com.jenny.enhancedexplosives.datagen;
|
||||
|
||||
import com.jenny.enhancedexplosives.items.items;
|
||||
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraftforge.client.model.generators.ItemModelBuilder;
|
||||
import net.minecraftforge.client.model.generators.ItemModelProvider;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
@ -25,8 +23,8 @@ public class ModItemModelProvider extends ItemModelProvider {
|
||||
simpleItem(items.TUNNEL_ARROW);
|
||||
}
|
||||
|
||||
private ItemModelBuilder simpleItem(RegistryObject<Item> item) {
|
||||
return withExistingParent(item.getId().getPath(),
|
||||
private void simpleItem(RegistryObject<Item> item) {
|
||||
withExistingParent(item.getId().getPath(),
|
||||
new ResourceLocation("item/generated")).texture("layer0",
|
||||
new ResourceLocation(MODID,"item/" + item.getId().getPath()));
|
||||
}
|
||||
|
@ -1,38 +1,14 @@
|
||||
package com.jenny.enhancedexplosives.entities.arrows;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
import net.minecraft.network.syncher.SynchedEntityData;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.projectile.AbstractArrow;
|
||||
import net.minecraft.world.entity.projectile.Arrow;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.alchemy.Potion;
|
||||
import net.minecraft.world.item.alchemy.PotionUtils;
|
||||
import net.minecraft.world.item.alchemy.Potions;
|
||||
import net.minecraft.world.level.Level;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
public class baseArrow extends AbstractArrow {
|
||||
private static final int EXPOSED_POTION_DECAY_TIME = 600;
|
||||
private static final int NO_EFFECT_COLOR = -1;
|
||||
private static final EntityDataAccessor<Integer> ID_EFFECT_COLOR = SynchedEntityData.defineId(Arrow.class, EntityDataSerializers.INT);
|
||||
private static final byte EVENT_POTION_PUFF = 0;
|
||||
private Potion potion = Potions.EMPTY;
|
||||
private final Set<MobEffectInstance> effects = Sets.newHashSet();
|
||||
private boolean fixedColor;
|
||||
private int tick = 0;
|
||||
|
||||
public baseArrow(EntityType<? extends baseArrow> pEntityType, Level pLevel) {
|
||||
@ -44,190 +20,22 @@ public class baseArrow extends AbstractArrow {
|
||||
}
|
||||
|
||||
public baseArrow(Level pLevel, LivingEntity pShooter, EntityType<? extends baseArrow> pEntityType) {
|
||||
super(pEntityType, pShooter, pLevel);
|
||||
}
|
||||
|
||||
public void setEffectsFromItem(ItemStack pStack) {
|
||||
if (pStack.is(Items.TIPPED_ARROW)) {
|
||||
this.potion = PotionUtils.getPotion(pStack);
|
||||
Collection<MobEffectInstance> collection = PotionUtils.getCustomEffects(pStack);
|
||||
if (!collection.isEmpty()) {
|
||||
for(MobEffectInstance mobeffectinstance : collection) {
|
||||
this.effects.add(new MobEffectInstance(mobeffectinstance));
|
||||
}
|
||||
}
|
||||
|
||||
int i = getCustomColor(pStack);
|
||||
if (i == -1) {
|
||||
this.updateColor();
|
||||
} else {
|
||||
this.setFixedColor(i);
|
||||
}
|
||||
} else if (pStack.is(Items.ARROW)) {
|
||||
this.potion = Potions.EMPTY;
|
||||
this.effects.clear();
|
||||
this.entityData.set(ID_EFFECT_COLOR, -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static int getCustomColor(ItemStack pStack) {
|
||||
CompoundTag compoundtag = pStack.getTag();
|
||||
return compoundtag != null && compoundtag.contains("CustomPotionColor", 99) ? compoundtag.getInt("CustomPotionColor") : -1;
|
||||
}
|
||||
|
||||
private void updateColor() {
|
||||
this.fixedColor = false;
|
||||
if (this.potion == Potions.EMPTY && this.effects.isEmpty()) {
|
||||
this.entityData.set(ID_EFFECT_COLOR, -1);
|
||||
} else {
|
||||
this.entityData.set(ID_EFFECT_COLOR, PotionUtils.getColor(PotionUtils.getAllEffects(this.potion, this.effects)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void addEffect(MobEffectInstance pEffectInstance) {
|
||||
this.effects.add(pEffectInstance);
|
||||
this.getEntityData().set(ID_EFFECT_COLOR, PotionUtils.getColor(PotionUtils.getAllEffects(this.potion, this.effects)));
|
||||
}
|
||||
|
||||
protected void defineSynchedData() {
|
||||
super.defineSynchedData();
|
||||
this.entityData.define(ID_EFFECT_COLOR, -1);
|
||||
super(pEntityType, pLevel);
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (this.level().isClientSide) {
|
||||
if (this.inGround) {
|
||||
if (this.inGroundTime % 5 == 0) {
|
||||
this.makeParticle(1);
|
||||
}
|
||||
} else {
|
||||
if (!this.inGround) {
|
||||
spawnParticles(0);
|
||||
}
|
||||
this.tick++;
|
||||
} else if (this.inGround && this.inGroundTime != 0 && !this.effects.isEmpty() && this.inGroundTime >= 600) {
|
||||
this.level().broadcastEntityEvent(this, (byte)0);
|
||||
this.potion = Potions.EMPTY;
|
||||
this.effects.clear();
|
||||
this.entityData.set(ID_EFFECT_COLOR, -1);
|
||||
}
|
||||
}
|
||||
|
||||
private void makeParticle(int pParticleAmount) {
|
||||
int i = this.getColor();
|
||||
if (i != -1 && pParticleAmount > 0) {
|
||||
double d0 = (double)(i >> 16 & 255) / 255.0D;
|
||||
double d1 = (double)(i >> 8 & 255) / 255.0D;
|
||||
double d2 = (double)(i >> 0 & 255) / 255.0D;
|
||||
|
||||
for(int j = 0; j < pParticleAmount; ++j) {
|
||||
this.level().addParticle(ParticleTypes.ENTITY_EFFECT, this.getRandomX(0.5D), this.getRandomY(), this.getRandomZ(0.5D), d0, d1, d2);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return this.entityData.get(ID_EFFECT_COLOR);
|
||||
}
|
||||
|
||||
private void setFixedColor(int pFixedColor) {
|
||||
this.fixedColor = true;
|
||||
this.entityData.set(ID_EFFECT_COLOR, pFixedColor);
|
||||
}
|
||||
|
||||
public void addAdditionalSaveData(@NotNull CompoundTag pCompound) {
|
||||
super.addAdditionalSaveData(pCompound);
|
||||
if (this.potion != Potions.EMPTY) {
|
||||
pCompound.putString("Potion", BuiltInRegistries.POTION.getKey(this.potion).toString());
|
||||
}
|
||||
|
||||
if (this.fixedColor) {
|
||||
pCompound.putInt("Color", this.getColor());
|
||||
}
|
||||
|
||||
if (!this.effects.isEmpty()) {
|
||||
ListTag listtag = new ListTag();
|
||||
|
||||
for(MobEffectInstance mobeffectinstance : this.effects) {
|
||||
listtag.add(mobeffectinstance.save(new CompoundTag()));
|
||||
}
|
||||
|
||||
pCompound.put("CustomPotionEffects", listtag);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void readAdditionalSaveData(@NotNull CompoundTag pCompound) {
|
||||
super.readAdditionalSaveData(pCompound);
|
||||
if (pCompound.contains("Potion", 8)) {
|
||||
this.potion = PotionUtils.getPotion(pCompound);
|
||||
}
|
||||
|
||||
for(MobEffectInstance mobeffectinstance : PotionUtils.getCustomEffects(pCompound)) {
|
||||
this.addEffect(mobeffectinstance);
|
||||
}
|
||||
|
||||
if (pCompound.contains("Color", 99)) {
|
||||
this.setFixedColor(pCompound.getInt("Color"));
|
||||
} else {
|
||||
this.updateColor();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void doPostHurtEffects(@NotNull LivingEntity pLiving) {
|
||||
super.doPostHurtEffects(pLiving);
|
||||
Entity entity = this.getEffectSource();
|
||||
|
||||
for(MobEffectInstance mobeffectinstance : this.potion.getEffects()) {
|
||||
pLiving.addEffect(new MobEffectInstance(mobeffectinstance.getEffect(), Math.max(mobeffectinstance.mapDuration((p_268168_) -> {
|
||||
return p_268168_ / 8;
|
||||
}), 1), mobeffectinstance.getAmplifier(), mobeffectinstance.isAmbient(), mobeffectinstance.isVisible()), entity);
|
||||
}
|
||||
|
||||
if (!this.effects.isEmpty()) {
|
||||
for(MobEffectInstance mobeffectinstance1 : this.effects) {
|
||||
pLiving.addEffect(mobeffectinstance1, entity);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected ItemStack getPickupItem() {
|
||||
if (this.effects.isEmpty() && this.potion == Potions.EMPTY) {
|
||||
return new ItemStack(Items.ARROW);
|
||||
} else {
|
||||
ItemStack itemstack = new ItemStack(Items.TIPPED_ARROW);
|
||||
PotionUtils.setPotion(itemstack, this.potion);
|
||||
PotionUtils.setCustomEffects(itemstack, this.effects);
|
||||
if (this.fixedColor) {
|
||||
itemstack.getOrCreateTag().putInt("CustomPotionColor", this.getColor());
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
||||
|
||||
public void handleEntityEvent(byte pId) {
|
||||
if (pId == 0) {
|
||||
int i = this.getColor();
|
||||
if (i != -1) {
|
||||
double d0 = (double)(i >> 16 & 255) / 255.0D;
|
||||
double d1 = (double)(i >> 8 & 255) / 255.0D;
|
||||
double d2 = (double)(i >> 0 & 255) / 255.0D;
|
||||
|
||||
for(int j = 0; j < 20; ++j) {
|
||||
this.level().addParticle(ParticleTypes.ENTITY_EFFECT, this.getRandomX(0.5D), this.getRandomY(), this.getRandomZ(0.5D), d0, d1, d2);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
super.handleEntityEvent(pId);
|
||||
}
|
||||
|
||||
return new ItemStack(Items.ARROW);
|
||||
}
|
||||
|
||||
public void spawnParticles(float partialTicks) {
|
||||
|
@ -6,12 +6,14 @@ import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class claymoreArrow extends baseArrow{
|
||||
private final int r = level().isClientSide ? 0 : level().getRandom().nextInt(0, 20);
|
||||
|
||||
public claymoreArrow(EntityType<claymoreArrow> pEntityType, Level pLevel) {
|
||||
super(pEntityType, pLevel);
|
||||
|
||||
}
|
||||
|
||||
public claymoreArrow(@NotNull Level pLevel, @NotNull LivingEntity pShooter) {
|
||||
@ -23,6 +25,14 @@ public class claymoreArrow extends baseArrow{
|
||||
pTarget.hurt(damageSources().mobProjectile(this, (LivingEntity) getOwner()), 15);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
if (!level().isClientSide && this.inGroundTime > 20 + r) {
|
||||
discard();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected ItemStack getPickupItem() {
|
||||
|
@ -11,9 +11,9 @@ import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class tunnelArrow extends baseArrow{
|
||||
protected static int explosionCount = 12;
|
||||
protected static int spacing = 2;
|
||||
protected static float power = 8;
|
||||
protected static final int explosionCount = 12;
|
||||
protected static final int spacing = 2;
|
||||
protected static final float power = 8;
|
||||
|
||||
public tunnelArrow(EntityType<tunnelArrow> pEntityType, Level pLevel) {
|
||||
super(pEntityType, pLevel);
|
||||
|
@ -34,8 +34,7 @@ public class repulsivePrimedTNT extends basePrimedTNT {
|
||||
double dist = getTargetDist(target);
|
||||
float speed = getSpeed();
|
||||
Vec3 mult = new Vec3(speed / dist, speed / dist, speed / dist);
|
||||
Vec3 ret = target.position().subtract(this.position()).normalize().multiply(mult);
|
||||
return ret;
|
||||
return target.position().subtract(this.position()).normalize().multiply(mult);
|
||||
}
|
||||
|
||||
public double getTargetDist(Entity target) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user