Jump to content

How do make a TnT block primed on placed?


madao161

Recommended Posts

Hi all, first timer here. Just have a quick question for you all. I'm looking to make a bomberman sorta like mod for minecraft, but I'm running into an issue with trying to make a tnt block become a primed tnt block on placed. Can someone please point me in the right direction to make this happen?

 

Thanks;

Link to comment
Share on other sites

"Primed" TNT isn't a block, it's an entity.  Specifically EntityTNTPrimed (IIRC).  In your block's onPlaced (or onAddedToWorld--both are called when the player places it, the former is not if the block is created via some other means) method, make it replace itself with air and spawn a new EnityTNTPrimed.

 

Also, take a look at the TNT block, see what it does when it gets set off, the code you need is there, just inside a different method.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I have tried doing what you said. In the original TnT block, I find this:

     */
    public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
    {
        if (par5EntityPlayer.getCurrentEquippedItem() != null && par5EntityPlayer.getCurrentEquippedItem().itemID == Item.flintAndSteel.itemID)
        {
            this.func_94391_a(par1World, par2, par3, par4, 1, par5EntityPlayer);
            par1World.setBlockToAir(par2, par3, par4);
            return true;
        }
        else
        {
            return super.onBlockActivated(par1World, par2, par3, par4, par5EntityPlayer, par6, par7, par8, par9);
        }
    }

 

So then in my modded BlockModTnT.java, I've placed the following:

 

   public void onBlockPlaced(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, EntityLiving par6EntityLiving)
    {
    	
    	 //this.func_94391_a(par1World, par2, par3, par4, 1, par5EntityPlayer);
         //par1World.setBlockToAir(par2, par3, par4);
    	ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Test mode:" + "Got here5");
         EntityTNTPrimed var7 = new EntityTNTPrimed(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F), par6EntityLiving);
         ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Test mode:" + "Got here6");
         par1World.spawnEntityInWorld(var7);
         ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Test mode:" + "Got here7");
         par1World.playSoundAtEntity(var7, "random.fuse", 1.0F, 1.0F);
         ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Test mode:" + "Got here8");
    }
    
    public void onBlockAdded(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, EntityLiving par6EntityLiving)
    {
        super.onBlockAdded(par1World, par2, par3, par4);
        ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Test mode:" + "Got here1");
        //this.func_94391_a(par1World, par2, par3, par4, 1, par5EntityPlayer);
        //par1World.setBlockToAir(par2, par3, par4);
        EntityTNTPrimed var7 = new EntityTNTPrimed(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F), par6EntityLiving);
        ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Test mode:" + "Got here2");
        par1World.spawnEntityInWorld(var7);
        ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Test mode:" + "Got here3");
        par1World.playSoundAtEntity(var7, "random.fuse", 1.0F, 1.0F);
        ModLoader.getMinecraftInstance().thePlayer.addChatMessage("Test mode:" + "Got here4");
        /*if (par1World.isBlockIndirectlyGettingPowered(par2, par3, par4))
        {
            this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1);
            par1World.setBlockToAir(par2, par3, par4);
        }*/
    }

 

This is my mod_Tnt.java

 

package net.minecraft.src;

public class mod_Tnt extends BaseMod

{
       
	public static final Block newTnT = (new BlockModTnT(244)).setHardness(0.0F).setUnlocalizedName("modtnt");
       
        public void load()
       
        {
                                ModLoader.registerBlock(newTnT);
                ModLoader.addName(newTnT, "ModdedTnT");
                ModLoader.addRecipe(new ItemStack(newTnT, 64), new Object [] {"###", Character.valueOf('#'), Block.dirt});
       
        }

                @Override
                public String getVersion() {
                        // TODO Auto-generated method stub
                        return null;
                }

                        }              
                

 

You can tell I've put a bunch of trace statements inside the BlockModTnT, and it doesn't look like any of them show up when I call them so it's almost like the code never even reaches there.

 

Please help.

Link to comment
Share on other sites

