Jump to content

Recommended Posts

Posted

Help! I am trying to make a custom TNT block and my texture isnt working. Heres my Block class:

package sg1Dev.TUTmod.blocks;

import net.minecraft.block.BlockTNT;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityTNTPrimed;
import net.minecraft.util.BlockPos;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import sg1Dev.TUTmod.YTTM;
import sg1Dev.TUTmod.world.EntityTestTNTPrimed;

public class BlockTestTNT extends BlockTNT
{
    public BlockTestTNT()
    {
        setHardness(0.0f);
        
        setHardness(2F);
        setResistance(3F);
        setStepSound(soundTypeGrass);
        setCreativeTab(YTTM.tabTutorial);
    }
    /**
     * Called upon the block being destroyed by an explosion
     */
    @Override
    public void onBlockDestroyedByExplosion(World par1World, BlockPos pos, Explosion par5Explosion)
    {
        if(!par1World.isRemote)
        {
            EntityTestTNTPrimed entitytntprimed = new EntityTestTNTPrimed(par1World, (double) ((float) pos.getX() + 0.5F), (double) ((float) pos.getY() + 0.5F), (double) ((float) pos.getZ() + 0.5F), par5Explosion.getExplosivePlacedBy());
            entitytntprimed.fuse = par1World.rand.nextInt(entitytntprimed.fuse / 4) + entitytntprimed.fuse / 8;
            par1World.spawnEntityInWorld(entitytntprimed);
        }
    }
    /**
     * Called right before the block is destroyed by a player. Args: world, x, y, z, metaData
     */
    @Override
    public void onBlockDestroyedByPlayer(World worldIn, BlockPos pos, IBlockState state)
    {
        this.explode(worldIn, pos, state, (EntityLivingBase) null);
    }
    
    public void explode(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase igniter)
    {
        if(!worldIn.isRemote)
        {
            if(((Boolean) state.getValue(EXPLODE)).booleanValue())
            {
                EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(worldIn, (double) ((float) pos.getX() + 0.5F), (double) ((float) pos.getY() + 0.5F), (double) ((float) pos.getZ() + 0.5F), igniter);
                worldIn.spawnEntityInWorld(entitytntprimed);
                worldIn.playSoundAtEntity(entitytntprimed, "game.tnt.primed", 1.0F, 1.0F);
            }
        }
    }
}

 

Heres my Entity class:

package sg1Dev.TUTmod.world;

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 EntityTestTNTPrimed extends EntityTNTPrimed
{

    private EntityLivingBase tntPlacedBy;
    public EntityTestTNTPrimed(World worldIn) 
    {
        super(worldIn);
    }
    public EntityTestTNTPrimed(World worldIn, double p_i1730_2_, double p_i1730_4_, double p_i1730_6_, EntityLivingBase entity)
    {
        this(worldIn);
        this.fuse = 85;
        this.tntPlacedBy = entity;
    }
    /**
     * 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.NOTE, this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D, new int[0]);
        }
    }
    private void explode()
    {
         float f = 8.0F;
         this.worldObj.createExplosion(this, this.posX, this.posY + (double) (this.height / 2.0F), this.posZ, f, true);
    }
    /**
     * (abstract) Protected helper method to read subclass entity data from NBT.
     */
    protected void readEntityFromNBT(NBTTagCompound tagCompound)
    {
        this.fuse = tagCompound.getByte("Fuse");
    }
    /**
     * returns null or the entityliving it was placed or ignited by
     */
    public EntityLivingBase getTntPlacedBy()
    {
        return this.tntPlacedBy;
    }
}

and my render class:

package sg1Dev.TUTmod.util;

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.client.renderer.texture.TextureMap;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityTNTPrimed;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import sg1Dev.TUTmod.YTTM;
import sg1Dev.TUTmod.world.EntityTestTNTPrimed;

@SideOnly(Side.CLIENT)
public class RenderTestTNTPrimed extends RenderTNTPrimed
{

    public RenderTestTNTPrimed(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 probability, the calss 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(EntityTNTPrimed entity, double x, double y, double z, float f, 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.F < 10.0F)
        {
            f2 = (float) (1.0 - ((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(YTTM.testTNT.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(YTTM.testTNT.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, f, partialTicks);
    }
    
    protected ResourceLocation func_180563_a(EntityTestTNTPrimed tntPrimed)
    {
        return TextureMap.locationBlocksTexture;
    }
    
    protected ResourceLocation getEntityTexture(Entity entity)
    {
        return this.func_180563_a((EntityTestTNTPrimed)entity);
    }
    
    public void doRender(Entity entity, double x, double y, double z, float p_76986_8_, float partialTicks)
    {
        this.doRender((EntityTestTNTPrimed)entity, x, y, z, p_76986_8_, partialTicks);
    }
}

 

my Blockstates json:

{
    "variants": {
        "normal": [
            { "model": "yt_tm:blocks/test_tnt" },
            { "model": "yt_tm:blocks/test_tnt", "y": 90 },
            { "model": "yt_tm:blocks/test_tnt", "y": 180 },
            { "model": "yt_tm:blocks/test_tnt", "y": 270 }
        ]
    }
}
and Block JSON:

{
    "parent": "block/cube_bottom_top",
    "textures": {
        "bottom": "yt_tm:blocks/test_tnt_bottom",
        "top": "yt_tm:blocks/test_tnt_top",
        "side": "yt_tm:blocks/test_tnt_side"
    }
}
an anyone help?

Posted

1.8 is the easiest version to write mods for me anyways. I don't know how to do this 1.11-1.12.2 stuff.

14 hours ago, diesieben07 said:

No, use 1.12.2. If you for some reason must use the 1.8.x versions, use the most up to date one, 1.8.9.

 

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.