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

Hey, i havent made mods in minecraft before and im currently starting out with trying to make some small simple mods.

 

Im currently trying to make a mod that checks when youre below a certain hp value and then gives you slowness or another potion effect.

I tried searching on google how to get the value from the player health as a int/var to use in a if sentence.

 

If anyone knows how to do this please respond! :)

 

https://imgur.com/a/a6tH8Zq

Tried this but it says errer: cannot find symbol

FMLClientSetupEvent is only called once, and is only called on the client (you'll want to give potion effects on the server), so the event you should use is TickEvent.PlayerTickEvent, then event.player.getHealth() to get the health, and lastly to add a potion effect you can also call .addEffect on the player instance provided by the event

Alright. the FMLClientSetupEvent is not the corret event to listen to (at all).

You will need to listen for the PlayerTickEvent event.

public class PlayerTickHandler {

    @SubscribeEvent
    public void onPlayerTick(TickEvent.PlayerTickEvent event) {
        PlayerEntity player = event.player;
        if (player.getHealth() < 7) {
            player.addPotionEffect(new EffectInstance(Effects.SLOWNESS, 60));
        }
    }
}

And register it for Forge event bus inside your mod's construcor like this: 

MinecraftForge.EVENT_BUS.register(new PlayerTickHandler());

Note the @SubscribeEvent, this essentially tells forge that the methods is listening for an event.

Edited by than00ber1

11 minutes ago, than00ber1 said:

You will need to listen for the PlayerTickEvent event.

that's a bad idea, add the Effect for example when the Player joins the World or when he mine a Block but not each Tick

11 minutes ago, than00ber1 said:

And register it for Forge event bus inside your mod's construcor like this:

use the @EventBusSubscriber annotation you need to pass as parameter the Mod Id

what did you try to achieve?

Edited by Luis_ST

  • Author
44 minutes ago, than00ber1 said:

Alright. the FMLClientSetupEvent is not the corret event to listen to (at all).

You will need to listen for the PlayerTickEvent event.

public class PlayerTickHandler {

    @SubscribeEvent
    public void onPlayerTick(TickEvent.PlayerTickEvent event) {
        PlayerEntity player = event.player;
        if (player.getHealth() < 7) {
            player.addPotionEffect(new EffectInstance(Effects.SLOWNESS, 60));
        }
    }
}

And register it for Forge event bus inside your mod's construcor like this: 

MinecraftForge.EVENT_BUS.register(new PlayerTickHandler());

Note the @SubscribeEvent, this essentially tells forge that the methods is listening for an event.

This gave me this error

https://imgur.com/a/o2TcJjr

  • Author
8 minutes ago, Luis_ST said:

do you know basic java?

to some degree, im fairly new to java. been working with Javascript and python up until now so not really.

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.