Sorry, I was just trying to get some trace messages through to see if I can see what's happening. What's the way to get an output message in the chat box so I can see what's happening?

 

Also, can someone give me some more specific help? I've wrestled with this for days now and can't figure out how to get this going...

 

Thanks

Link to comment
Share on other sites

The method gives you a player argument. You can use it.

 

Step-by-step for overriding a method properly:

-Go to your parent class (Block in this case ?)

-Copy the method declaration from it ( public void onBlockPlaced(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, EntityLivingBase par6EntityLiving) ? )

-Paste it in your class

Optional:

-Put @Override on top, so you can tell what you did in the future

-Change the variable name to your liking (public void onBlockPlaced(World world, int x, int y, int z, EntityPlayer player, EntityLivingBase living) ? )

 

All this is basic Java, and this forum isn't for basic Java lessons. ;)

Link to comment
Share on other sites

Please, stop using

ModLoader

 

Fixed that for you.

 

Madao, why are you using ModLoader.addName instead of LanguageRegistry.addName?  ModLoader.addRecipe instead of GameRegistry.addShapedRecipe ?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Okay, let's start anew here because I am genuinely all confused now.

 

I upgraded to 1.6.4 so now that my code works better with everything else.

 

Just to restate what I am trying to do here, instead of having to use flint+steel or any other item to activate the TnT. I want the TnT to activate the moment I place it down.

 

I've looked what sets a TnT block and changes the entity into a primed TnT. From what I can see, it should be this (inside BlockTNT.java)

    
public void primeTnt(World par1World, int par2, int par3, int par4, int par5, EntityLivingBase par6EntityLivingBase)
    {
        if (!par1World.isRemote)
        {
            if ((par5 & 1) == 1)
            {
                EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F), par6EntityLivingBase);
                par1World.spawnEntityInWorld(entitytntprimed);
                par1World.playSoundAtEntity(entitytntprimed, "random.fuse", 1.0F, 1.0F);
            }
        }
    }

 

 

It changes the TnT block into entity of PrimedTnT into the world. So in logical sense I should just call this function inside the function onBlockPlaced, or is it onBlockAdded (not sure the diff).

Here's the problem, the function decoration for the two in the block.java is as following:

 

    
public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9)
    {
        return par9;
    }

public void onBlockAdded(World par1World, int par2, int par3, int par4) {}

 

Meanwhile as we see that the arguments that PrimedTnT takes in is

 

public void primeTnt(World par1World, int par2, int par3, int par4, int par5, EntityLivingBase par6EntityLivingBase)

 

If I assume that we use onBlockPlaced, we are missing EntityLivingBase  par6EntitityLivingBase that I have no idea how I can get to pass in (and that's also assuming par1-5 in onBlockPlaced is the same things needed as par1-5 in primeTnt) and I have no idea what par9 is that is needed to be returned. If we assume it's onBlockAdded, we are missing par5 and par6EntityLivingBase.

 

I hope this provides more clear view of what my issue is so more clear help can be provided.

 

Thanks

Link to comment
Share on other sites

Prefer using

public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)

This will be called after all block placement checks.

Not hard to find, was it ? :P

 

You can also put null for EntityLivingBase as argument for the TNT. It is only used for the EntityTNTPrimed constructor and does not affect its logic.

 

onBlockAdded is called on world generation too, so you may not want to use that.

Link to comment
Share on other sites

onBlockPlacedBy will pass a player necessary to make it go boom.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I've done the following and now it works!

    public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
    {
    	this.primeTnt(par1World, par2, par3, par4, 1, par5EntityLivingBase);
    	 par1World.setBlockToAir(par2, par3, par4);
         
    }
    

 

Thanks a bunch guys!

Link to comment
Share on other sites

@draco18s

It is not necessary at all. See onBlockDestroyedByPlayer in BlockTNT.

 

A player object is not required for the TNT to function, but that particular function has one available.  Slight difference.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.