Jump to content

[SOLVED] [1.12.2] Getting Capability in GuiScreen returns 0


FlashHUN

Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.