Posted March 8, 20196 yr 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 March 8, 20196 yr by FlashHUN Marked as Solved
March 8, 20196 yr 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.
March 8, 20196 yr 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 March 8, 20196 yr 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.