Jump to content

[Unsolved] [1.8] Can't get texture to show up for entity similar to TNTPrimed


サムエル

Recommended Posts

I'm making a mod block called the "chaos block" which will explode suddenly under certain circumstances. When it's set off, it mimics the TNT block and creates an entity EntityBlockChaosPrimed which is very close to EntityTNTPrimed. It also uses its own entity render file called RenderBlockChaosPrimed which is also much like its TNT counterpart. Everything seems to be working fine except that I can't get the texture to show up. I've searched for many hours and tried different methods but so far nothing has worked. I considered making a second blockstate for BlockChaos and using that instead of netherrack in the render file but I don't know how to do that yet and if I can do it with a simple ResourceLocation I'd like to do that. The entity is registered and the rest of the render file works fine so I don't believe that's part of the problem.

 

Here is the relevant code:

 

EntityBlockChaosPrimed.java:

 

package com.samuel.chaosblock.entities;

 

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.util.EnumParticleTypes;

import net.minecraft.world.World;

 

public class EntityBlockChaosPrimed extends Entity

{

    /** How long the fuse is */

    public int fuse;

    private EntityLivingBase tntPlacedBy;

 

    public EntityBlockChaosPrimed(World worldIn)

    {

        super(worldIn);

        this.preventEntitySpawning = true;

        this.setSize(0.98F, 0.98F);

    }

 

    public EntityBlockChaosPrimed(World worldIn, double posX, double posY, double posZ, EntityLivingBase elb)

    {

        this(worldIn);

        this.setPosition(posX, posY, posZ);

        float var9 = (float)(Math.random() * Math.PI * 2.0D);

        //this.motionX = (double)(-((float)Math.sin((double)var9)) * 0.02F);

        this.motionY = 0.20000000298023224D;

        //this.motionZ = (double)(-((float)Math.cos((double)var9)) * 0.02F);

        this.fuse = 20;

        //this.prevPosX = posX;

        this.prevPosY = posY;

        //this.prevPosZ = posZ;

        this.tntPlacedBy = elb;

    }

 

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

 

            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 var1 = 4.0F;

        this.worldObj.createExplosion(this, this.posX, this.posY + (double)(this.height / 2.0F), this.posZ, var1, 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;

    }

}

 

 

RenderBlockChaosPrimed.java:

 

package com.samuel.chaosblock.client.render.entities;

 

import com.samuel.chaosblock.BlockChaos;

import com.samuel.chaosblock.ChaosBlock;

import com.samuel.chaosblock.entities.EntityBlockChaosPrimed;

 

import net.minecraft.client.Minecraft;

import net.minecraft.client.renderer.BlockRendererDispatcher;

import net.minecraft.client.renderer.GlStateManager;

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

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

import net.minecraft.client.renderer.texture.TextureMap;

import net.minecraft.entity.Entity;

import net.minecraft.init.Blocks;

import net.minecraft.util.MathHelper;

import net.minecraft.util.ResourceLocation;

 

public class RenderBlockChaosPrimed extends Render {

 

    private static final ResourceLocation Texture = new ResourceLocation("chaosblock:textures/entities/chaos_block_primed.png");

 

    public RenderBlockChaosPrimed(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 doRender(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(EntityBlockChaosPrimed entity, double p_76986_2_, double p_76986_4_, double p_76986_6_, float p_76986_8_, float p_76986_9_)

    {

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

        GlStateManager.pushMatrix();

        GlStateManager.translate((float)p_76986_2_, (float)p_76986_4_ + 0.5F, (float)p_76986_6_);

        float var11;

 

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

        {

            var11 = 1.0F - ((float)entity.fuse - p_76986_9_ + 1.0F) / 10.0F;

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

            var11 *= var11;

            var11 *= var11;

            float var12 = 1.0F + var11 * 0.3F;

            GlStateManager.scale(var12, var12, var12);

        }

 

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

        this.bindEntityTexture(entity);

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

        var10.renderBlockBrightness(Blocks.netherrack.getDefaultState(), entity.getBrightness(p_76986_9_));

        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, var11);

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

            GlStateManager.enablePolygonOffset();

            var10.renderBlockBrightness(BlockChaos.getStateById(1), 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, p_76986_2_, p_76986_4_, p_76986_6_, p_76986_8_, p_76986_9_);

    }

   

    protected ResourceLocation setEntityTexture(EntityBlockChaosPrimed p_180563_1_)

    {

        return Texture;

    }

 

    /**

    * 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 setEntityTexture((EntityBlockChaosPrimed)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 doRender(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((EntityBlockChaosPrimed)p_76986_1_, p_76986_2_, p_76986_4_, p_76986_6_, p_76986_8_, p_76986_9_);

    }

}

 

 

The texture file is located in "assets/chaosblock/textures/entities/" and is named the same as in the render file.

 

Edit: Also, if anyone might be able to tell me how to give this block a custom explosion sound without modifying the regular explosion sound, I'd really appreciate it.

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.