Posted October 9, 20214 yr 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
October 9, 20214 yr 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
October 9, 20214 yr 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, 20214 yr by than00ber1
October 9, 20214 yr 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, 20214 yr by Luis_ST
October 9, 20214 yr 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
October 9, 20214 yr 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.
October 9, 20214 yr 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/
October 9, 20214 yr Author 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
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.