Jump to content

[1.7.10] Problem with invisible TNT entity


BlackHole

Recommended Posts

So, I'm trying to make a custom explosive block, and the problem is that the primed explosive entity is invisible. It is there, and it explodes, but it's invisible. Here are the relevant parts of the code :

 

The class for the entity

 

package com.ceselegend.rozmod.entity;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;

public class RozNukePrimed extends Entity {

    public int fuse;
    private EntityLivingBase tntPlacedBy;

    public RozNukePrimed(World world) {
        super(world);
        this.preventEntitySpawning = true;
        this.setSize(0.98F, 0.98F);
        this.yOffset = this.height / 2.0F;
    }

    public RozNukePrimed(World world, double posX, double posY, double posZ, EntityLivingBase entity) {
        this(world);
        this.setPosition(posX, posY, posZ);
        float f = (float)(Math.random() * Math.PI * 2.0D);
        this.motionX = (double)(-((float)Math.sin((double)f)) * 0.02F);
        this.motionY = 0.20000000298023224D;
        this.motionZ = (double)(-((float)Math.cos((double)f)) * 0.02F);
        this.fuse = 80;
        this.prevPosX = posX;
        this.prevPosY = posY;
        this.prevPosZ = posZ;
        this.tntPlacedBy = entity;
    }

    protected void entityInit() {}

    /**
     * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
     * prevent them from trampling crops
     */
    protected boolean canTriggerWalking()
    {
        return false;
    }

    /**
     * Returns true if other Entities should be prevented from moving through this Entity.
     */
    public boolean canBeCollidedWith()
    {
        return !this.isDead;
    }

    /**
     * Called to update the entity's position/logic.
     */
    public void onUpdate()
    {
        this.prevPosX = this.posX;
        this.prevPosY = this.posY;
        this.prevPosZ = this.posZ;
        this.motionY -= 0.03999999910593033D;
        this.moveEntity(this.motionX, this.motionY, this.motionZ);
        this.motionX *= 0.9800000190734863D;
        this.motionY *= 0.9800000190734863D;
        this.motionZ *= 0.9800000190734863D;

        if (this.onGround)
        {
            this.motionX *= 0.699999988079071D;
            this.motionZ *= 0.699999988079071D;
            this.motionY *= -0.5D;
        }

        if (this.fuse-- <= 0)
        {
            this.setDead();

            if (!this.worldObj.isRemote)
            {
                this.explode();
            }
        }
        else
        {
            this.worldObj.spawnParticle("smoke", this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D);
        }
    }

    private void explode()
    {
        float f = 32.0F;
        this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, f, true);
    }

    /**
     * (abstract) Protected helper method to write subclass entity data to NBT.
     */
    protected void writeEntityToNBT(NBTTagCompound tagNBT)
    {
        tagNBT.setByte("Fuse", (byte)this.fuse);
    }

    /**
     * (abstract) Protected helper method to read subclass entity data from NBT.
     */
    protected void readEntityFromNBT(NBTTagCompound tagNBT)
    {
        this.fuse = tagNBT.getByte("Fuse");
    }

    @SideOnly(Side.CLIENT)
    public float getShadowSize()
    {
        return 0.0F;
    }

    /**
     * returns null or the entityliving it was placed or ignited by
     */
    public EntityLivingBase getTntPlacedBy()
    {
        return this.tntPlacedBy;
    }
}

 

 

Then renderer class associated with it :

 

package com.ceselegend.rozmod.render;


import com.ceselegend.rozmod.entity.RozNukePrimed;
import com.ceselegend.rozmod.init.ModBlocks;
import com.ceselegend.rozmod.utility.LogHelper;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;

@SideOnly(Side.CLIENT)
public class RenderRozNukePrimed extends Render {
    private RenderBlocks blockRenderer = new RenderBlocks();
    private static final ResourceLocation entityTexture = new ResourceLocation("RozNuke_side.png");

    public RenderRozNukePrimed()
    {
        this.shadowSize = 0.5F;
    }

    /**
     * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
     * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
     * (Render<T extends Entity) and this method has signature public void func_76986_a(T entity, double d, double d1,
     * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
     */
    public void doRender(RozNukePrimed p_76986_1_, double p_76986_2_, double p_76986_4_, double p_76986_6_, float p_76986_8_, float p_76986_9_)
    {
        LogHelper.info("Render called !");
        GL11.glPushMatrix();
        GL11.glTranslatef((float)p_76986_2_, (float)p_76986_4_, (float)p_76986_6_);
        float f2;

        if ((float)p_76986_1_.fuse - p_76986_9_ + 1.0F < 10.0F)
        {
            f2 = 1.0F - ((float)p_76986_1_.fuse - p_76986_9_ + 1.0F) / 10.0F;

            if (f2 < 0.0F)
            {
                f2 = 0.0F;
            }

            if (f2 > 1.0F)
            {
                f2 = 1.0F;
            }

            f2 *= f2;
            f2 *= f2;
            float f3 = 1.0F + f2 * 0.3F;
            GL11.glScalef(f3, f3, f3);
        }

        f2 = (1.0F - ((float)p_76986_1_.fuse - p_76986_9_ + 1.0F) / 100.0F) * 0.8F;
        this.bindEntityTexture(p_76986_1_);
        this.blockRenderer.renderBlockAsItem(ModBlocks.rozNuke, 0, p_76986_1_.getBrightness(p_76986_9_));

        if (p_76986_1_.fuse / 5 % 2 == 0)
        {
            GL11.glDisable(GL11.GL_TEXTURE_2D);
            GL11.glDisable(GL11.GL_LIGHTING);
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_DST_ALPHA);
            GL11.glColor4f(1.0F, 1.0F, 1.0F, f2);
            this.blockRenderer.renderBlockAsItem(ModBlocks.rozNuke, 0, 1.0F);
            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
            GL11.glDisable(GL11.GL_BLEND);
            GL11.glEnable(GL11.GL_LIGHTING);
            GL11.glEnable(GL11.GL_TEXTURE_2D);
        }

