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

Hiya,

 

I made a small mod that listens for when the player gets damaged.

It works perfectly in SP but when I join a server it doesn't work anymore.

 

How do I allow it to run in multiplayer?

  • Author

Sure, this is my `init` method:

 

@EventHandler
public void init(FMLInitializationEvent event)
{
    // some example code
    logger.info("ShockMod loaded.");

    MinecraftForge.EVENT_BUS.register(new LivingDamageEventHandler(logger));
}

 

The EventHandler is just

 

    @SubscribeEvent
    public void livingDamage(LivingDamageEvent event) {
        this.logger.info("Event entity id: " + event.getEntity().getEntityId() + " | My id: " + Minecraft.getMinecraft().player.getEntityId());
        if (event.getEntity().getEntityId() != Minecraft.getMinecraft().player.getEntityId()) {
            return;
        }

        //Do stuff
    }

 

And these are the flags(?) I supply to the @Mod flag.

 

public static final String MODID = "shockmod";
public static final String NAME = "Shock Mod";
public static final String VERSION = "1.0";
public static final boolean CLIENTSIDEONLY = true;
public static final boolean CANBEDEACTIVATED = true;

Edited by Tvde1

  • Author
2 minutes ago, diesieben07 said:

Minecraft is a client-only class. What are you trying to achieve by checking for Minecraft::player? There is no "the player" on a server. There are many players.

This mod is running on the client. I want it to work when connected to a server.

  • Author

Do you know which event runs on the client where I can get notified whenever the logged in player gets hurt?

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.