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

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 by vemerion
Add note about capabilities

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.

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.