Actions after death

Hello my friends, i want add some new actions after player death but i have some troubles with it because dont have enoughe knowledge about minecraft inside. Can you tell me have it class or objects responsible for show window with buttons after player death ( i want disable it) and actions like move , inventory or chat ( i want disable they too) ?

Just making sure. You want to disable the death screen, moving, chat and inventory?

Yep. For dead player.

Ok, so your going to need to have a event listener for checking that the player will die, attempting to move, attempting to send a message and opening inventory. Im not going to spoon feed you completely, so ill show you the death one and you can do the rest.

So in your listeners class, create a method like this

@EventListener
public void onPlayerDeath(DamageEntityEvent event){
}

after that you want to check that the entity is a player and the damage inflicted will cause the death

@EventListener
public void onPlayerDeath(DamageEntityEvent event){
  if(!(event.getTargetEntity() instanceof Player)){
    return;
  }
  if(!event.willCauseDeath()){
    return;
  }
}

After that you need to respawn the player, by respawning the player at this point will bypass the death screen.

Player player = (Player)event.getTargetEntity();
player.respawn();

When it comes to the inventory, I believe minecraft handles the opening of the players inventory on the client side now completely, meaning that you wont be able to interfere with that, however you can stop the client from picking up items as well as dropping items, so you could cancel those events if you want giving the effect of a fixed inventory.

edit:
also remember to register the event listener

1 Like

And again thank you, very useful information !