damaging an item in a curios slot when player attacks.
userofbricks opened this issue ยท 3 comments
so I have been trying over and over to damage my gauntlet items when the player attacks an entity but I have had no luck. I tried to do it with forge events but I had no luck. Is there a specific way for damaging items in curio slots?
It's nothing out of the ordinary, outside of using a particular API method in the lambda parameter as shown here:
There could be a multitude of reasons why you're having issues, so you'll have to show your code first before I can really help.
right. here is my code. I followed the same setup as the reference Items. My event is of course in the events folder, item in items, capability class in common, etc. I think my main issue for the event is how I am getting the item stack. I tried another way in the item class but I don't think it is correct. Both are commented out as to not interfere with each other. The event crashed the game so here is the crash report I got from it:
crash-2020-03-31_17.38.03-client.txt
A few things:
- You don't need to register your own capability instance like you're doing here. Curios already registers the capability you need. Instead, you just need to pass the provider to your item by overriding the
initCapabilities
method, like here. - You have a lot of places where you do a null-check against an
Optional
, like here, which isn't really the way you should do it because you risk making incorrect assumptions about the value you're getting (which could be empty and non-null). You should useOptional#ifPresent
and pass in a lambda function to perform whatever code you need when a value exists. - It seems like the crash is occurring because whatever you're passing in here in
items[i]
is returning null, when it needs to be a non-null value. I'd check your registry values again and make sure they're actually being initialized.