Jump to content

Recommended Posts

Posted

I am trying to implement a right-click interaction between a vanilla tool and a vanilla block (so I can't use onBlockActivated or onItemUse). Everything is working fine except my call to ItemStack#attemptDamageItem, because the PlayerEntity I get from PlayerInteractEvent.RightClickBlock#getPlayer() is an instance of ClientPlayerEntity, not a ServerPlayerEntity. However, ItemStack#attemptDamageItem expects a ServerPlayerEntity only. I tried passing in null as the damager parameter, and this almost works, but the item doesn't break when reaching 0 durability. This may be, because the ITEM_DURABILITY_CHANGED trigger never fires when damager is null. Now my question: How can I get access to a ServerPlayerEntity instance, or alternatively, how can I make sure the item breaks when reaching 0 durability?

My code looks as follows:

  Reveal hidden contents

 

Posted

I'm sorry if this is a stupid question, but how would I do that? Because right now, the PlayerEntity is never an instance of ServerPlayerEntity (my check never returns true)

Posted
  On 7/17/2022 at 1:46 PM, jonaskohl said:

I'm sorry if this is a stupid question, but how would I do that? Because right now, the PlayerEntity is never an instance of ServerPlayerEntity (my check never returns true)

Expand  

which version of minecraft did you use, since PlayerEntity is not a mojang mapping

Posted

I realized that I'm still on 1.16.4 with MCP mappings, so I probably can't expect any support...

(I tried upgrading the mod to 1.18.2, but that went, uhm, let's say horrible, as so much has changed between 1.16.4 and 1.18.2 and I couldn't find a migration guide, so the mod would require a major rewrite, but that's an entierly different topic...)

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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