ThaxxelGaming Posted April 27, 2013 Posted April 27, 2013 Hey guys, I am stepping up into a more intermediate level of modding after a long break. Made a sword, wanting to have myself click on a block (dirt, cobblestone, etc) and make the surrounding area explode on touch or disappear. One of the two. (Without totally killing me in the process) Started off with the code below: Code: public class ItemTNTSword extends ItemSword{ public ItemTNTSword(int par1, EnumToolMaterial i) { super(par1, i); this.maxStackSize = 1; this.setCreativeTab(CreativeTabs.tabCombat); } public void updateIcons(IconRegister iconRegister){ iconIndex = iconRegister.registerIcon("Explosive:TnTSword"); } public boolean onBlockActivated(ItemStack itemstack, EntityPlayer entityplayer, World world, int blockx, int blocky, int blockz, int par7, float x, float y, float z) { if (par7 == 0) blocky--; if (par7 == 1) blocky++; if (par7 == 2) blockz--; if (par7 == 3) blockz++; if (par7 == 4) blockx--; if (par7 == 5) blockx++; world.createExplosion(entityplayer, blockx, blocky, blockz, 10.0f, true); return true; } However, this doesn't seem to work. I realize I have something wrong here, just not sure what. I am also pretty sure "onBlockActivated" is the wrong use for what I am going for. Would appreciate the help and input!! Thanks! Quote
Darknesschaos Posted April 27, 2013 Posted April 27, 2013 I believe onBlockActivated only triggers when you right click it. But you never specified what button you are clicking with. Also, I advise using a switch system instead of your bunch of if(...) code. Not that efficiency here would matter too much, but any little bit always helps. edit: Or at least use an if else system. Quote
ThaxxelGaming Posted April 28, 2013 Author Posted April 28, 2013 Fantastic! Thanks man! Found that using: public boolean onItemUse worked! OR i could use public ItemStack onItemRightClick. By changing the extends folder to Item.java rather than ItemSword.java. You helped out a lot, never would have thought otherwise! Thanks! Quote
Recommended Posts
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.