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

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.

I think you may still need to register the method itself in the bus or specify it in the decorator. 

Edited by chxr

  • 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 by PadFoot2008

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.

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.