Posted November 4, 20204 yr I have already made a custom TNT entity and a custom TNT block using the vanilla classes. But, How do I render the custom TNT? Edited November 4, 20204 yr by someRandomKid
November 4, 20204 yr You need an entity renderer...look at vanilla TNTRenderer Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
November 4, 20204 yr Author I have already tried that, I just get an invisible entity. Do I have to stitch my texture into the atlas? Edited November 4, 20204 yr by someRandomKid
November 4, 20204 yr Did you bind your entity renderer to your entity? You can do that with RenderingRegistry.registerEntityRenderingHandler Edited November 4, 20204 yr by Beethoven92 Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
November 5, 20204 yr Author Quote Did you bind your entity renderer to your entity? You can do that with RenderingRegistry.registerEntityRenderingHandler yes, I already have. Basically I get no errors in the output log, but the entity is invisible. Edited November 5, 20204 yr by someRandomKid
November 5, 20204 yr All right, can you show your code please? Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
November 5, 20204 yr Author public class MegaTNTRenderer extends EntityRenderer<MegaTNTEntity> { @Override public void render(MegaTNTEntity entityIn, float entityYaw, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int packedLightIn) { matrixStackIn.push(); matrixStackIn.translate(0.0D, 0.5D, 0.0D); if ((float)entityIn.getFuse() - partialTicks + 1.0F < 10.0F) { float f = 1.0F - ((float)entityIn.getFuse() - partialTicks + 1.0F) / 10.0F; f = MathHelper.clamp(f, 0.0F, 1.0F); f = f * f; f = f * f; float f1 = 1.0F + f * 0.3F; matrixStackIn.scale(f1, f1, f1); } matrixStackIn.rotate(Vector3f.YP.rotationDegrees(-90.0F)); matrixStackIn.translate(-0.5D, -0.5D, 0.5D); matrixStackIn.rotate(Vector3f.YP.rotationDegrees(90.0F)); TNTMinecartRenderer.renderTntFlash(RegistryHandler.MEGA_TNT.get().getDefaultState(), matrixStackIn, bufferIn, packedLightIn, entityIn.getFuse() / 5 % 2 == 0); matrixStackIn.pop(); super.render(entityIn, entityYaw, partialTicks, matrixStackIn, bufferIn, packedLightIn); } public MegaTNTRenderer(EntityRendererManager renderManager) { super(renderManager); this.shadowSize = 0.5F; } @Override public ResourceLocation getEntityTexture(MegaTNTEntity entity) { return PlayerContainer.LOCATION_BLOCKS_TEXTURE; } } Tell me if you need more code. Edited November 5, 20204 yr by someRandomKid
November 5, 20204 yr Show also the MegaTNTEntity class please Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
November 5, 20204 yr Author public class MegaTNTEntity extends Entity { private static final DataParameter<Integer> FUSE = EntityDataManager.createKey(MegaTNTEntity.class, DataSerializers.VARINT); @Nullable private LivingEntity tntPlacedBy; private int fuse; public MegaTNTEntity(EntityType<? extends MegaTNTEntity> type, World worldIn) { super(type, worldIn); } public MegaTNTEntity(World worldIn, double x, double y, double z, @Nullable LivingEntity igniter) { this(RegistryHandler.MEGA_TNT_ENTITY.get(),worldIn); this.setPosition(x, y, z); double d0 = worldIn.rand.nextDouble() * (double)((float)Math.PI * 2F); this.setMotion(-Math.sin(d0) * 0.02D, 0.2D, -Math.cos(d0) * 0.02D); this.prevPosX = x; this.prevPosY = y; this.prevPosZ = z; this.fuse = 120; this.tntPlacedBy = igniter; } @Nullable public LivingEntity getTntPlacedBy() { return this.tntPlacedBy; } public void setFuse(int fuse) { this.fuse = fuse; } public boolean canBeCollidedWith() { return false; } @Override protected void registerData() { this.dataManager.register(FUSE, 80); } @Override public void writeAdditional(CompoundNBT compound) { compound.putShort("Fuse", (short)this.getFuse()); } /** * (abstract) Protected helper method to read subclass entity data from NBT. */ @Override public void readAdditional(CompoundNBT compound) { this.setFuse(compound.getShort("Fuse")); } @Override public void tick() { //new_swords.LOGGER.info(this.fuse); //new_swords.LOGGER.info(this.getPosX() + "," + this.getPosY() + "," + this.getPosZ()); //new_swords.LOGGER.info("on ground? " + this.onGround); if (!this.hasNoGravity()) { this.setMotion(this.getMotion().add(0.0D, -0.04D, 0.0D)); } this.move(MoverType.SELF, this.getMotion()); this.setMotion(this.getMotion().scale(0.98D)); if (this.onGround) { this.setMotion(this.getMotion().mul(0.7D, -0.5D, 0.7D)); } --this.fuse; if (this.fuse <= 0) { this.remove(); if (!this.world.isRemote) { this.explode(); } } else { this.handleWaterMovement(); if (this.world.isRemote) { this.world.addParticle(ParticleTypes.SMOKE, this.getPosX(), this.getPosY() + 0.5D, this.getPosZ(), 0.0D, 0.0D, 0.0D); } } } protected void explode() { float f = 20.0f; new_swords.LOGGER.info("exploding?"); MinecraftServer server = this.getServer(); if(server == null) return; ServerWorld world = server.getWorld(this.dimension); world.createExplosion(this, this.getPosX(), this.getPosYHeight(0.0625D), this.getPosZ(), f, Explosion.Mode.BREAK); } public int getFuse() { return this.fuse; } public void notifyDataManagerChange(DataParameter<?> key) { if (FUSE.equals(key)) { this.fuse = this.getFuseDataManager(); } } /** * Gets the fuse from the data manager */ public int getFuseDataManager() { return this.dataManager.get(FUSE); } public @NotNull IPacket<?> createSpawnPacket() { return new SSpawnObjectPacket(this); } }
November 5, 20204 yr This code seems to be the problem: public @NotNull IPacket<?> createSpawnPacket() { return new SSpawnObjectPacket(this); } You cannot use the vanilla spawn packet here, you need to override createSpawnPacket with: return NetworkHooks.getEntitySpawningPacket(this); otherwise your entity will be existing only on the server and so invisibile to you on the client Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port
November 5, 20204 yr Author Works now, but since my fuse is 40 longer than the vanilla fuse, my tnt disappears too early.
November 5, 20204 yr Author I fixed the bug, thanks for helping! Edited November 5, 20204 yr by someRandomKid
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.