Jump to content

Recommended Posts

Posted

I have a hammer in my mod which when you left click on stone it makes it cracked stone. The item damages fine but when it reaches 0 durability, the item damage returns to 0 and the stack size is reduced to zero, however the item doesn't go away. Also, the breaking animation and sound is not shown or played.

 

Source code: https://github.com/penguinsfan77/RandomStuff/

 

The item is damaged and the stone is cracked in the ItemEventHandler class in the events package. The Hammer class is in the items package.

 

Any help is greatly appreciated, thanks.

Posted

I recently looked at the TileEntityFurnace class of Vanilla Minecraft, and they used something like

if(hammerItemStack.stackSize >= 0){
hammerItemStack = null;
}

I'm not sure and haven't tested it, but it might solve the issue with the ItemStack with size 0.

Thanks for helping me <3

Posted

I recently looked at the TileEntityFurnace class of Vanilla Minecraft, and they used something like

if(hammerItemStack.stackSize >= 0){
hammerItemStack = null;
}

I'm not sure and haven't tested it, but it might solve the issue with the ItemStack with size 0.

 

Thanks for your help. That should fix the issue of the item not going away but I don't think it it will fix the issue of of the item not playing the break sound or particle effect.

Posted

So the hammer class now extends item tool and i discovered that the reason that the item wasn't breaking was because I wasn't actually breaking a block. So i moved my code out of the ItemEventHandler class and into the onBlockDestroyed method. This allows the item to break properly however the stone is not cracking anymore and it seems that the setBlock() method doesn't work.

Here is what I have:

@Override
public boolean onBlockDestroyed(ItemStack item, World world, Block block, int x, int y, int z, EntityLivingBase player) {

item.damageItem(1, player);

if (block.equals(Blocks.stone)) {
	world.setBlock(x, y, z, ModBlocks.crackedStone);
}

return true;

}

 

Could someone try to explain why the block that was broken is not replaced by cracked stone?

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.