tnt render system rewrite

This commit is contained in:
Jenny 2025-01-25 21:18:43 +01:00
parent ab77a7246a
commit 94133e167a
Signed by: Jenny
GPG Key ID: 4A98012FB1C39311
12 changed files with 50 additions and 72 deletions

View File

@ -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.8.0
mod_version=0.8.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

View File

@ -12,11 +12,9 @@ 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> {
public class BaseTNTRenderer<T extends basePrimedTNT> extends EntityRenderer<T> {
private final BlockRenderDispatcher blockRenderer;
public BaseTNTRenderer(EntityRendererProvider.Context pContext) {
@ -25,7 +23,7 @@ public class BaseTNTRenderer extends EntityRenderer<basePrimedTNT> {
this.blockRenderer = pContext.getBlockRenderDispatcher();
}
public void render(basePrimedTNT pEntity, float pEntityYaw, float pPartialTicks, PoseStack pPoseStack, @NotNull MultiBufferSource pBuffer, int pPackedLight) {
public void render(T 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();
@ -37,31 +35,17 @@ public class BaseTNTRenderer extends EntityRenderer<basePrimedTNT> {
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();
case "ender" -> blocks.TNT_ENDER.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);
TntMinecartRenderer.renderWhiteSolidBlock(this.blockRenderer, pEntity.renderBlock().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) {
public ResourceLocation getTextureLocation(@NotNull T pEntity) {
return TextureAtlas.LOCATION_BLOCKS;
}
}

View File

@ -11,7 +11,6 @@ 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> {
@ -42,7 +41,7 @@ public class clusterTNTRenderer 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.defaultBlockState(), pPoseStack, pBuffer, pPackedLight, i / 5 % 2 == 0);
TntMinecartRenderer.renderWhiteSolidBlock(this.blockRenderer, pEntity.renderBlock().defaultBlockState(), pPoseStack, pBuffer, pPackedLight, i / 5 % 2 == 0);
pPoseStack.popPose();
super.render(pEntity, pEntityYaw, pPartialTicks, pPoseStack, pBuffer, pPackedLight);
}

View File

@ -9,18 +9,19 @@ 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.level.block.Block;
import net.minecraft.world.level.block.Blocks;
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");
super(entities.DYNAMITE.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power);
}
public dynamite(EntityType<dynamite> entityType, Level level) {
super(entityType, level, null);
this.setRenderID("dynamite");
}
@Override
@ -59,4 +60,8 @@ public class dynamite extends basePrimedTNT {
Vec3 vec3 = pShooter.getDeltaMovement();
this.setDeltaMovement(this.getDeltaMovement().add(vec3.x, pShooter.onGround() ? 0.0D : vec3.y, vec3.z));
}
public Block renderBlock() {
return Blocks.TNT;
}
}

View File

@ -11,12 +11,11 @@ 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");
super(entities.TNT_CLUSTER.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power);
this.addDeltaMovement(move);
}
public ClusterPrimedTNT(EntityType<ClusterPrimedTNT> entityType, Level level) {
super(entityType, level, null);
this.setRenderID("cluster");
}
}

View File

@ -1,33 +1,34 @@
package com.jenny.enhancedexplosives.entities.tnt;
import com.jenny.enhancedexplosives.blocks.blocks;
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.level.block.Block;
import net.minecraft.world.level.block.Blocks;
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());
super(entities.TNT_STRONGER.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power);
}
public StrongerPrimedTNT(EntityType<StrongerPrimedTNT> entityType, Level level) {
super(entityType, level, null);
this.setRenderID(evalRenderID());
}
public String evalRenderID() {
int a = (int) this.getPower();
@Override
public Block renderBlock() {
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";
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.END_GATEWAY;
};
}
}

View File

@ -7,6 +7,8 @@ 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.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
@ -15,13 +17,10 @@ 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);
@ -34,13 +33,12 @@ public abstract class basePrimedTNT extends Entity implements TraceableEntity {
this.owner = owner;
}
public basePrimedTNT(EntityType<? extends basePrimedTNT> pEntityType, Level pLevel, @Nullable LivingEntity owner, Vec3 pos, int fuse, float power, String renderID) {
public basePrimedTNT(EntityType<? extends basePrimedTNT> pEntityType, Level pLevel, @Nullable LivingEntity owner, Vec3 pos, int fuse, float power) {
super(pEntityType, pLevel);
commonInit(pLevel, owner);
setPos(pos);
setFuse(fuse);
setPower(power);
setRenderID(renderID);
}
protected void explode() {
@ -93,26 +91,24 @@ public abstract class basePrimedTNT extends Entity implements TraceableEntity {
return !this.isRemoved();
}
protected Entity.@NotNull MovementEmission getMovementEmission() {
return Entity.MovementEmission.NONE;
@NotNull
protected MovementEmission getMovementEmission() {
return 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
@ -124,15 +120,11 @@ public abstract class basePrimedTNT extends Entity implements TraceableEntity {
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;
}
public Block renderBlock() {
return Blocks.GLASS;
}
}

View File

@ -17,13 +17,12 @@ 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");
super(entities.TNT_BLACK_HOLE.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power);
this.setSpeed(speed);
}
public blackHolePrimedTNT(EntityType<blackHolePrimedTNT> entityType, Level level) {
super(entityType, level, null);
this.setRenderID("black_hole");
this.setSpeed(this.getSpeed());
}

View File

@ -19,13 +19,12 @@ 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");
super(entities.TNT_CLAYMORE.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power);
setPCount(projectileCount);
}
public claymorePrimedTNT(EntityType<claymorePrimedTNT> entityType, Level level) {
super(entityType, level, null);
setRenderID("tnt_claymore");
}
public Vec3 targetVector(RandomSource rng) {

View File

@ -1,16 +1,11 @@
package com.jenny.enhancedexplosives.entities.tnt;
import com.jenny.enhancedexplosives.blocks.blocks;
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.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.targeting.TargetingConditions;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.phys.Vec3;
import javax.annotation.Nullable;
@ -18,12 +13,14 @@ import javax.annotation.Nullable;
public class enderPrimedTNT extends basePrimedTNT {
public enderPrimedTNT(Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse) {
super(entities.TNT_ENDER.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power, "ender");
super(entities.TNT_ENDER.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power);
}
public enderPrimedTNT(EntityType<enderPrimedTNT> entityType, Level level) {
super(entityType, level, null);
setRenderID("ender");
}
public Block renderBlock() {
return blocks.TNT_ENDER.get();
}
}

View File

@ -8,6 +8,8 @@ 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.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
@ -18,7 +20,7 @@ public class homingPrimedTNT extends basePrimedTNT {
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");
super(entities.TNT_HOMING.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power);
this.target = null;
this.setSpeed(speed);
}

View File

@ -8,6 +8,8 @@ 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.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
@ -28,12 +30,11 @@ public class selectivePrimedTNT extends basePrimedTNT {
}
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");
super(entities.TNT_SELECTIVE.get(), pLevel, pOwner, new Vec3(pX, pY, pZ), fuse, power);
}
public selectivePrimedTNT(EntityType<selectivePrimedTNT> entityType, Level level) {
super(entityType, level, null);
this.setRenderID("tnt_selective");
}
@Override
protected void explode() {