Posted March 8, 20232 yr I tried to create an event class which shall check if a player is holding a torch and make zombies and skeleton scared of the player an run away, but IntelliJ is telling me that Class 'ModEvents' is never used and Method 'onPlayerTick(net.minecraftforge.event.TickEvent.PlayerTickEvent)' is never used and both the class name and the method name appear grayed out instead of yellow. I don't understand where I went wrong. Please help and do tell me if I need to provide any other pieces of my mod. @Mod.EventBusSubscriber(modid = ImmersiveSurvival.MOD_ID) public class ModEvents { @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent event) { if (event.side == LogicalSide.CLIENT && event.phase == TickEvent.Phase.END) { PlayerEntity player = event.player; if (player.getHeldItemMainhand().getItem() == Items.TORCH) { World world = player.world; AxisAlignedBB box = player.getBoundingBox().grow(8.0); List<MobEntity> mobs = world.getEntitiesWithinAABB(MobEntity.class, box); for (MobEntity mob : mobs) { if (!mob.isPotionActive(FEAR_EFFECT) && (mob instanceof ZombieEntity || mob instanceof SkeletonEntity)) { mob.addPotionEffect(new EffectInstance(FEAR_EFFECT, 20)); mob.setRevengeTarget(player); } } } World world = player.world; AxisAlignedBB box = player.getBoundingBox().grow(128.0); for (Entity entity : world.getLoadedEntitiesWithinAABB(MobEntity.class, box)) { if (entity instanceof LivingEntity) { LivingEntity livingEntity = (LivingEntity) entity; if ((livingEntity instanceof ZombieEntity || livingEntity instanceof SkeletonEntity) && livingEntity.isPotionActive(FEAR_EFFECT)) { if (livingEntity.getActivePotionEffect(FEAR_EFFECT).getDuration() == 0) { livingEntity.setRevengeTarget(null); } } } } } } } Also, I created a Fear_Effect which doesnt really do anything except set a countdown so that I can set the target back to null. Please suggest a better way if you know one.
March 8, 20232 yr I think you may still need to register the method itself in the bus or specify it in the decorator. Edited March 8, 20232 yr by chxr
March 8, 20232 yr Author Edited - Actually I think I've already done that in the line before the class declaration. @Mod.EventBusSubscriber(modid = ImmersiveSurvival.MOD_ID) And also in the Mod class. MinecraftForge.EVENT_BUS.register(ModEvents.class); But it's still not working, please please help. Edited March 8, 20232 yr by PadFoot2008
March 8, 20232 yr Only register the event handler one way, not both. IntelliJ thinks the functions aren't called because the code that calls them is not normal code. You can safely ignore the warnings, as long as the methods are being called in-game (which you could check by setting a breakpoint and running debug).
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.