rename to "Enhanced Explosives"

This commit is contained in:
Jenny committed 2025-01-25 03:51:55 +01:00
1 parent c9fbf66fd5
commit d812e54058
88 files changed
+212 -218

No files matched your search

@@ -0,0 +1,231 @@
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;
public baseArrow(EntityType<? extends baseArrow> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
}
public baseArrow(Level pLevel, double pX, double pY, double pZ, EntityType<? extends baseArrow> pEntityType) {
super(pEntityType, pX, pY, pZ, pLevel);
}
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);
}
public void tick() {
super.tick();
if (this.level().isClientSide) {
if (this.inGround) {
if (this.inGroundTime % 5 == 0) {
this.makeParticle(1);
}
} else {
this.makeParticle(2);
}
} 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);
}
}
}
@@ -0,0 +1,57 @@
package com.jenny.enhancedexplosives.entities.arrows;
import com.jenny.enhancedexplosives.entities.entities;
import com.jenny.enhancedexplosives.items.items;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.util.RandomSource;
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 net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
public class carpetArrow extends baseArrow {
private int tick = 0;
private Vec3 pos = position();
public final int childCount = 32;
public carpetArrow(EntityType<carpetArrow> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
}
public carpetArrow(Level pLevel, LivingEntity pShooter) {
super(pLevel, pShooter, entities.ARROW_CARPET.get());
}
@Override
public void tick() {
pos = position();
super.tick();
if (level().isClientSide()) {
level().addParticle(ParticleTypes.SMOKE, this.getX(), this.getY(), this.getZ(), 0.0D, 0.0D, 0.0D);
}
tick++;
if (pos.y > position().y) {
spawnChildren(childCount);
discard();
}
}
protected void spawnChildren(int count) {
Vec3 delta = getDeltaMovement();
RandomSource rng = level().getRandom();
for (int i = 0; i < count; i++) {
concussiveArrow arrow = new concussiveArrow(entities.ARROW_CONCUSSIVE.get(), level());
Vec3 move = delta.add((float) rng.nextInt(-10, 11) / 10, 0, (float) rng.nextInt(-10, 11) / 10);
arrow.setPos(position());
arrow.setDeltaMovement(delta.add(move.multiply(0.2, 0, 0.2)));
level().addFreshEntity(arrow);
}
}
@NotNull
protected ItemStack getPickupItem() {
return new ItemStack(items.CARPET_ARROW.get());
}
}
@@ -0,0 +1,45 @@
package com.jenny.enhancedexplosives.entities.arrows;
import com.jenny.enhancedexplosives.entities.entities;
import com.jenny.enhancedexplosives.items.items;
import net.minecraft.core.particles.ParticleTypes;
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 concussiveArrow extends baseArrow{
public concussiveArrow(EntityType<concussiveArrow> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
}
public concussiveArrow(Level pLevel, LivingEntity pShooter) {
super(pLevel, pShooter, entities.ARROW_CONCUSSIVE.get());
}
@Override
public void tick() {
super.tick();
if (level().isClientSide()) {
level().addParticle(ParticleTypes.SMOKE, this.getX(), this.getY(), this.getZ(), 0.0D, 0.0D, 0.0D);
}
if (this.inGround) {
this.level().explode(this, getX(), getY(), getZ(), 8.0f, Level.ExplosionInteraction.NONE);
//this.level().explode(this, null, new NilExplosionCalculator(), this.getX(), this.getY(), this.getZ(), 8, false, Level.ExplosionInteraction.NONE);
this.discard();
}
}
@Override
protected void doPostHurtEffects(@NotNull LivingEntity pTarget) {
this.level().explode(this, getX(), getY(), getZ(), 8.0f, Level.ExplosionInteraction.NONE);
//this.level().explode(this, null, new NilExplosionCalculator(), this.getX(), this.getY(), this.getZ(), 8, false, Level.ExplosionInteraction.NONE);
this.discard();
}
@NotNull
protected ItemStack getPickupItem() {
return new ItemStack(items.CONCUSSIVE_ARROW.get());
}
}
@@ -0,0 +1,44 @@
package com.jenny.enhancedexplosives.entities.arrows;
import com.jenny.enhancedexplosives.items.items;
import com.jenny.enhancedexplosives.entities.entities;
import net.minecraft.core.particles.ParticleTypes;
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 tntArrow extends baseArrow {
public tntArrow(EntityType<tntArrow> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
}
public tntArrow(Level pLevel, LivingEntity pShooter) {
super(pLevel, pShooter, entities.ARROW_TNT.get());
}
@Override
public void tick() {
super.tick();
if (level().isClientSide()) {
level().addParticle(ParticleTypes.SMOKE, this.getX(), this.getY(), this.getZ(), 0.0D, 0.0D, 0.0D);
}
if (this.inGround) {
this.level().explode(this, this.getX(), this.getY(), this.getZ(), 2, Level.ExplosionInteraction.TNT);
this.discard();
}
}
@Override
protected void doPostHurtEffects(@NotNull LivingEntity pTarget) {
this.level().explode(this, this.getX(), this.getY(), this.getZ(), 2, Level.ExplosionInteraction.TNT);
this.discard();
}
@NotNull
protected ItemStack getPickupItem() {
return new ItemStack(items.TNT_ARROW.get());
}
}
@@ -0,0 +1,66 @@
package com.jenny.enhancedexplosives.entities.client;
import com.jenny.enhancedexplosives.blocks.blocks;
import com.jenny.enhancedexplosives.entities.tnt.basePrimedTNT;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.TntMinecartRenderer;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import org.jetbrains.annotations.NotNull;
public class BaseTNTRenderer extends EntityRenderer<basePrimedTNT> {
private final BlockRenderDispatcher blockRenderer;
public BaseTNTRenderer(EntityRendererProvider.Context pContext) {
super(pContext);
this.shadowRadius = 0.5F;
this.blockRenderer = pContext.getBlockRenderDispatcher();
}
public void render(basePrimedTNT pEntity, float pEntityYaw, float pPartialTicks, PoseStack pPoseStack, @NotNull MultiBufferSource pBuffer, int pPackedLight) {
pPoseStack.pushPose();
pPoseStack.translate(0.0F, 0.5F, 0.0F);
int i = pEntity.getFuse();
if ((float)i - pPartialTicks + 1.0F < 10.0F) {
float f = 1.0F - ((float)i - pPartialTicks + 1.0F) / 10.0F;
f = Mth.clamp(f, 0.0F, 1.0F);
f *= f;
f *= f;
float f1 = 1.0F + f * 0.3F;
pPoseStack.scale(f1, f1, f1);
}
String renderID = pEntity.getRenderID();
if (renderID == null) {
renderID = "";
}
Block block = switch (renderID) {
case "stronger_8" -> blocks.TNT_8.get();
case "stronger_16" -> blocks.TNT_16.get();
case "stronger_32" -> blocks.TNT_32.get();
case "stronger_64" -> blocks.TNT_64.get();
case "stronger_128" -> blocks.TNT_128.get();
case "homing" -> blocks.TNT_HOMING.get();
default -> Blocks.NETHER_PORTAL; // placeholder for debugging
};
pPoseStack.mulPose(Axis.YP.rotationDegrees(-90.0F));
pPoseStack.translate(-0.5F, -0.5F, 0.5F);
pPoseStack.mulPose(Axis.YP.rotationDegrees(90.0F));
TntMinecartRenderer.renderWhiteSolidBlock(this.blockRenderer, block.defaultBlockState(), pPoseStack, pBuffer, pPackedLight, i / 5 % 2 == 0);
pPoseStack.popPose();
super.render(pEntity, pEntityYaw, pPartialTicks, pPoseStack, pBuffer, pPackedLight);
}
@NotNull
public ResourceLocation getTextureLocation(@NotNull basePrimedTNT pEntity) {
return TextureAtlas.LOCATION_BLOCKS;
}
}
@@ -0,0 +1,44 @@
package com.jenny.enhancedexplosives.entities.client;
import com.jenny.enhancedexplosives.entities.arrows.baseArrow;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.TntMinecartRenderer;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Blocks;
import org.jetbrains.annotations.NotNull;
public class TNTArrowRenderer extends EntityRenderer<baseArrow> {
private final BlockRenderDispatcher blockRenderer;
private float i = 0;
public TNTArrowRenderer(EntityRendererProvider.Context pContext) {
super(pContext);
this.shadowRadius = 0.0F;
this.blockRenderer = pContext.getBlockRenderDispatcher();
}
public void render(@NotNull baseArrow pEntity, float pEntityYaw, float pPartialTicks, PoseStack pPoseStack, @NotNull MultiBufferSource pBuffer, int pPackedLight) {
pPoseStack.pushPose();
pPoseStack.translate(0.0F, 0.5F, 0.0F);
pPoseStack.scale(0.5f, 0.5f, 0.5f);
i += 0.1f;
pPoseStack.mulPose(Axis.YP.rotationDegrees(-90.0F));
pPoseStack.translate(-0.5F, -0.5F, 0.5F);
pPoseStack.mulPose(Axis.YP.rotationDegrees(90.0F));
TntMinecartRenderer.renderWhiteSolidBlock(this.blockRenderer, Blocks.TNT.defaultBlockState(), pPoseStack, pBuffer, pPackedLight, Math.round(Math.sin(i)) == 0);
pPoseStack.popPose();
super.render(pEntity, pEntityYaw, pPartialTicks, pPoseStack, pBuffer, pPackedLight);
}
@NotNull
public ResourceLocation getTextureLocation(@NotNull baseArrow pEntity) {
return TextureAtlas.LOCATION_BLOCKS;
}
}
@@ -0,0 +1,53 @@
package com.jenny.enhancedexplosives.entities.client;
import com.jenny.enhancedexplosives.entities.tnt.basePrimedTNT;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
import net.minecraft.client.renderer.entity.EntityRenderer;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.client.renderer.entity.TntMinecartRenderer;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.level.block.Blocks;
import org.jetbrains.annotations.NotNull;
public class clusterTNTRenderer extends EntityRenderer<basePrimedTNT> {
private final BlockRenderDispatcher blockRenderer;
public clusterTNTRenderer(EntityRendererProvider.Context pContext) {
super(pContext);
this.shadowRadius = 0.5F;
this.blockRenderer = pContext.getBlockRenderDispatcher();
}
public void render(basePrimedTNT pEntity, float pEntityYaw, float pPartialTicks, PoseStack pPoseStack, @NotNull MultiBufferSource pBuffer, int pPackedLight) {
pPoseStack.pushPose();
pPoseStack.translate(0.0F, 0.5F, 0.0F);
int i = pEntity.getFuse();
if ((float)i - pPartialTicks + 1.0F < 10.0F) {
float f = 1.0F - ((float)i - pPartialTicks + 1.0F) / 10.0F;
f = Mth.clamp(f, 0.0F, 1.0F);
f *= f;
f *= f;
float f1 = 0.5f + f * 0.3F;
pPoseStack.scale(f1, f1, f1);
}
else {
pPoseStack.scale(0.5f, 0.5f, 0.5f);
}
pPoseStack.mulPose(Axis.YP.rotationDegrees(-90.0F));
pPoseStack.translate(-0.5F, -0.5F, 0.5F);
pPoseStack.mulPose(Axis.YP.rotationDegrees(90.0F));
TntMinecartRenderer.renderWhiteSolidBlock(this.blockRenderer, Blocks.TNT.defaultBlockState(), pPoseStack, pBuffer, pPackedLight, i / 5 % 2 == 0);
pPoseStack.popPose();
super.render(pEntity, pEntityYaw, pPartialTicks, pPoseStack, pBuffer, pPackedLight);
}
public @NotNull ResourceLocation getTextureLocation(@NotNull basePrimedTNT pEntity) {
return TextureAtlas.LOCATION_BLOCKS;
}
}
@@ -0,0 +1,82 @@
package com.jenny.enhancedexplosives.entities;
import com.jenny.enhancedexplosives.entities.arrows.*;
import com.jenny.enhancedexplosives.entities.client.BaseTNTRenderer;
import com.jenny.enhancedexplosives.entities.client.TNTArrowRenderer;
import com.jenny.enhancedexplosives.entities.client.clusterTNTRenderer;
import com.jenny.enhancedexplosives.entities.throwable.dynamite;
import com.jenny.enhancedexplosives.entities.tnt.*;
import net.minecraft.client.renderer.entity.EntityRenderers;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import static com.jenny.enhancedexplosives.EnhancedExplosives.MODID;
public class entities {
public static final DeferredRegister<EntityType<?>> ENTITY_TYPES =
DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, MODID);
public static final RegistryObject<EntityType<homingPrimedTNT>> TNT_HOMING =
ENTITY_TYPES.register("tnt_homing", () -> EntityType.Builder.<homingPrimedTNT>of(homingPrimedTNT::new, MobCategory.MISC)
.sized(0.98F, 0.7F).fireImmune().clientTrackingRange(8).build("tnt_homing"));
public static final RegistryObject<EntityType<StrongerPrimedTNT>> TNT_STRONGER =
ENTITY_TYPES.register("tnt_stronger", () -> EntityType.Builder.<StrongerPrimedTNT>of(StrongerPrimedTNT::new, MobCategory.MISC)
.sized(0.98F, 0.7F).fireImmune().clientTrackingRange(8).build("tnt_stronger"));
public static final RegistryObject<EntityType<ClusterPrimedTNT>> TNT_CLUSTER =
ENTITY_TYPES.register("tnt_cluster", () -> EntityType.Builder.<ClusterPrimedTNT>of(ClusterPrimedTNT::new, MobCategory.MISC)
.sized(0.48F, 0.48F).fireImmune().clientTrackingRange(8).build("tnt_cluster"));
public static final RegistryObject<EntityType<blackHolePrimedTNT>> TNT_BLACK_HOLE =
ENTITY_TYPES.register("tnt_blackhole", () -> EntityType.Builder.<blackHolePrimedTNT>of(blackHolePrimedTNT::new, MobCategory.MISC)
.sized(0.98F, 0.7F).fireImmune().clientTrackingRange(8).build("tnt_blackhole"));
public static final RegistryObject<EntityType<selectivePrimedTNT>> TNT_SELECTIVE =
ENTITY_TYPES.register("tnt_selective", () -> EntityType.Builder.<selectivePrimedTNT>of(selectivePrimedTNT::new, MobCategory.MISC)
.sized(0.98F, 0.7F).fireImmune().clientTrackingRange(8).build("tnt_selective"));
public static final RegistryObject<EntityType<claymorePrimedTNT>> TNT_CLAYMORE =
ENTITY_TYPES.register("tnt_claymore", () -> EntityType.Builder.<claymorePrimedTNT>of(claymorePrimedTNT::new, MobCategory.MISC)
.sized(0.98F, 0.7F).fireImmune().clientTrackingRange(8).build("tnt_claymore"));
public static final RegistryObject<EntityType<tntArrow>> ARROW_TNT =
ENTITY_TYPES.register("arrow_tnt", () -> EntityType.Builder.<tntArrow>of(tntArrow::new, MobCategory.MISC)
.sized(0.48F, 0.48F).clientTrackingRange(64).build("arrow_tnt"));
public static final RegistryObject<EntityType<concussiveArrow>> ARROW_CONCUSSIVE =
ENTITY_TYPES.register("arrow_concussive", () -> EntityType.Builder.<concussiveArrow>of(concussiveArrow::new, MobCategory.MISC)
.sized(0.48F, 0.48F).clientTrackingRange(64).build("arrow_concussive"));
public static final RegistryObject<EntityType<carpetArrow>> ARROW_CARPET =
ENTITY_TYPES.register("arrow_carpet", () -> EntityType.Builder.<carpetArrow>of(carpetArrow::new, MobCategory.MISC)
.sized(0.48F, 0.48F).clientTrackingRange(64).build("arrow_carpet"));
public static final RegistryObject<EntityType<dynamite>> DYNAMITE =
ENTITY_TYPES.register("dynamite", () -> EntityType.Builder.<dynamite>of(dynamite::new, MobCategory.MISC)
.sized(0.48F, 0.48F).clientTrackingRange(64).build("dynamite"));
public static void register(IEventBus eventBus) {
ENTITY_TYPES.register(eventBus);
}
public static void registerRenderers () {
EntityRenderers.register(TNT_STRONGER.get(), BaseTNTRenderer::new);
EntityRenderers.register(TNT_HOMING.get(), BaseTNTRenderer::new);
EntityRenderers.register(TNT_BLACK_HOLE.get(), BaseTNTRenderer::new);
EntityRenderers.register(TNT_CLAYMORE.get(), BaseTNTRenderer::new);
EntityRenderers.register(TNT_SELECTIVE.get(), BaseTNTRenderer::new);
EntityRenderers.register(TNT_CLUSTER.get(), clusterTNTRenderer::new);
EntityRenderers.register(ARROW_TNT.get(), TNTArrowRenderer::new);
EntityRenderers.register(ARROW_CONCUSSIVE.get(), TNTArrowRenderer::new);
EntityRenderers.register(ARROW_CARPET.get(), TNTArrowRenderer::new);
EntityRenderers.register(DYNAMITE.get(), clusterTNTRenderer::new);
}
}
@@ -0,0 +1,62 @@
package com.jenny.enhancedexplosives.entities.throwable;
import com.jenny.enhancedexplosives.entities.entities;
import com.jenny.enhancedexplosives.entities.tnt.basePrimedTNT;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import javax.annotation.Nullable;
public class dynamite extends basePrimedTNT {
public dynamite (Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse) {
super(entities.DYNAMITE.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power, "dynamite");
}
public dynamite(EntityType<dynamite> entityType, Level level) {
super(entityType, level, null);
this.setRenderID("dynamite");
}
@Override
public void tick() {
if (!this.isNoGravity()) {
this.setDeltaMovement(this.getDeltaMovement().add(0.0D, -0.04D, 0.0D));
}
Vec3 beforeMove = getDeltaMovement();
this.move(MoverType.SELF, this.getDeltaMovement());
this.setDeltaMovement(this.getDeltaMovement().scale(0.98D));
if (this.onGround()) {
this.setDeltaMovement(this.getDeltaMovement().multiply(0.7D, 0, 0.7D).add(0, (-beforeMove.y) * 0.5, 0));
}
int i = this.getFuse() - 1;
this.setFuse(i);
if (i <= 0) {
this.discard();
if (!this.level().isClientSide) {
this.explode();
}
} else {
this.updateInWaterStateAndDoFluidPushing();
if (this.level().isClientSide) {
this.level().addParticle(ParticleTypes.SMOKE, this.getX(), this.getY() + 0.5D, this.getZ(), 0.0D, 0.0D, 0.0D);
}
}
}
public void shootFromRotation(Entity pShooter, float pX, float pY, float pZ, float pVelocity) {
float f = -Mth.sin(pY * ((float)Math.PI / 180F)) * Mth.cos(pX * ((float)Math.PI / 180F));
float f1 = -Mth.sin((pX + pZ) * ((float)Math.PI / 180F));
float f2 = Mth.cos(pY * ((float)Math.PI / 180F)) * Mth.cos(pX * ((float)Math.PI / 180F));
Vec3 vec = new Vec3(f, f1, f2).multiply(pVelocity, pVelocity, pVelocity);
this.setDeltaMovement(vec);
Vec3 vec3 = pShooter.getDeltaMovement();
this.setDeltaMovement(this.getDeltaMovement().add(vec3.x, pShooter.onGround() ? 0.0D : vec3.y, vec3.z));
}
}
@@ -0,0 +1,22 @@
package com.jenny.enhancedexplosives.entities.tnt;
import com.jenny.enhancedexplosives.entities.entities;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import javax.annotation.Nullable;
public class ClusterPrimedTNT extends basePrimedTNT {
public ClusterPrimedTNT (Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse, Vec3 move) {
super(entities.TNT_CLUSTER.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power, "cluster");
this.addDeltaMovement(move);
}
public ClusterPrimedTNT(EntityType<ClusterPrimedTNT> entityType, Level level) {
super(entityType, level, null);
this.setRenderID("cluster");
}
}
@@ -0,0 +1,33 @@
package com.jenny.enhancedexplosives.entities.tnt;
import com.jenny.enhancedexplosives.entities.entities;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import javax.annotation.Nullable;
public class StrongerPrimedTNT extends basePrimedTNT {
public StrongerPrimedTNT (Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse) {
super(entities.TNT_STRONGER.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power, "default");
this.setRenderID(evalRenderID());
}
public StrongerPrimedTNT(EntityType<StrongerPrimedTNT> entityType, Level level) {
super(entityType, level, null);
this.setRenderID(evalRenderID());
}
public String evalRenderID() {
int a = (int) this.getPower();
return switch ((int) this.getPower()) {
case 8 -> "stronger_8";
case 16 -> "stronger_16";
case 32 -> "stronger_32";
case 64 -> "stronger_64";
case 128 -> "stronger_128";
default -> "default";
};
}
}
@@ -0,0 +1,138 @@
package com.jenny.enhancedexplosives.entities.tnt;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.world.entity.*;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
public abstract class basePrimedTNT extends Entity implements TraceableEntity {
private static final EntityDataAccessor<Integer> DATA_FUSE_ID = SynchedEntityData.defineId(basePrimedTNT.class, EntityDataSerializers.INT);
private static final EntityDataAccessor<Float> DATA_POWER_ID = SynchedEntityData.defineId(basePrimedTNT.class, EntityDataSerializers.FLOAT);
private static final EntityDataAccessor<String> DATA_RENDER_ID = SynchedEntityData.defineId(basePrimedTNT.class, EntityDataSerializers.STRING);
@Nullable
private LivingEntity owner;
private String renderID = "default";
public basePrimedTNT(EntityType<? extends basePrimedTNT> pEntityType, Level pLevel, @Nullable LivingEntity owner) {
super(pEntityType, pLevel);
commonInit(pLevel, owner);
}
private void commonInit(Level pLevel, @Nullable LivingEntity owner) {
double d0 = pLevel.random.nextDouble() * (double)((float)Math.PI * 2F);
this.setDeltaMovement(-Math.sin(d0) * 0.02D, (double)0.2F, -Math.cos(d0) * 0.02D);
this.blocksBuilding = true;
this.owner = owner;
}
public basePrimedTNT(EntityType<? extends basePrimedTNT> pEntityType, Level pLevel, @Nullable LivingEntity owner, Vec3 pos, int fuse, float power, String renderID) {
super(pEntityType, pLevel);
commonInit(pLevel, owner);
setPos(pos);
setFuse(fuse);
setPower(power);
setRenderID(renderID);
}
protected void explode() {
this.level().explode(this, this.getX(), this.getY(0.0625D), this.getZ(), this.getPower(), Level.ExplosionInteraction.TNT);
}
public int getFuse() {
return this.entityData.get(DATA_FUSE_ID);
}
public void setFuse(int fuse) {
this.entityData.set(DATA_FUSE_ID, fuse);
}
public float getPower() {
return this.entityData.get(DATA_POWER_ID);
}
public void setPower(float power) {
this.entityData.set(DATA_POWER_ID, power);
}
public void tick() {
if (!this.isNoGravity()) {
this.setDeltaMovement(this.getDeltaMovement().add(0.0D, -0.04D, 0.0D));
}
this.move(MoverType.SELF, this.getDeltaMovement());
this.setDeltaMovement(this.getDeltaMovement().scale(0.98D));
if (this.onGround()) {
this.setDeltaMovement(this.getDeltaMovement().multiply(0.7D, -0.5D, 0.7D));
}
int i = this.getFuse() - 1;
this.setFuse(i);
if (i <= 0) {
this.discard();
if (!this.level().isClientSide) {
this.explode();
}
} else {
this.updateInWaterStateAndDoFluidPushing();
if (this.level().isClientSide) {
this.level().addParticle(ParticleTypes.SMOKE, this.getX(), this.getY() + 0.5D, this.getZ(), 0.0D, 0.0D, 0.0D);
}
}
}
public boolean isPickable() {
return !this.isRemoved();
}
protected Entity.@NotNull MovementEmission getMovementEmission() {
return Entity.MovementEmission.NONE;
}
protected void defineSynchedData() {
this.entityData.define(DATA_FUSE_ID, 80);
this.entityData.define(DATA_POWER_ID, 4.0f);
this.entityData.define(DATA_RENDER_ID, "default");
}
protected void addAdditionalSaveData(CompoundTag pCompound) {
pCompound.putShort("Fuse", (short)this.getFuse());
pCompound.putFloat("Power", (short)this.getPower());
pCompound.putString("RenderID", getRenderID());
}
protected void readAdditionalSaveData(CompoundTag pCompound) {
this.setFuse(pCompound.getShort("Fuse"));
this.setPower(pCompound.getFloat("Power"));
this.setRenderID(pCompound.getString("RenderID"));
}
@Nullable
public LivingEntity getOwner() {
return this.owner;
}
public void setOwner(@Nullable LivingEntity owner) {
this.owner = owner;
}
public void setRenderID(String renderID) {
this.entityData.set(DATA_RENDER_ID, renderID);
}
public String getRenderID() {
return this.entityData.get(DATA_RENDER_ID);
}
protected float getEyeHeight(@NotNull Pose pPose, @NotNull EntityDimensions pSize) {
return 0.15F;
}
}
@@ -0,0 +1,89 @@
package com.jenny.enhancedexplosives.entities.tnt;
import com.jenny.enhancedexplosives.entities.entities;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.world.entity.*;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import javax.annotation.Nullable;
import java.util.List;
public class blackHolePrimedTNT extends basePrimedTNT {
private static final EntityDataAccessor<Float> DATA_SPEED_ID = SynchedEntityData.defineId(blackHolePrimedTNT.class, EntityDataSerializers.FLOAT);
public blackHolePrimedTNT(Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse, float speed) {
super(entities.TNT_BLACK_HOLE.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power, "black_hole");
this.setSpeed(speed);
}
public blackHolePrimedTNT(EntityType<blackHolePrimedTNT> entityType, Level level) {
super(entityType, level, null);
this.setRenderID("black_hole");
this.setSpeed(this.getSpeed());
}
private Vec3 targetVector(Entity target) {
double dist = getTargetDist(target);
float speed = getSpeed();
Vec3 mult = new Vec3(speed / dist, speed / dist, speed / dist);
Vec3 ret = this.position().subtract(target.position()).normalize().multiply(mult);
if (dist < this.position().subtract(target.position().add(ret)).length()) {
// reduce overshoot
return Vec3.ZERO;
}
else {
return ret;
}
}
public double getTargetDist(Entity target) {
return target.position().subtract(this.position()).length();
}
public List<Entity> findTargets() {
Vec3 corner1 = this.position().subtract(15, 15, 15);
Vec3 corner2 = this.position().add(15, 15, 15);
AABB boundingBox = new AABB(corner1, corner2);
return this.level().getEntities(this, boundingBox);
}
@Override
public void tick() {
for (Entity e : findTargets()) {
e.addDeltaMovement(targetVector(e));
}
super.tick();
}
@Override
protected void addAdditionalSaveData(CompoundTag pCompound) {
pCompound.putFloat("Speed", this.getSpeed());
super.addAdditionalSaveData(pCompound);
}
@Override
protected void readAdditionalSaveData(CompoundTag pCompound) {
this.setSpeed(pCompound.getFloat("Speed"));
super.readAdditionalSaveData(pCompound);
}
public void setSpeed(float speed) {
this.entityData.set(DATA_SPEED_ID, speed);
}
public float getSpeed() {
return this.entityData.get(DATA_SPEED_ID);
}
@Override
protected void defineSynchedData() {
this.entityData.define(DATA_SPEED_ID, 4.0f);
super.defineSynchedData();
}
}
@@ -0,0 +1,77 @@
package com.jenny.enhancedexplosives.entities.tnt;
import com.jenny.enhancedexplosives.entities.entities;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.Arrow;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import javax.annotation.Nullable;
public class claymorePrimedTNT extends basePrimedTNT {
private static final EntityDataAccessor<Integer> DATA_PCOUNT_ID = SynchedEntityData.defineId(claymorePrimedTNT.class, EntityDataSerializers.INT);
public claymorePrimedTNT(Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse, int projectileCount) {
super(entities.TNT_CLAYMORE.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power, "tnt_claymore");
setPCount(projectileCount);
}
public claymorePrimedTNT(EntityType<claymorePrimedTNT> entityType, Level level) {
super(entityType, level, null);
setRenderID("tnt_claymore");
}
public Vec3 targetVector(RandomSource rng) {
return new Vec3(
(double) rng.nextInt(-10, 11) / 10,
(double) rng.nextInt( 11) / 10,
(double) rng.nextInt(-10, 11) / 10);
}
@Override
public void explode() {
super.explode();
RandomSource rng = level().getRandom();
for (int i = 0; i < getPCount(); i++) {
Vec3 target = targetVector(rng);
Vec3 pos = position().add(target);
Projectile e = new Arrow(level(),pos.x, pos.y + 1, pos.z);
e.setDeltaMovement(target.multiply(5, 0.1, 5));
level().addFreshEntity(e);
}
}
@Override
protected void addAdditionalSaveData(CompoundTag pCompound) {
pCompound.putFloat("ProjectileCount", this.getPCount());
super.addAdditionalSaveData(pCompound);
}
@Override
protected void readAdditionalSaveData(CompoundTag pCompound) {
this.setPCount(pCompound.getInt("ProjectileCount"));
super.readAdditionalSaveData(pCompound);
}
public void setPCount(int pCount) {
this.entityData.set(DATA_PCOUNT_ID, pCount);
}
public int getPCount() {
return this.entityData.get(DATA_PCOUNT_ID);
}
@Override
protected void defineSynchedData() {
this.entityData.define(DATA_PCOUNT_ID, 16);
super.defineSynchedData();
}
}
@@ -0,0 +1,91 @@
package com.jenny.enhancedexplosives.entities.tnt;
import com.jenny.enhancedexplosives.entities.entities;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.ai.targeting.TargetingConditions;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import javax.annotation.Nullable;
public class homingPrimedTNT extends basePrimedTNT {
private static final EntityDataAccessor<Float> DATA_SPEED_ID = SynchedEntityData.defineId(homingPrimedTNT.class, EntityDataSerializers.FLOAT);
Entity target;
public homingPrimedTNT (Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse, float speed) {
super(entities.TNT_HOMING.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power, "homing");
this.target = null;
this.setSpeed(speed);
}
public homingPrimedTNT(EntityType<homingPrimedTNT> entityType, Level level) {
super(entityType, level, null);
}
private Vec3 targetVector() {
double targetDist = getTargetDist();
Vec3 targetVec = new Vec3(0, 0, 0);
if (targetDist > 3) {
float speed = getSpeed();
targetVec = new Vec3(target.getX() - this.getX(), target.getY() - this.getY(), target.getZ() - this.getZ()).normalize().multiply(speed, speed, speed);
if (targetDist < 10) {
targetVec.multiply(targetDist / 10, targetDist / 10, targetDist / 10);
}
}
return targetVec;
}
public double getTargetDist() {
return new Vec3(target.getX(), target.getY(), target.getZ()).subtract(this.getX(), this.getY(), this.getZ()).length();
}
public void findTarget() {
Vec3 corner1 = this.position().subtract(15, 15, 15);
Vec3 corner2 = this.position().add(15, 15, 15);
AABB boundingBox = new AABB(corner1, corner2);
target = this.level().getNearestEntity(LivingEntity.class, TargetingConditions.forNonCombat(), null, this.getX(), this.getY(), this.getZ(), boundingBox);
}
@Override
public void tick() {
if (target == null) {
findTarget();
}
else {
if (getTargetDist() > 15) {target = null;} else {addDeltaMovement(targetVector());}
}
super.tick();
}
@Override
protected void addAdditionalSaveData(CompoundTag pCompound) {
pCompound.putFloat("Speed", this.getSpeed());
super.addAdditionalSaveData(pCompound);
}
@Override
protected void readAdditionalSaveData(CompoundTag pCompound) {
this.setSpeed(pCompound.getFloat("Speed"));
super.readAdditionalSaveData(pCompound);
}
public void setSpeed(float speed) {
this.entityData.set(DATA_SPEED_ID, speed);
}
public float getSpeed() {
return this.entityData.get(DATA_SPEED_ID);
}
@Override
protected void defineSynchedData() {
this.entityData.define(DATA_SPEED_ID, 4.0f);
super.defineSynchedData();
}
}
@@ -0,0 +1,47 @@
package com.jenny.enhancedexplosives.entities.tnt;
import com.jenny.enhancedexplosives.entities.entities;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.ExplosionDamageCalculator;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
public class selectivePrimedTNT extends basePrimedTNT {
static class SelectiveExplosionCalculator extends ExplosionDamageCalculator {
private final String block;
public SelectiveExplosionCalculator(String block) {
this.block = block;
}
public boolean shouldBlockExplode(@NotNull Explosion pExplosion, @NotNull BlockGetter pReader, @NotNull BlockPos pPos, BlockState pState, float pPower) {
return pState.getBlock().toString().equals(block);
}
}
public selectivePrimedTNT(Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse) {
super(entities.TNT_SELECTIVE.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power, "tnt_selective");
}
public selectivePrimedTNT(EntityType<selectivePrimedTNT> entityType, Level level) {
super(entityType, level, null);
this.setRenderID("tnt_selective");
}
@Override
protected void explode() {
SelectiveExplosionCalculator dmgCalc = new SelectiveExplosionCalculator(getBlock());
this.level().explode(this, null, dmgCalc, position(), getPower(), false, Level.ExplosionInteraction.TNT);
}
public String getBlock() {
return level().getBlockState(new BlockPos((int) Math.round(getX()), (int) Math.round(getY() - 1), (int) Math.round(getZ()))).getBlock().toString();
}
}