Jump to content

Recommended Posts

Posted

I am new to Minecraft moding but not to coding or java. I just sat down and created a custom tnt mod and I copied the `EntityTNTPrimed.java`to do a custom explosion but when the block is activated and my `EntityNuclearTntPrimed` gets created it is invisible. Any help would be appreciated.

Posted

You should set up your own entity model.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

You should set up your own entity model.

 

Here is my code:

 

 

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 EntityNuclearTntPrimed extends Entity
{
    public int fuse;
    private EntityLivingBase tntPlacedBy;

    public EntityNuclearTntPrimed(World worldIn)
    {
        super(worldIn);
        this.preventEntitySpawning = true;
        this.setSize(0.98F, 0.98F);
    }

    public EntityNuclearTntPrimed(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() {}

    protected boolean canTriggerWalking()
    {
        return false;
    }

    public boolean canBeCollidedWith()
    {
        return !this.isDead;
    }

    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 size = 50.0F;
        UberTntMod.createLargeExplosion(this.worldObj, this, this.posX, this.posY + (double)(this.height / 2.0F), this.posZ, size, true, true);
    }

    protected void writeEntityToNBT(NBTTagCompound tagCompound)
    {
        tagCompound.setByte("Fuse", (byte)this.fuse);
    }

    protected void readEntityFromNBT(NBTTagCompound tagCompund)
    {
        this.fuse = tagCompund.getByte("Fuse");
    }

    public EntityLivingBase getTntPlacedBy()
    {
        return this.tntPlacedBy;
    }

    public float getEyeHeight()
    {
        return 0.0F;
    }
}

 

 

Posted

1. Post your entity registration code.

2. Did you created/registered your TNT model?

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

My Tnt Block Code:

 

 

public class NuclearTntBlock extends BlockTNT 
{

public NuclearTntBlock () 
    {
	super();
	setHardness(2.0F);
	setStepSound(Block.soundTypeMetal);
        setUnlocalizedName("nuclearTnt");
        setCreativeTab(CreativeTabs.tabRedstone);
    }

@Override
    public void onBlockDestroyedByExplosion(World worldIn, BlockPos pos, Explosion explosionIn)
    {
        if (!worldIn.isRemote)
        {
            EntityNuclearTntPrimed entitytntprimed = new EntityNuclearTntPrimed(worldIn, (double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), explosionIn.getExplosivePlacedBy());
            entitytntprimed.fuse = worldIn.rand.nextInt(entitytntprimed.fuse / 4) + entitytntprimed.fuse / 8;
            worldIn.spawnEntityInWorld(entitytntprimed);
        }
    }

@Override
    public void explode(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase igniter)
    {
        if (!worldIn.isRemote)
        {
            if (((Boolean)state.getValue(EXPLODE)).booleanValue())
            {
                EntityNuclearTntPrimed entitytntprimed = new EntityNuclearTntPrimed(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);
            }
        }
    }
}

 

 

 

My Mod Code:

 

 

@Mod(modid = UberTntMod.MODID, version = UberTntMod.VERSION)
public class UberTntMod
{
    public static final String MODID = "ubertntmod";
    public static final String VERSION = "1.0";
    
    public static Block nuclearTnt;
    
    @EventHandler
    public void preInit(FMLPreInitializationEvent event) 
    {
    	nuclearTnt = new NuclearTntBlock();
        GameRegistry.registerBlock(nuclearTnt, "nuclearTnt");
    }
    
    @EventHandler
    public void init(FMLInitializationEvent event)
    {
    	Item itemBlock = GameRegistry.findItem("ubertntmod", "nuclearTnt");
        ModelResourceLocation itemModelResourceLocation = new ModelResourceLocation("ubertntmod:nuclearTnt", "inventory");
        final int DEFAULT_ITEM_SUBTYPE = 0;
        Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(itemBlock, DEFAULT_ITEM_SUBTYPE, itemModelResourceLocation);
        
        IRecipe nuclearTntRecipe = new ShapedOreRecipe(new ItemStack(nuclearTnt), new Object[] {
            "TTT",
            "TTT",
            "TTT",
            'T', Blocks.tnt,
    });
    GameRegistry.addRecipe(nuclearTntRecipe);
    }
    
    public static LargeExplosion createLargeExplosion(World inWorld, Entity p_72876_1_, double p_72876_2_, double p_72876_4_, double p_72876_6_, float p_72876_8_, boolean p_72876_9_)
    {
        return UberTntMod.newLargeExplosion(inWorld, p_72876_1_, p_72876_2_, p_72876_4_, p_72876_6_, p_72876_8_, true, p_72876_9_);
    }
    
