more entity rendering & fix correct tnt on chain explosion
This commit is contained in:
parent
095e3d4e8b
commit
400942b6f8
@ -1,13 +1,10 @@
|
|||||||
package com.jenny.compressedtnt;
|
package com.jenny.compressedtnt;
|
||||||
|
|
||||||
import com.jenny.compressedtnt.blocks.blocks;
|
import com.jenny.compressedtnt.blocks.blocks;
|
||||||
import com.jenny.compressedtnt.entities.client.BaseTNTRenderer;
|
|
||||||
import com.jenny.compressedtnt.entities.entities;
|
import com.jenny.compressedtnt.entities.entities;
|
||||||
import com.mojang.logging.LogUtils;
|
import com.mojang.logging.LogUtils;
|
||||||
import net.minecraft.client.renderer.entity.EntityRenderers;
|
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.event.BuildCreativeModeTabContentsEvent;
|
|
||||||
import net.minecraftforge.event.server.ServerStartingEvent;
|
import net.minecraftforge.event.server.ServerStartingEvent;
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
@ -37,20 +34,12 @@ public class Compressedtnt {
|
|||||||
|
|
||||||
// Register ourselves for server and other game events we are interested in
|
// Register ourselves for server and other game events we are interested in
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
|
|
||||||
// Register the item to a creative tab
|
|
||||||
modEventBus.addListener(this::addCreative);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void commonSetup(final FMLCommonSetupEvent event) {
|
private void commonSetup(final FMLCommonSetupEvent event) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the example block item to the building blocks tab
|
|
||||||
private void addCreative(BuildCreativeModeTabContentsEvent event) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// You can use SubscribeEvent and let the Event Bus discover methods to call
|
// You can use SubscribeEvent and let the Event Bus discover methods to call
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onServerStarting(ServerStartingEvent event) {
|
public void onServerStarting(ServerStartingEvent event) {
|
||||||
@ -63,7 +52,7 @@ public class Compressedtnt {
|
|||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onClientSetup(FMLClientSetupEvent event) {
|
public static void onClientSetup(FMLClientSetupEvent event) {
|
||||||
EntityRenderers.register(entities.TNT_HOMING.get(), pContext -> new BaseTNTRenderer(pContext, blocks.TNT_HOMING.get()));
|
entities.registerRenderers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -8,6 +8,7 @@ import net.minecraft.sounds.SoundSource;
|
|||||||
import net.minecraft.util.RandomSource;
|
import net.minecraft.util.RandomSource;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.level.Explosion;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.TntBlock;
|
import net.minecraft.world.level.block.TntBlock;
|
||||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||||
@ -32,7 +33,7 @@ public class ClusterTNTBlock extends TntBlock {
|
|||||||
this.childRange = childRange;
|
this.childRange = childRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onCaughtFire(@NotNull BlockState state, @NotNull Level world, @NotNull BlockPos pos, @Nullable Direction face, @Nullable LivingEntity igniter) {
|
public void onCaughtFire(@NotNull BlockState state, @NotNull Level world, @NotNull BlockPos pos, @Nullable Direction face, @Nullable LivingEntity igniter) {
|
||||||
explode(world, pos, igniter, this.pRadius, this.fuseTime, this.childCount, this.childRange);
|
explode(world, pos, igniter, this.pRadius, this.fuseTime, this.childCount, this.childRange);
|
||||||
}
|
}
|
||||||
@ -42,20 +43,33 @@ public class ClusterTNTBlock extends TntBlock {
|
|||||||
explode(p_57434_, p_57435_, (LivingEntity)null, pRadius, fuseTime, childCount, childRange);
|
explode(p_57434_, p_57435_, (LivingEntity)null, pRadius, fuseTime, childCount, childRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Vec3 getMove(Level level, int childRange) {
|
||||||
|
RandomSource rng = level.getRandom();
|
||||||
|
float offsetX = (float) rng.nextInt(- childRange, childRange + 1) / 15;
|
||||||
|
float offsetZ = (float) rng.nextInt(- childRange, childRange + 1) / 15;
|
||||||
|
return new Vec3(offsetX, 0, offsetZ);
|
||||||
|
}
|
||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
private static void explode(Level level, BlockPos blockPos, @Nullable LivingEntity entity, float pRadius, int fuseTime, int childCount, int childRange) {
|
private static void explode(Level level, BlockPos blockPos, @Nullable LivingEntity entity, float pRadius, int fuseTime, int childCount, int childRange) {
|
||||||
RandomSource rng = level.getRandom();
|
|
||||||
float offsetX, offsetZ;
|
|
||||||
if (!level.isClientSide) {
|
if (!level.isClientSide) {
|
||||||
for (int i = 0; i < childCount; i++) {
|
for (int i = 0; i < childCount; i++) {
|
||||||
offsetX = (float) rng.nextInt(- childRange, childRange + 1) / 15;
|
ClusterPrimedTNT primedtnt = new ClusterPrimedTNT(level, (double) blockPos.getX() + (double) 0.5F, (double) blockPos.getY(), (double) blockPos.getZ() + (double) 0.5F, entity, pRadius, fuseTime, getMove(level, childRange));
|
||||||
offsetZ = (float) rng.nextInt(- childRange, childRange + 1) / 15;
|
|
||||||
Vec3 move = new Vec3(offsetX, 0, offsetZ);
|
|
||||||
ClusterPrimedTNT primedtnt = new ClusterPrimedTNT(level, (double) blockPos.getX() + (double) 0.5F, (double) blockPos.getY(), (double) blockPos.getZ() + (double) 0.5F, entity, pRadius, fuseTime, move);
|
|
||||||
level.addFreshEntity(primedtnt);
|
level.addFreshEntity(primedtnt);
|
||||||
level.gameEvent(entity, GameEvent.PRIME_FUSE, blockPos);
|
level.gameEvent(entity, GameEvent.PRIME_FUSE, blockPos);
|
||||||
}
|
}
|
||||||
level.playSound((Player) null, blockPos.getX(), blockPos.getY(), blockPos.getZ(), SoundEvents.TNT_PRIMED, SoundSource.BLOCKS, 1.0F, 1.0F);
|
level.playSound((Player) null, blockPos.getX(), blockPos.getY(), blockPos.getZ(), SoundEvents.TNT_PRIMED, SoundSource.BLOCKS, 1.0F, 1.0F);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void wasExploded(Level level, BlockPos blockPos, Explosion pExplosion) {
|
||||||
|
if (!level.isClientSide) {
|
||||||
|
for (int i = 0; i < childCount; i++) {
|
||||||
|
int ft = (short) (level.random.nextInt(fuseTime / 4) + fuseTime / 8);
|
||||||
|
ClusterPrimedTNT primedtnt = new ClusterPrimedTNT(level, (double) blockPos.getX() + (double) 0.5F, (double) blockPos.getY(), (double) blockPos.getZ() + (double) 0.5F, pExplosion.getIndirectSourceEntity(), pRadius, ft, getMove(level, childRange));
|
||||||
|
level.addFreshEntity(primedtnt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import net.minecraft.sounds.SoundEvents;
|
|||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.level.Explosion;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.TntBlock;
|
import net.minecraft.world.level.block.TntBlock;
|
||||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||||
@ -27,7 +28,7 @@ public class homingTNTBlock extends TntBlock {
|
|||||||
this.speed = speed;
|
this.speed = speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onCaughtFire(@NotNull BlockState state, @NotNull Level world, @NotNull BlockPos pos, @Nullable Direction face, @Nullable LivingEntity igniter) {
|
public void onCaughtFire(@NotNull BlockState state, @NotNull Level world, @NotNull BlockPos pos, @Nullable Direction face, @Nullable LivingEntity igniter) {
|
||||||
explode(world, pos, igniter, this.pRadius, this.fuseTime, this.speed);
|
explode(world, pos, igniter, this.pRadius, this.fuseTime, this.speed);
|
||||||
}
|
}
|
||||||
@ -46,4 +47,14 @@ public class homingTNTBlock extends TntBlock {
|
|||||||
level.gameEvent(entity, GameEvent.PRIME_FUSE, blockPos);
|
level.gameEvent(entity, GameEvent.PRIME_FUSE, blockPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void wasExploded(Level level, BlockPos blockPos, Explosion pExplosion) {
|
||||||
|
if (!level.isClientSide) {
|
||||||
|
homingPrimedTNT primedtnt = new homingPrimedTNT(level, (double) blockPos.getX() + (double) 0.5F, (double) blockPos.getY(), (double) blockPos.getZ() + (double) 0.5F, pExplosion.getIndirectSourceEntity(), pRadius, fuseTime, speed);
|
||||||
|
int i = primedtnt.getFuse();
|
||||||
|
primedtnt.setFuse((short) (level.random.nextInt(i / 4) + i / 8));
|
||||||
|
level.addFreshEntity(primedtnt);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import net.minecraft.sounds.SoundEvents;
|
|||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.level.Explosion;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.TntBlock;
|
import net.minecraft.world.level.block.TntBlock;
|
||||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||||
@ -25,7 +26,7 @@ public class strongerTNTBlock extends TntBlock {
|
|||||||
this.fuseTime = fuseTime;
|
this.fuseTime = fuseTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onCaughtFire(BlockState state, Level world, BlockPos pos, @Nullable Direction face, @Nullable LivingEntity igniter) {
|
public void onCaughtFire(BlockState state, Level world, BlockPos pos, @Nullable Direction face, @Nullable LivingEntity igniter) {
|
||||||
explode(world, pos, igniter, this.pRadius, this.fuseTime);
|
explode(world, pos, igniter, this.pRadius, this.fuseTime);
|
||||||
}
|
}
|
||||||
@ -45,4 +46,15 @@ public class strongerTNTBlock extends TntBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void wasExploded(Level level, BlockPos blockPos, Explosion pExplosion) {
|
||||||
|
if (!level.isClientSide) {
|
||||||
|
int ft = (short) (level.random.nextInt(fuseTime / 4) + fuseTime / 8);
|
||||||
|
StrongerPrimedTNT primedtnt = new StrongerPrimedTNT(level, (double) blockPos.getX() + (double) 0.5F, (double) blockPos.getY(), (double) blockPos.getZ() + (double) 0.5F, pExplosion.getIndirectSourceEntity(), pRadius, ft);
|
||||||
|
int i = primedtnt.getFuse();
|
||||||
|
primedtnt.setFuse((short) (level.random.nextInt(i / 4) + i / 8));
|
||||||
|
level.addFreshEntity(primedtnt);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,23 @@
|
|||||||
package com.jenny.compressedtnt.entities;
|
package com.jenny.compressedtnt.entities;
|
||||||
|
|
||||||
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.item.PrimedTnt;
|
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.phys.Vec3;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class ClusterPrimedTNT extends PrimedTnt {
|
public class ClusterPrimedTNT extends basePrimedTNT {
|
||||||
final float pRadius;
|
|
||||||
|
|
||||||
public ClusterPrimedTNT (Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float pRadius, int fuseTime, Vec3 move) {
|
public ClusterPrimedTNT (Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse, Vec3 move) {
|
||||||
super(pLevel, pX, pY, pZ, pOwner);
|
super(entities.TNT_CLUSTER.get(), pLevel, pOwner);
|
||||||
this.pRadius = pRadius;
|
this.setPos(pX, pY, pZ);
|
||||||
this.setFuse(fuseTime);
|
this.setFuse(fuse);
|
||||||
|
this.setPower(power);
|
||||||
this.addDeltaMovement(move);
|
this.addDeltaMovement(move);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public ClusterPrimedTNT(EntityType<ClusterPrimedTNT> entityType, Level level) {
|
||||||
protected void explode() {
|
super(entityType, level, null);
|
||||||
float $$0 = pRadius;
|
|
||||||
this.level().explode(this, this.getX(), this.getY((double)0.0625F), this.getZ(), pRadius, Level.ExplosionInteraction.TNT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,20 @@
|
|||||||
package com.jenny.compressedtnt.entities;
|
package com.jenny.compressedtnt.entities;
|
||||||
|
|
||||||
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.item.PrimedTnt;
|
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class StrongerPrimedTNT extends PrimedTnt {
|
public class StrongerPrimedTNT extends basePrimedTNT {
|
||||||
final float pRadius;
|
public StrongerPrimedTNT (Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float power, int fuse) {
|
||||||
|
super(entities.TNT_STRONGER.get(), pLevel, pOwner);
|
||||||
public StrongerPrimedTNT (Level pLevel, double pX, double pY, double pZ, @Nullable LivingEntity pOwner, float pRadius, int fuseTime) {
|
this.setPos(pX, pY, pZ);
|
||||||
super(pLevel, pX, pY, pZ, pOwner);
|
this.setFuse(fuse);
|
||||||
this.pRadius = pRadius;
|
this.setPower(power);
|
||||||
this.setFuse(fuseTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public StrongerPrimedTNT(EntityType<StrongerPrimedTNT> entityType, Level level) {
|
||||||
protected void explode() {
|
super(entityType, level, null);
|
||||||
float $$0 = pRadius;
|
|
||||||
this.level().explode(this, this.getX(), this.getY((double)0.0625F), this.getZ(), pRadius, Level.ExplosionInteraction.TNT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,21 +5,24 @@ import net.minecraft.nbt.CompoundTag;
|
|||||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||||
import net.minecraft.network.syncher.SynchedEntityData;
|
import net.minecraft.network.syncher.SynchedEntityData;
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.*;
|
||||||
import net.minecraft.world.entity.EntityType;
|
|
||||||
import net.minecraft.world.entity.MoverType;
|
|
||||||
import net.minecraft.world.entity.TraceableEntity;
|
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
|
||||||
public abstract class BasePrimedTNT extends Entity implements TraceableEntity {
|
import javax.annotation.Nullable;
|
||||||
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);
|
|
||||||
|
|
||||||
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);
|
super(pEntityType, pLevel);
|
||||||
double d0 = pLevel.random.nextDouble() * (double)((float)Math.PI * 2F);
|
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.setDeltaMovement(-Math.sin(d0) * 0.02D, (double)0.2F, -Math.cos(d0) * 0.02D);
|
||||||
this.blocksBuilding = true;
|
this.blocksBuilding = true;
|
||||||
|
this.owner = owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void explode() {
|
protected void explode() {
|
||||||
@ -91,4 +94,13 @@ public abstract class BasePrimedTNT extends Entity implements TraceableEntity {
|
|||||||
this.setFuse(pCompound.getShort("Fuse"));
|
this.setFuse(pCompound.getShort("Fuse"));
|
||||||
this.setPower(pCompound.getFloat("Power"));
|
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;
|
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.blaze3d.vertex.PoseStack;
|
||||||
import com.mojang.math.Axis;
|
import com.mojang.math.Axis;
|
||||||
import net.minecraft.client.renderer.MultiBufferSource;
|
import net.minecraft.client.renderer.MultiBufferSource;
|
||||||
@ -14,16 +13,18 @@ import net.minecraft.resources.ResourceLocation;
|
|||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
|
|
||||||
public class BaseTNTRenderer extends EntityRenderer<BasePrimedTNT> {
|
public class BaseTNTRenderer extends EntityRenderer<basePrimedTNT> {
|
||||||
private final BlockRenderDispatcher blockRenderer;
|
private BlockRenderDispatcher blockRenderer;
|
||||||
|
private final Block block;
|
||||||
|
|
||||||
public BaseTNTRenderer(EntityRendererProvider.Context pContext, Block block) {
|
public BaseTNTRenderer(EntityRendererProvider.Context pContext, Block block) {
|
||||||
super(pContext);
|
super(pContext);
|
||||||
this.shadowRadius = 0.5F;
|
this.shadowRadius = 0.5F;
|
||||||
this.blockRenderer = pContext.getBlockRenderDispatcher();
|
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.pushPose();
|
||||||
pPoseStack.translate(0.0F, 0.5F, 0.0F);
|
pPoseStack.translate(0.0F, 0.5F, 0.0F);
|
||||||
int i = pEntity.getFuse();
|
int i = pEntity.getFuse();
|
||||||
@ -39,15 +40,12 @@ public class BaseTNTRenderer extends EntityRenderer<BasePrimedTNT> {
|
|||||||
pPoseStack.mulPose(Axis.YP.rotationDegrees(-90.0F));
|
pPoseStack.mulPose(Axis.YP.rotationDegrees(-90.0F));
|
||||||
pPoseStack.translate(-0.5F, -0.5F, 0.5F);
|
pPoseStack.translate(-0.5F, -0.5F, 0.5F);
|
||||||
pPoseStack.mulPose(Axis.YP.rotationDegrees(90.0F));
|
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();
|
pPoseStack.popPose();
|
||||||
super.render(pEntity, pEntityYaw, pPartialTicks, pPoseStack, pBuffer, pPackedLight);
|
super.render(pEntity, pEntityYaw, pPartialTicks, pPoseStack, pBuffer, pPackedLight);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public ResourceLocation getTextureLocation(basePrimedTNT pEntity) {
|
||||||
* Returns the location of an entity's texture.
|
|
||||||
*/
|
|
||||||
public ResourceLocation getTextureLocation(BasePrimedTNT pEntity) {
|
|
||||||
return TextureAtlas.LOCATION_BLOCKS;
|
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;
|
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.EntityType;
|
||||||
import net.minecraft.world.entity.MobCategory;
|
import net.minecraft.world.entity.MobCategory;
|
||||||
import net.minecraftforge.eventbus.api.IEventBus;
|
import net.minecraftforge.eventbus.api.IEventBus;
|
||||||
@ -15,9 +18,25 @@ public class entities {
|
|||||||
|
|
||||||
public static final RegistryObject<EntityType<homingPrimedTNT>> TNT_HOMING =
|
public static final RegistryObject<EntityType<homingPrimedTNT>> TNT_HOMING =
|
||||||
ENTITY_TYPES.register("tnt_homing", () -> EntityType.Builder.<homingPrimedTNT>of(homingPrimedTNT::new, MobCategory.MISC)
|
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) {
|
public static void register(IEventBus eventBus) {
|
||||||
ENTITY_TYPES.register(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;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class homingPrimedTNT extends BasePrimedTNT {
|
public class homingPrimedTNT extends basePrimedTNT {
|
||||||
float pRadius = 0;
|
|
||||||
float speed = 0;
|
float speed = 0;
|
||||||
Entity target;
|
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) {
|
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(entities.TNT_HOMING.get(), pLevel);
|
||||||
this.setPos(pX, pY, pZ);
|
this.setPos(pX, pY, pZ);
|
||||||
this.owner = pOwner;
|
this.setOwner(pOwner);
|
||||||
this.pRadius = power;
|
|
||||||
this.speed = speed;
|
this.speed = speed;
|
||||||
this.target = null;
|
this.target = null;
|
||||||
this.setPower(power);
|
this.setPower(power);
|
||||||
@ -29,7 +24,7 @@ public class homingPrimedTNT extends BasePrimedTNT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public homingPrimedTNT(EntityType<homingPrimedTNT> entityType, Level level) {
|
public homingPrimedTNT(EntityType<homingPrimedTNT> entityType, Level level) {
|
||||||
super(entityType, level);
|
super(entityType, level, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vec3 targetVector() {
|
private Vec3 targetVector() {
|
||||||
@ -68,12 +63,6 @@ public class homingPrimedTNT extends BasePrimedTNT {
|
|||||||
super.tick();
|
super.tick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public LivingEntity getOwner() {
|
|
||||||
return this.owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected float getEyeHeight(@NotNull Pose pPose, @NotNull EntityDimensions pSize) {
|
protected float getEyeHeight(@NotNull Pose pPose, @NotNull EntityDimensions pSize) {
|
||||||
return 0.15F;
|
return 0.15F;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"variants": {
|
||||||
|
"": {
|
||||||
|
"model": "compressedtnt:block/tnt_homing"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"type": "minecraft:crafting_shapeless",
|
||||||
|
"category": "redstone",
|
||||||
|
"ingredients":[
|
||||||
|
{
|
||||||
|
"item": "minecraft:tnt"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"item": "minecraft:ender_eye"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"result": {
|
||||||
|
"item": "compressedtnt:tnt_homing"
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user