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

In my mod I need to set up a GuiScreen that just simply shows the player some of their stats. However, even though the client is synced with the server through packets, I can't get the data in the GUI.

 

The problem is that the

mc.player.getCapability(CapabilityMana.MANA_CAPABILITY, null).get...()

methods return 0.

 

What could be causing this?

Edited by FlashHUN
Marked as Solved

  • Author
Just now, diesieben07 said:

What causes this is that you are not syncing the data to the client.

Show your syncing code.

Sorry, been coding for 6 hours now, my brain has started to melt. Realized that I'm dumb, and the only data that I didn't sync was what I tried to get from the GUI. Sorry for wasting your time.

  • Author
7 minutes ago, FlashHUN said:
13 minutes ago, diesieben07 said:

What causes this is that you are not syncing the data to the client.

Show your syncing code.

Sorry, been coding for 6 hours now, my brain has started to melt. Realized that I'm dumb, and the only data that I didn't sync was what I tried to get from the GUI. Sorry for wasting your time.

Actually, nevermind. Like I said, I'm tired. It's synced.

 

PacketLand:

public class PacketLand implements IMessage {
    private int mana;

    public PacketLand() {}
    
    public PacketLand(EntityPlayer player) {
        mana = player.getCapability(CapabilityMana.MANA_CAPABILITY, null).getLand();
    }
    
    @Override
    public void fromBytes(ByteBuf buf) {
    	mana = buf.readInt();
    }

    @Override
    public void toBytes(ByteBuf buf) {
        buf.writeInt(mana);
    }

    public static class Handler implements IMessageHandler<PacketLand, IMessage> {
        @Override
        public IMessage onMessage(PacketLand message, MessageContext ctx) {
            FMLCommonHandler.instance().getWorldThread(ctx.netHandler).addScheduledTask(() -> handle(message, ctx));
            return null;
        }

        private void handle(PacketLand message, MessageContext ctx) {
        	Main.proxy.handleMana(message.mana, 27);
        }
    }
}

 

Events for syncing:

@SubscribeEvent
    public static void playerClone(final PlayerEvent.Clone event) {
        final IMana oldMana = getMana(event.getOriginal());
        final IMana newMana = getMana(event.getEntityPlayer());

        if (newMana != null && oldMana != null) {
            newMana.setLand(oldMana.getLand());
            System.out.println("Player Clone Event Successful");
        }
    }

@SubscribeEvent
    public static void loginEvent(final PlayerLoggedInEvent event) {
    	EntityPlayer player = event.player;
    	PacketHandler.INSTANCE.sendTo(new PacketLand(player), (EntityPlayerMP)player);
    	System.out.println("Synced");
    }
    
    @SubscribeEvent
    public static void changeDimesionEvent(final PlayerChangedDimensionEvent event) {
    	EntityPlayer player = event.player;
    	PacketHandler.INSTANCE.sendTo(new PacketLand(player), (EntityPlayerMP)player);
    	System.out.println("Synced");
    }
    
    @SubscribeEvent
    public static void respawnEvent(final PlayerRespawnEvent event) {
    	EntityPlayer player = event.player;
    	PacketHandler.INSTANCE.sendTo(new PacketLand(player), (EntityPlayerMP)player);
    	System.out.println("Synced");
    }

 

ClientProxy:

public void handleMana(int mana, int packetType) {
		EntityPlayer player = Minecraft.getMinecraft().player;
		switch (packetType) {
			case 24: player.getCapability(CapabilityMana.MANA_CAPABILITY, null).setLand(mana); break;
		}
	}

 

Edited by FlashHUN

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.