Posted June 6, 201411 yr I'm working on a mod and have been stuck the past few days searching for a simple way to make one of my items soulbound such that if a player dies it stays in their inventory instead of being dropped. Does anyone have a good tutorial they could point me to, or a good set of ideas I can use to get this done?
June 6, 201411 yr Author Okay, I tried using LivingDeathEvent to check if the player had the item upon death and remove it from their inventory and using then PlayerRespawnEvent to give the item back to the player. This does seem to work, but I accidentally noticed if the player dies and doesn't respawn but exits instead, then when they return to the world and respawn, they don't get the item given to them.
June 6, 201411 yr Look at PlayerEvent for more events about player actions. PlayerEvent.PlayerLoggedInEvent PlayerEvent.PlayerLoggedOutEvent You can use these 2 events for your issues.
June 6, 201411 yr Author coolboy4531, I feel like I'm supposed to use the loggedIn/Out events to save the data about the soulbound item to the server while the player is away, but I'm at a loss when trying to figure out how to do it. Or did you mean for me to use those methods to do something else? diesieben07, I can't seem to do anything successful with that event. The annotation I found on it says I can cancel it to stop all drops from entering the world, but I only want to prevent the soulbound items from dropping. Upon further review, using "System.out.println()" I can see, this event isn't even being called when a player dies.
June 6, 201411 yr Author /facepalm/ I forgot to preface my method with "@SubscribeEvent". No wonder I couldn't get it to do anything. Okay, yes, removing the item from the list prevents it from dropping, but it doesn't keep it in the player's inventory. The item is just deleted. I tried adding the item back into the inventory after removing it from the drops list, and now I can see it in the inventory hotbar when the player is dead and the respawn menu is up while all the other items have been dropped to the ground, but once I respawn, the item is gone again. And it still didn't drop.
June 6, 201411 yr Author I see. Back to square one. In that sense, it's really no different than using the LivingDeathEvent to check if the item is present and removing it form their inventory at that point. Using either LivingDeathEvent or PlayerDropsEvent, I still have to use PlayerRespawnEvent to give the item back. So now we return to the issue where coolboy4531 suggested I use the player LoggedIn/Out events to (I assume) save the soulbound item data in case the player logs off instead of respawning.
June 7, 201411 yr Author You're right, it wasn't hard. I just didn't have that little bit of needed information in my memory bank. It works perfectly now. Thank you so much for your help!
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.