Jump to content

[1.15.2] Have an item make player not drop items on death?


Recommended Posts

Vanilla already has a gamerule for this (keepInventory). Just turn it on.

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Three events are of interest to you - player death event (LivingDeath), PlayerDrops event and player Clone event.

 

First two trigger when player's avatar dies - player looks at the death message and the respawn button button. Items are scattered all over the death site. Then - maybe 5 seconds later - player clicks the respawn button. Then the Clone event fires - data is transfered from old (dead) player instance to a freshly created one.

 

Be sure to note the (possibly) long delay between items being scattered and the new instance of the player being created (yes, the game will create a new player object. do not fight that).

 

First event - Living death can be used to remember in which slot each item was.

 

Second event - drops - has a "drops" collection - a list of ItemStacks that the dead player is about to drop dropped. You need to put them back into his inventory (the dead player object waits for the clone event; it will be destroyed at some point after the clone event) and delete from drops list.

 

Third event - Clone - is where you go through player inventories of the old/dead player (main inventory (36 slots), armor inventory (4 slots), offhand inventory (1 slot) ), copy each item and add it to the new player's inventory. (when everything works, consider baubles support.)

 

-------------------------

 

that's at least how i did it a while ago (disclaimer: i may not have remembered everything correctly)... it may not be the best way.

 

Start with printing a line or two into console for every event. Once you get events and conditions to output proper messages, copying item stacks will be a small step.

Link to comment
Share on other sites

Oh thanks! This is very helpful and I played around with all of these and have a good idea of how the three events work. Now how do you actually store information to be used on a different event?

 

I think my needs changed a little bit. One of my users recommends that I only have specific items come back with the player rather than the whole inventory. So how could I do this:

First event: Find a specific item in inventory on death

Second event: Delete that specific item from drop collection

Third event: Place that specific item in player inventory

 

As far as I could tell from testing, in the Clone event, the getOriginal() does not have a record of the player inventory.

Link to comment
Share on other sites

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.