Posted May 26, 20205 yr so basically i made an event that checks if the player is crouching. If you are crouching, you get 2 potion effects. This worked, but when i released shift the potion effects still appeared on my gui, though the effects weren't doing anything. How do i fix this? package com.watizdat.mysterymod.events; import com.watizdat.mysterymod.MysteryMod; import net.minecraft.entity.LivingEntity; import net.minecraft.potion.EffectInstance; import net.minecraft.potion.Effects; import net.minecraftforge.client.event.InputUpdateEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; @Mod.EventBusSubscriber(modid = MysteryMod.MOD_ID, bus = Bus.FORGE) public class PlayerSneakEvent { @SubscribeEvent public static void playerSneakEvent(InputUpdateEvent event){ if(event.getMovementInput().sneaking) { System.out.println("hello"); LivingEntity livingEntity = event.getEntityLiving(); livingEntity.addPotionEffect(new EffectInstance(Effects.STRENGTH, 20, 2)); livingEntity.addPotionEffect(new EffectInstance(Effects.SLOWNESS, 20, 2)); } } }
May 26, 20205 yr They have to be applied on the server. Use !world.isRemote to check it. Also check documentation about sides https://mcforge.readthedocs.io/en/latest/concepts/sides/
May 26, 20205 yr You need to learn about the concept of sides. Input events are client side; you cannot do anything that would affect the server (interact with world, blocks, entities, etc). Instead, subscribe to PlayerTickEvent, and check if the event is fired on the server side and check PlayerEntity#isSneaking for sneaking. Edited May 26, 20205 yr by DavidM Some tips: Spoiler Modder Support: Spoiler 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Spoiler 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.
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.