    public static LargeExplosion createLargeExplosion(World inWorld, Entity p_72876_1_, double p_72876_2_, double p_72876_4_, double p_72876_6_, float p_72876_8_, boolean p_72876_9_, boolean p_72876_10_)
    {
        return UberTntMod.newLargeExplosion(inWorld, p_72876_1_, p_72876_2_, p_72876_4_, p_72876_6_, p_72876_8_, p_72876_9_, p_72876_10_);
    }

    private static LargeExplosion newLargeExplosion(World inWorld, Entity p_72885_1_, double p_72885_2_, double p_72885_4_, double p_72885_6_, float p_72885_8_, boolean p_72885_9_, boolean p_72885_10_)
    {
    	LargeExplosion explosion = new LargeExplosion(inWorld, p_72885_1_, p_72885_2_, p_72885_4_, p_72885_6_, p_72885_8_, p_72885_9_, p_72885_10_);
    	if (net.minecraftforge.event.ForgeEventFactory.onExplosionStart(inWorld, explosion.vanillaExplosion)) return explosion;
    	explosion.doLargeExplosionA();
    	explosion.doLargeExplosionB(true);
    	
        return explosion;
    }
}

 

 

Posted

I tried adding:

int entityID = EntityRegistry.findGlobalUniqueEntityId();
EntityRegistry.registerGlobalEntityID(EntityNuclearTntPrimed.class, "nuclearTntPrimed", entityID);

 

but it did not help

Posted

1. First, you should register your Entity using EntityRegistry#registerModEntity.

      (You have to specify the id. If you have only one entity, just putting 0 in it would be fine.)

2. TileEntities and Entities are totally different, just to note.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

Show your tnt entity class. I had the same problem and had to change something in the entity class

 

EDIT:

The entity tnt class has 2 constructors, you need to write this.fuse = whatever number the other one is in the first constructor to.

Posted

 

 

Here is my tnt Entity Code:

 

 

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 EntityNuclearTntPrimed extends Entity
{
    public int fuse;
    private EntityLivingBase tntPlacedBy;

    public EntityNuclearTntPrimed(World worldIn)
    {
        super(worldIn);
        this.preventEntitySpawning = true;
        this.setSize(0.98F, 0.98F);
    }

    public EntityNuclearTntPrimed(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() {}

    protected boolean canTriggerWalking()
    {
        return false;
    }

    public boolean canBeCollidedWith()
    {
        return !this.isDead;
    }

    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 size = 50.0F;
        UberTntMod.createLargeExplosion(this.worldObj, this, this.posX, this.posY + (double)(this.height / 2.0F), this.posZ, size, true, true);
    }

    protected void writeEntityToNBT(NBTTagCompound tagCompound)
    {
        tagCompound.setByte("Fuse", (byte)this.fuse);
    }

    protected void readEntityFromNBT(NBTTagCompound tagCompund)
    {
        this.fuse = tagCompund.getByte("Fuse");
    }

    public EntityLivingBase getTntPlacedBy()
    {
        return this.tntPlacedBy;
    }

    public float getEyeHeight()
    {
        return 0.0F;
    }
}

 

 

Posted

It (the fuse field) is not related with this issue...

Anyway you should register custom entity renderer, as elix said.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

Anyway it seems that he didn't set up custom entity renderer.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

Okay so a custom Entity Renderer like this? :

 

 

public class RenderEntityNuclearTntPrimed extends RenderEntity {

private static final ResourceLocation textureLocation = new ResourceLocation(UberTntMod.MODID + ":" + "textures/models/entityTest.png");

public RenderEntityNuclearTntPrimed(RenderManager manager) {
	super(manager);
}

@Override
protected ResourceLocation getEntityTexture(Entity par1Entity)
{
	return textureLocation;
}

}

 

 

 

And if so how do I get it to deal with the fact that my entity texture has custom top, bottom, side or should I join them into one file just for this entity I looked through the mc textures and saw no place where they did that though for normal tnt.

 

Posted

Try using Techne. It would answer your questions and solve most of your problems.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

  • 2 years later...
Posted
On 3/2/2015 at 8:10 AM, Elix_x said:

Take look at RenderTNTPrimed.class. It is renderer class that renderers EntityTNTPrimed. It will answer most of your questions

How do you add the renderer to the entity?

  • 3 months later...
  • Guest locked this topic
Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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