Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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 by someRandomKid

  • Author

I have already tried that, I just get an invisible entity.

Do I have to stitch my texture into the atlas?

Edited by someRandomKid

  • 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 by someRandomKid

  • 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 by someRandomKid

  • 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);
    }
}

 

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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.