        GL11.glPopMatrix();
    }

    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected ResourceLocation getEntityTexture(RozNukePrimed p_110775_1_)
    {
        return entityTexture;
    }

    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected ResourceLocation getEntityTexture(Entity p_110775_1_)
    {
        return this.getEntityTexture((RozNukePrimed)p_110775_1_);
    }

    /**
     * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
     * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
     * (Render<T extends Entity) and this method has signature public void func_76986_a(T entity, double d, double d1,
     * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
     */
    public void doRender(Entity p_76986_1_, double p_76986_2_, double p_76986_4_, double p_76986_6_, float p_76986_8_, float p_76986_9_)
    {
        this.doRender((RozNukePrimed)p_76986_1_, p_76986_2_, p_76986_4_, p_76986_6_, p_76986_8_, p_76986_9_);
    }
}

 

 

The registering of the renderer in the ClientProxy :

 

RenderingRegistry.registerEntityRenderingHandler(RozNukePrimed.class, new RenderRozNukePrimed());

 

 

The entity registering in the main file :

 

 EntityRegistry.registerGlobalEntityID(RozNukePrimed.class, "rozNukePrimed", EntityRegistry.findGlobalUniqueEntityId());
        EntityRegistry.registerModEntity(RozNukePrimed.class,"rozNukePrimed",1,this,128,1,false);

 

 

I've tried to add some debug lines, and it seems that the doRender() method of the renderer is never called, in fact the constructor of the renderer class never seems to be called; if that can help.

signat10.png
Link to comment
Share on other sites

Are you sure it's never called?

 

if this is called RenderingRegistry.registerEntityRenderingHandler(RozNukePrimed.class, new RenderRozNukePrimed()); then the constructor for RenderRozNukePrimed is called, even if the registerEntityRenderingHandler fails the method parameters are executed before.

 

Put a debug line on the "RenderingRegistry.registerEntityRenderingHandler(RozNukePrimed.class, new RenderRozNukePrimed());" line and check if that line is getting executed, because I have a feeling it's not.

I require Java, both the coffee and the code :)

Link to comment
Share on other sites

Are you sure it's never called?

 

if this is called RenderingRegistry.registerEntityRenderingHandler(RozNukePrimed.class, new RenderRozNukePrimed()); then the constructor for RenderRozNukePrimed is called, even if the registerEntityRenderingHandler fails the method parameters are executed before.

 

Put a debug line on the "RenderingRegistry.registerEntityRenderingHandler(RozNukePrimed.class, new RenderRozNukePrimed());" line and check if that line is getting executed, because I have a feeling it's not.

That's what I first though, but if I put a debug line in the function that executes that line it says it is, which is why I'm stumped by the fact that if I put the line in the constructor it doesn't show up.

signat10.png
Link to comment
Share on other sites

RenderingRegistry.registerEntityRenderingHandler(RozNukePrimed.class, new RenderRozNukePrimed())

Where do you call that method?

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

RenderingRegistry.registerEntityRenderingHandler(RozNukePrimed.class, new RenderRozNukePrimed())

Where do you call that method?

In the ClientProxy class. Here is the complete code for the Client Proxy class :

 

package com.ceselegend.rozmod.proxy;

import com.ceselegend.rozmod.entity.RozNukePrimed;
import com.ceselegend.rozmod.render.RenderRozNukePrimed;
import cpw.mods.fml.client.registry.RenderingRegistry;

public class ClientProxy extends CommonProxy {

    @Override
    public void registerRenderers() {
        RenderingRegistry.registerEntityRenderingHandler(RozNukePrimed.class, new RenderRozNukePrimed());
    }

    @Override
    public ClientProxy getClientProxy() {
        return this;
    }
}

 

 

The proxy method is called in the main mod preInit method like this :

proxy.registerRenderers();

 

For more details on the code, here is the link to the code's GitHub

signat10.png
Link to comment
Share on other sites

This is one of my custom renderers from a mod I'm working on, this is all executed on preInit

 

@Override
public void registerCustomBlockRenderers()
{
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityPaintableBlockEntity.class, new TileEntityPaintableBlockRenderer());
GameRegistry.registerTileEntity(TileEntityPaintableBlockEntity.class, "tileEntityPaintableBlock");

Reference.PAINTER_BLOCK_RENDERING_HANDLER_ID = RenderingRegistry.getNextAvailableRenderId();
RenderingRegistry.registerBlockHandler(new PainterBlockRenderingHandler(Reference.PAINTER_BLOCK_RENDERING_HANDLER_ID));
}

 

Try and replace your code with mine, see how it works... I think you need to bind the entity with the bindTileEntitySpecialRenderer

I require Java, both the coffee and the code :)

Link to comment
Share on other sites

This is one of my custom renderers from a mod I'm working on, this is all executed on preInit

 

@Override
public void registerCustomBlockRenderers()
{
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityPaintableBlockEntity.class, new TileEntityPaintableBlockRenderer());
GameRegistry.registerTileEntity(TileEntityPaintableBlockEntity.class, "tileEntityPaintableBlock");

Reference.PAINTER_BLOCK_RENDERING_HANDLER_ID = RenderingRegistry.getNextAvailableRenderId();
RenderingRegistry.registerBlockHandler(new PainterBlockRenderingHandler(Reference.PAINTER_BLOCK_RENDERING_HANDLER_ID));
}

 

Try and replace your code with mine, see how it works... I think you need to bind the entity with the bindTileEntitySpecialRenderer

That is for blocks, but he has problems with entities...

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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