Event- When Item is Broken. Is it possible?

Started by NoobMaximus on Wed, 11/25/2015 - 20:11
Last seen on 21:49, 14. Jun 2017
Joined Nov 2015
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
Event- When Item is Broken. Is it possible?
Wed, 11/25/2015 - 20:11

Hello,

I'm farly new to modding, and I noticed that there is no "easy way" of adding an event that triggers whan a tool or item breacks or uses all of it's durabilty.

I have a sword and what I would like to be albe to do is, when it breacks I wont it to give you a broken sword, that you will be able to repare (craft) into a useable sword again.

Is this possable? If so please tell me how.

NoobMaximus

Last seen on 17:04, 17. Aug 2018
Joined Aug 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
  • wiki contributor
  • moderator
Try:
Wed, 11/25/2015 - 20:54

Try:

Make new empty overlay. To the overlay , above this line : 
public mcreator_SOMETHING(){}

add:


@SubscribeEvent
public void onItemBreakEvent(PlayerDestroyItemEvent event) {
{
    if (event.ItemStack == new ItemStack(YOUR SWORD NAME IN FORMAT mcreator_SOMETHING.block ))
{

event.entity.inventory.addItemStackToInventory(new ItemStack(mcreator_YOUR BROKEN SWORD.block, 1));

}}

Last seen on 21:49, 14. Jun 2017
Joined Nov 2015
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
RE:Try:
Fri, 11/27/2015 - 03:32

@#1

Thank you for replying, Nuparu00

I can't tell if i didn't work, or if i did it wron@#1 g, but i'm getting errors back saying:C:\Pylo\MCreator160\forge\build\sources\java\mod\mcreator\mcreator_rustySword.java:105: error: illegal start of expression
public mcreator_rustySword(){}

And

C:\Pylo\MCreator160\forge\build\sources\java\mod\mcreator\mcreator_rustySword.java:107: error: illegal start of expression
public static Item block;

Last seen on 17:04, 17. Aug 2018
Joined Aug 2013
User points:

Statistics:

  • Comments:
  • Forum topics:
  • Modifications:
  • Wiki pages:
  • wiki contributor
  • moderator
RE:RE:Try:
Sat, 11/28/2015 - 16:45

@#1.1 Can you please send me the codes?