Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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!!  :D

 

Thanks!

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.

  • Author

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! :)

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.