Posted September 29, 20204 yr I am trying to make it so that when you eat an item, after 5 seconds you die, I use the TickEvent for it, when i do event.player.setHealth(0), the death screen comes up, but the player doesn't die, meaning the respawn button doesn't work and the player can die whilst in the death menu, here's the code that I am using (I added a food item called hog_meat, hogCurse is a global boolean that turns on when you eat the hog_meat, and hog_timer is a global timer that starts when you eat hog_meat): @SubscribeEvent public static void onTick(TickEvent.PlayerTickEvent event){ if (event.player.getEntityWorld().isRemote) { if (hogCurse) { if (hogCurseTimer < 5 * 40) { hogCurseTimer++; if (hogCurseTimer % 40 == 0) { String msg = TextFormatting.RED + "You have " + (6 - hogCurseTimer / 40) + " Seconds left until you DIE!"; event.player.sendMessage(new StringTextComponent(msg), event.player.getUniqueID()); } } else { if (event.player.isAlive()) { String msg = TextFormatting.RED + "You didn't eat bread, now DIE!"; event.player.sendMessage(new StringTextComponent(msg), event.player.getUniqueID()); event.player.setHealth(0); hogCurse = false; hogCurseTimer = 0; } } } } } What can I do to make it work?
September 29, 20204 yr 28 minutes ago, PlainPlaying said: What can I do to make it work? The kill command uses this to kill an entity: event.player.attackEntityFrom(DamageSource.OUT_OF_WORLD, Float.MAX_VALUE) However, there might be other problems with the code. You should not use global variables like this, for example what would happen if several players eat the item at the same time? You should use capabilities for these kinds of things Edited September 29, 20204 yr by vemerion Add note about capabilities
September 29, 20204 yr Author i define all the variables at the start of the class, but wouldn't it say <PLAYER> fell out of the world?
September 29, 20204 yr 2 minutes ago, PlainPlaying said: i define all the variables at the start of the class, but wouldn't it say <PLAYER> fell out of the world? You can create a custom DamageSource if you want a more appropriate death message. However, note that you should not use global variables like this, since they will be shared across all players. You should instead use capabilities.
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.