hendrick020301 Posted October 9, 2021 Posted October 9, 2021 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 Quote
ImNotJahan Posted October 9, 2021 Posted October 9, 2021 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 Quote
than00ber1 Posted October 9, 2021 Posted October 9, 2021 (edited) 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 October 9, 2021 by than00ber1 Quote
Luis_ST Posted October 9, 2021 Posted October 9, 2021 (edited) 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 October 9, 2021 by Luis_ST Quote
hendrick020301 Posted October 9, 2021 Author Posted October 9, 2021 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 Quote
hendrick020301 Posted October 9, 2021 Author Posted October 9, 2021 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. Quote
Luis_ST Posted October 9, 2021 Posted October 9, 2021 basic java is required for modding minecraft take a look at the follwing links: Official documentation: https://docs.oracle.com/javase/tutorial/ Absolute basics with an interactive editor: https://www.codecademy.com/learn/learn-java Ongoing online course with assignments: https://java-programming.mooc.fi/ Quote
hendrick020301 Posted October 9, 2021 Author Posted October 9, 2021 19 minutes ago, Luis_ST said: basic java is required for modding minecraft take a look at the follwing links: Official documentation: https://docs.oracle.com/javase/tutorial/ Absolute basics with an interactive editor: https://www.codecademy.com/learn/learn-java Ongoing online course with assignments: https://java-programming.mooc.fi/ ty Quote
Recommended Posts
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.