more entity rendering & fix correct tnt on chain explosion

This commit is contained in:
Jenny committed 2025-01-21 17:03:32 +01:00
1 parent 095e3d4e8b
commit 400942b6f8
14 files changed
+251 -78

No files matched your search

@@ -1,25 +1,23 @@
package com.jenny.compressedtnt.entities;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.PrimedTnt;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import javax.annotation.Nullable;
public class ClusterPrimedTNT extends PrimedTnt {
final float pRadius;
public class ClusterPrimedTNT extends basePrimedTNT {
public ClusterPrimedTNT (Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float pRadius, int fuseTime, Vec3 move) {
super(pLevel, pX, pY, pZ, pOwner);
this.pRadius = pRadius;
this.setFuse(fuseTime);
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);
this.setPos(pX, pY, pZ);
this.setFuse(fuse);
this.setPower(power);
this.addDeltaMovement(move);
}
@Override
protected void explode() {
float $$0 = pRadius;
this.level().explode(this, this.getX(), this.getY((double)0.0625F), this.getZ(), pRadius, Level.ExplosionInteraction.TNT);
public ClusterPrimedTNT(EntityType<ClusterPrimedTNT> entityType, Level level) {
super(entityType, level, null);
}
}
@@ -1,23 +1,20 @@
package com.jenny.compressedtnt.entities;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.PrimedTnt;
import net.minecraft.world.level.Level;
import javax.annotation.Nullable;
public class StrongerPrimedTNT extends PrimedTnt {
final float pRadius;
public StrongerPrimedTNT (Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float pRadius, int fuseTime) {
super(pLevel, pX, pY, pZ, pOwner);
this.pRadius = pRadius;
this.setFuse(fuseTime);
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);
this.setPos(pX, pY, pZ);
this.setFuse(fuse);
this.setPower(power);
}
@Override
protected void explode() {
float $$0 = pRadius;
this.level().explode(this, this.getX(), this.getY((double)0.0625F), this.getZ(), pRadius, Level.ExplosionInteraction.TNT);
public StrongerPrimedTNT(EntityType<StrongerPrimedTNT> entityType, Level level) {
super(entityType, level, null);
}
}
@@ -5,21 +5,24 @@ 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.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MoverType;
import net.minecraft.world.entity.TraceableEntity;
import net.minecraft.world.entity.*;
import net.minecraft.world.level.Level;
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);
import javax.annotation.Nullable;
public BasePrimedTNT(EntityType<? extends BasePrimedTNT> pEntityType, Level pLevel) {
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);
@Nullable
private LivingEntity owner;
public basePrimedTNT(EntityType<? extends basePrimedTNT> pEntityType, Level pLevel, @Nullable LivingEntity owner) {
super(pEntityType, pLevel);
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;
}
protected void explode() {
@@ -91,4 +94,13 @@ public abstract class BasePrimedTNT extends Entity implements TraceableEntity {
this.setFuse(pCompound.getShort("Fuse"));
this.setPower(pCompound.getFloat("Power"));
}
@Nullable
public LivingEntity getOwner() {
return this.owner;
}
public void setOwner(LivingEntity owner) {
this.owner = owner;
}
}
@@ -1,7 +1,6 @@
package com.jenny.compressedtnt.entities.client;
import com.jenny.compressedtnt.blocks.blocks;
import com.jenny.compressedtnt.entities.BasePrimedTNT;
import com.jenny.compressedtnt.entities.basePrimedTNT;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.renderer.MultiBufferSource;
@@ -14,16 +13,18 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.level.block.Block;
public class BaseTNTRenderer extends EntityRenderer<BasePrimedTNT> {
private final BlockRenderDispatcher blockRenderer;
public class BaseTNTRenderer extends EntityRenderer<basePrimedTNT> {
private BlockRenderDispatcher blockRenderer;
private final Block block;
public BaseTNTRenderer(EntityRendererProvider.Context pContext, Block block) {
super(pContext);
this.shadowRadius = 0.5F;
this.blockRenderer = pContext.getBlockRenderDispatcher();
this.block = block;
}
public void render(BasePrimedTNT pEntity, float pEntityYaw, float pPartialTicks, PoseStack pPoseStack, MultiBufferSource pBuffer, int pPackedLight) {
public void render(basePrimedTNT pEntity, float pEntityYaw, float pPartialTicks, PoseStack pPoseStack, MultiBufferSource pBuffer, int pPackedLight) {
pPoseStack.pushPose();
pPoseStack.translate(0.0F, 0.5F, 0.0F);
int i = pEntity.getFuse();
@@ -39,15 +40,12 @@ public class BaseTNTRenderer extends EntityRenderer<BasePrimedTNT> {
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_HOMING.get().defaultBlockState(), pPoseStack, pBuffer, pPackedLight, i / 5 % 2 == 0);
TntMinecartRenderer.renderWhiteSolidBlock(this.blockRenderer, block.defaultBlockState(), pPoseStack, pBuffer, pPackedLight, i / 5 % 2 == 0);
pPoseStack.popPose();
super.render(pEntity, pEntityYaw, pPartialTicks, pPoseStack, pBuffer, pPackedLight);
}
/**
* Returns the location of an entity's texture.
*/
public ResourceLocation getTextureLocation(BasePrimedTNT pEntity) {
public ResourceLocation getTextureLocation(basePrimedTNT pEntity) {
return TextureAtlas.LOCATION_BLOCKS;
}
}
@@ -0,0 +1,53 @@
package com.jenny.compressedtnt.entities.client;
import com.jenny.compressedtnt.blocks.blocks;
import com.jenny.compressedtnt.entities.ClusterPrimedTNT;
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 org.jetbrains.annotations.NotNull;
public class clusterTNTRenderer extends EntityRenderer<ClusterPrimedTNT> {
private final BlockRenderDispatcher blockRenderer;
public clusterTNTRenderer(EntityRendererProvider.Context pContext) {
super(pContext);
this.shadowRadius = 0.5F;
this.blockRenderer = pContext.getBlockRenderDispatcher();
}
public void render(ClusterPrimedTNT 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_CLUSTER_2.get().defaultBlockState(), pPoseStack, pBuffer, pPackedLight, i / 5 % 2 == 0);
pPoseStack.popPose();
super.render(pEntity, pEntityYaw, pPartialTicks, pPoseStack, pBuffer, pPackedLight);
}
public @NotNull ResourceLocation getTextureLocation(@NotNull ClusterPrimedTNT pEntity) {
return TextureAtlas.LOCATION_BLOCKS;
}
}
@@ -0,0 +1,59 @@
package com.jenny.compressedtnt.entities.client;
import com.jenny.compressedtnt.blocks.blocks;
import com.jenny.compressedtnt.entities.StrongerPrimedTNT;
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 org.jetbrains.annotations.NotNull;
public class strongerTNTRenderer extends EntityRenderer<StrongerPrimedTNT> {
private final BlockRenderDispatcher blockRenderer;
public strongerTNTRenderer(EntityRendererProvider.Context pContext) {
super(pContext);
this.shadowRadius = 0.5F;
this.blockRenderer = pContext.getBlockRenderDispatcher();
}
public void render(StrongerPrimedTNT 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);
}
Block block = switch ((int) pEntity.getPower()) {
case 8 -> blocks.TNT_8.get();
case 16 -> blocks.TNT_16.get();
case 32 -> blocks.TNT_32.get();
case 64 -> blocks.TNT_64.get();
case 128 -> blocks.TNT_128.get();
default -> blocks.TNT_HOMING.get();
};
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);
}
public @NotNull ResourceLocation getTextureLocation(@NotNull StrongerPrimedTNT pEntity) {
return TextureAtlas.LOCATION_BLOCKS;
}
}
@@ -1,5 +1,8 @@
package com.jenny.compressedtnt.entities;
import com.jenny.compressedtnt.blocks.blocks;
import com.jenny.compressedtnt.entities.client.*;
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;
@@ -15,9 +18,25 @@ public class entities {
public static final RegistryObject<EntityType<homingPrimedTNT>> TNT_HOMING =
ENTITY_TYPES.register("tnt_homing", () -> EntityType.Builder.<homingPrimedTNT>of(homingPrimedTNT::new, MobCategory.MISC)
.sized(2.5f, 2.5f).build("tnt_homing"));
.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 void register(IEventBus eventBus) {
ENTITY_TYPES.register(eventBus);
}
}
public static void registerRenderers () {
EntityRenderers.register(TNT_STRONGER.get(), strongerTNTRenderer::new);
EntityRenderers.register(TNT_CLUSTER.get(), clusterTNTRenderer::new);
EntityRenderers.register(TNT_HOMING.get(), pContext -> new BaseTNTRenderer(pContext, blocks.TNT_HOMING.get()));
}
}
@@ -9,19 +9,14 @@ import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
public class homingPrimedTNT extends BasePrimedTNT {
float pRadius = 0;
public class homingPrimedTNT extends basePrimedTNT {
float speed = 0;
Entity target;
@Nullable
private LivingEntity owner;
public homingPrimedTNT (Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse, float speed) {
this(entities.TNT_HOMING.get(), pLevel);
this.setPos(pX, pY, pZ);
this.owner = pOwner;
this.pRadius = power;
this.setOwner(pOwner);
this.speed = speed;
this.target = null;
this.setPower(power);
@@ -29,7 +24,7 @@ public class homingPrimedTNT extends BasePrimedTNT {
}
public homingPrimedTNT(EntityType<homingPrimedTNT> entityType, Level level) {
super(entityType, level);
super(entityType, level, null);
}
private Vec3 targetVector() {
@@ -68,12 +63,6 @@ public class homingPrimedTNT extends BasePrimedTNT {
super.tick();
}
@Nullable
public LivingEntity getOwner() {
return this.owner;
}
protected float getEyeHeight(@NotNull Pose pPose, @NotNull EntityDimensions pSize) {
return 0.15F;
}