Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I am looking to create an item where if it is in the player's main inventory, when the player dies, they do not drop their items upon death.

 

What would I look into to create this effect? Item being consumed on use could be useful but not required.

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.

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.

  • Author

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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.