Jump to content

1.8 Custom TNT Rendering Error


Born2Code

Recommended Posts

Hello, I'm working on a mod that has a tnt launcher. Well the basic primed tnt entity simply falls to the ground which I don't want. So I made my own custom tnt entity to change that (so that it shoots out), but for some reason I can't get it to render. Currently both my render class and entity class are the same as the originals. Any amount of help is appreciated.

 

Main Mod File

 

package teampap.grenade;

 

import net.minecraft.client.Minecraft;

import net.minecraftforge.fml.common.Mod;

import net.minecraftforge.fml.common.SidedProxy;

import net.minecraftforge.fml.common.event.FMLInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;

import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

import net.minecraftforge.fml.common.registry.EntityRegistry;

import teampap.grenade.entities.EntityGrenade;

import teampap.grenade.entities.EntityImpactGrenade;

import teampap.grenade.entities.EntityMyTNT;

import teampap.grenade.entities.EntitySafeGrenade;

import teampap.grenade.items.ModItems;

import teampap.grenade.lib.Constants;

import teampap.grenade.lib.proxies.CommonProxy;

 

@Mod(modid = Constants.MODID, name = Constants.MODNAME, version = Constants.MODVERSION)

public class Grenade

{

 

    @SidedProxy(clientSide = Constants.CLIENTPROXY, serverSide = Constants.COMMONPROXY)

    public static CommonProxy proxy;

 

    @Mod.EventHandler

    public void preInit(FMLPreInitializationEvent event)

    {

        ModItems.init();

    }

 

    @Mod.EventHandler

    public void init(FMLInitializationEvent event)

    {

        EntityRegistry.registerModEntity(EntityGrenade.class,      "Grenade",      4, this, 80, 3, true);

        EntityRegistry.registerModEntity(EntitySafeGrenade.class,  "SafeGrenade",  5, this, 80, 3, true);

        EntityRegistry.registerModEntity(EntityImpactGrenade.class, "ImpactGrenade", 6, this, 80, 3, true);

        EntityRegistry.registerModEntity(EntityMyTNT.class,        "MyTNT",        7, this, 80, 3, true);

 

        ModItems.register();

        ModItems.registerRenders();

        proxy.registerRenderThings();

    }

 

    @Mod.EventHandler

    public void postInit(FMLPostInitializationEvent event)

    {

 

    }

}

 

 

 

ClientProxy

 

package teampap.grenade.lib.proxies;

 

import net.minecraft.client.Minecraft;

import net.minecraft.client.model.ModelCow;

import net.minecraft.client.renderer.entity.RenderCow;

import net.minecraft.client.renderer.entity.RenderSnowball;

import net.minecraft.client.renderer.entity.RenderTNTPrimed;

import net.minecraftforge.fml.client.registry.RenderingRegistry;

import teampap.grenade.entities.EntityGrenade;

import teampap.grenade.entities.EntityImpactGrenade;

import teampap.grenade.entities.EntityMyTNT;

import teampap.grenade.entities.EntitySafeGrenade;

import teampap.grenade.items.ModItems;

import teampap.grenade.renderers.RenderMyTNT;

 

public class ClientProxy extends CommonProxy

{

    public void registerRenderThings()

    {

        RenderingRegistry.registerEntityRenderingHandler(EntityGrenade.class,      new RenderSnowball(Minecraft.getMinecraft().getRenderManager(), ModItems.grenade, Minecraft.getMinecraft().getRenderItem()));

        RenderingRegistry.registerEntityRenderingHandler(EntitySafeGrenade.class,  new RenderSnowball(Minecraft.getMinecraft().getRenderManager(), ModItems.safeGrenade, Minecraft.getMinecraft().getRenderItem()));

        RenderingRegistry.registerEntityRenderingHandler(EntityImpactGrenade.class, new RenderSnowball(Minecraft.getMinecraft().getRenderManager(), ModItems.impactGrenade, Minecraft.getMinecraft().getRenderItem()));

        RenderingRegistry.registerEntityRenderingHandler(EntityMyTNT.class, new RenderMyTNT(Minecraft.getMinecraft().getRenderManager()));

 

    }

}

 

 

 

EntityMyTNT

 

package teampap.grenade.entities;

 

 

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.item.EntityTNTPrimed;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.util.EnumParticleTypes;

import net.minecraft.world.World;

 

public class EntityMyTNT extends EntityTNTPrimed

{

    /** How long the fuse is */

    public int fuse;

    private EntityLivingBase tntPlacedBy;

    private static final String __OBFID = "CL_00001681";

 

    public EntityMyTNT(World worldIn)

    {

        super(worldIn);

        this.preventEntitySpawning = true;

        this.setSize(0.98F, 0.98F);

    }

 

    public EntityMyTNT(World worldIn, double p_i1730_2_, double p_i1730_4_, double p_i1730_6_, EntityLivingBase p_i1730_8_)

    {

        this(worldIn);

        this.setPosition(p_i1730_2_, p_i1730_4_, p_i1730_6_);

        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 = p_i1730_2_;

        this.prevPosY = p_i1730_4_;

        this.prevPosZ = p_i1730_6_;

        this.tntPlacedBy = p_i1730_8_;

    }

 

    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.handleWaterMovement();

            this.worldObj.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D, new int[0]);

        }

    }

 

    private void explode()

    {

        float f = 4.0F;

        this.worldObj.createExplosion(this, this.posX, this.posY + (double) (this.height / 2.0F), this.posZ, f, true);

    }

 

    /**

    * (abstract) Protected helper method to write subclass entity data to NBT.

    */

    protected void writeEntityToNBT(NBTTagCompound tagCompound)

    {

        tagCompound.setByte("Fuse", (byte) this.fuse);

    }

 

    /**

    * (abstract) Protected helper method to read subclass entity data from NBT.

    */

    protected void readEntityFromNBT(NBTTagCompound tagCompund)

    {

        this.fuse = tagCompund.getByte("Fuse");

    }

 

    /**

    * returns null or the entityliving it was placed or ignited by

    */

    public EntityLivingBase getTntPlacedBy()

    {

        return this.tntPlacedBy;

    }

 

    public float getEyeHeight()

    {

        return 0.0F;

    }

}

 

 

 

RenderMyTNT

 

package teampap.grenade.renderers;

 

import net.minecraft.client.Minecraft;

import net.minecraft.client.renderer.BlockRendererDispatcher;

import net.minecraft.client.renderer.GlStateManager;

import net.minecraft.client.renderer.entity.RenderManager;

import net.minecraft.client.renderer.entity.RenderTNTPrimed;

import net.minecraft.entity.Entity;

import net.minecraft.init.Blocks;

import net.minecraft.util.MathHelper;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

import teampap.grenade.entities.EntityMyTNT;

import teampap.grenade.lib.Constants;

 

@SideOnly(Side.CLIENT)

public class RenderMyTNT extends RenderTNTPrimed

{

    private static final String __OBFID = "CL_00001030";

    private static final ResourceLocation myTexture = new ResourceLocation(Constants.MODID + ":textures/entity/myTNT.png");

 

    public RenderMyTNT(RenderManager p_i46134_1_)

    {

        super(p_i46134_1_);

        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 doe

    */

    public void doRender(EntityMyTNT entity, double x, double y, double z, float p_76986_8_, float partialTicks)

    {

        BlockRendererDispatcher blockrendererdispatcher = Minecraft.getMinecraft().getBlockRendererDispatcher();

        GlStateManager.pushMatrix();

        GlStateManager.translate((float)x, (float)y + 0.5F, (float)z);

        float f2;

 

        if ((float)entity.fuse - partialTicks + 1.0F < 10.0F)

        {

            f2 = 1.0F - ((float)entity.fuse - partialTicks + 1.0F) / 10.0F;

            f2 = MathHelper.clamp_float(f2, 0.0F, 1.0F);

            f2 *= f2;

            f2 *= f2;

            float f3 = 1.0F + f2 * 0.3F;

            GlStateManager.scale(f3, f3, f3);

        }

 

        f2 = (1.0F - ((float)entity.fuse - partialTicks + 1.0F) / 100.0F) * 0.8F;

        this.bindEntityTexture(entity);

        GlStateManager.translate(-0.5F, -0.5F, 0.5F);

        blockrendererdispatcher.renderBlockBrightness(Blocks.tnt.getDefaultState(), entity.getBrightness(partialTicks));

        GlStateManager.translate(0.0F, 0.0F, 1.0F);

 

        if (entity.fuse / 5 % 2 == 0)

        {

            GlStateManager.disableTexture2D();

            GlStateManager.disableLighting();

            GlStateManager.enableBlend();

            GlStateManager.blendFunc(770, 772);

            GlStateManager.color(1.0F, 1.0F, 1.0F, f2);

            GlStateManager.doPolygonOffset(-3.0F, -3.0F);

            GlStateManager.enablePolygonOffset();

            blockrendererdispatcher.renderBlockBrightness(Blocks.tnt.getDefaultState(), 1.0F);

            GlStateManager.doPolygonOffset(0.0F, 0.0F);

            GlStateManager.disablePolygonOffset();

            GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);

            GlStateManager.disableBlend();

            GlStateManager.enableLighting();

            GlStateManager.enableTexture2D();

        }

 

        GlStateManager.popMatrix();

        super.doRender(entity, x, y, z, p_76986_8_, partialTicks);

    }

 

    protected ResourceLocation func_180563_a(EntityMyTNT p_180563_1_)

    {

        return myTexture;

    }

 

    /**

    * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.

    */

    protected ResourceLocation getEntityTexture(Entity entity)

    {

        return this.func_180563_a((EntityMyTNT)entity);

    }

 

    /**

    * 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 doe

    */

    public void doRender(Entity entity, double x, double y, double z, float p_76986_8_, float partialTicks)

    {

        this.doRender((EntityMyTNT)entity, x, y, z, p_76986_8_, partialTicks);

    }

}

 

Link to comment
Share on other sites

Hello, I appreciate the help, but I don't quite see how I would do that. Here is my launcher item class when I spawn the entity, if you could let me know how I would do that I would appreciate that =)

 

package teampap.grenade.items;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.item.EntityTNTPrimed;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import teampap.grenade.lib.Constants;

public class ItemTNTLauncher extends Item
{
    private String name = "tntLauncher";

    public ItemTNTLauncher()
    {
        setUnlocalizedName(Constants.MODID + "_" + name);
        setCreativeTab(CreativeTabs.tabCombat);
    }

    public ItemStack onItemRightClick(ItemStack item, World world, EntityPlayer player)
    {

        item.damageItem(1, player);

        if (!world.isRemote)
        {
            world.spawnEntityInWorld(new EntityTNTPrimed(world, player.posX, player.posY, player.posZ, player));
        }

        return item;

    }
}

Link to comment
Share on other sites

Thanks! One last thing though, how would I know where the player is facing in order to shoot it out in that direction?

 

EntityTNTPrimed mytnt = new EntityTNTPrimed(world, player.posX, player.posY, player.posZ, player);
mytnt.motionX += 10;
world.spawnEntityInWorld(mytnt); 

 

The above works, but it (obviously) only shoots out in one direction.

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.