Posted July 5, 20178 yr What I'm trying to accomplish is when the button is pressed it will consume an item in the players inventory. This is what I have currently @Override protected void actionPerformed (GuiButton button) throws IOException { if (button == insertCoin) { if (menu == -1){ EntityPlayer player = Minecraft.getMinecraft().player; if (player.inventory.hasItemStack(new ItemStack(ArcadeItems.coin))) { ItemStack coin = player.inventory.getStackInSlot(player.inventory.getSlotFor(new ItemStack(ArcadeItems.coin))); if (coin.getCount() > cost) { int slot = player.inventory.getSlotFor(new ItemStack(ArcadeItems.coin)); ItemStack newStack = player.inventory.decrStackSize(slot, coin.getCount() - cost); player.inventory.setInventorySlotContents(slot, newStack); menu = 0; } else if (coin.getCount() == cost) { player.inventory.setInventorySlotContents(player.inventory.getSlotFor(new ItemStack(ArcadeItems.coin)), ItemStack.EMPTY); menu = 0; } else enoughCoins = false; } else enoughCoins = false; } } } It does remove a coin, but it only updates client side so relogging into the world I would have the original numbered stack. How do I properly update the player's inventory? MobDrops http://www.planetminecraft.com/mod/125-mobdrops/
July 5, 20178 yr You need to send a custom packet to the server and let the server do everything you need to. You also should never trust a client in general so most of your checks and actions should be server-side.
July 5, 20178 yr Author 49 minutes ago, V0idWa1k3r said: You need to send a custom packet to the server and let the server do everything you need to. You also should never trust a client in general so most of your checks and actions should be server-side. Thank you. That helped. But what would be the best way to do the checks server-side? MobDrops http://www.planetminecraft.com/mod/125-mobdrops/
July 5, 20178 yr Just now, SuperHB said: what would be the best way to do the checks server-side? In your GUI only send the packet with most basic info that allows you to identify what the player is trying to do. On the server get all the values, perform the checks and send the response if needed. The approach is to do all logic on the server and simply notify the client when appropriate.
July 6, 20178 yr Author 2 hours ago, V0idWa1k3r said: In your GUI only send the packet with most basic info that allows you to identify what the player is trying to do. On the server get all the values, perform the checks and send the response if needed. The approach is to do all logic on the server and simply notify the client when appropriate. I was able to move all the checks to server-side. But how do I send data back to the client? I've been looking around and haven't been able to find how to receive the return from the onMessage MobDrops http://www.planetminecraft.com/mod/125-mobdrops/
July 6, 20178 yr 1 hour ago, SuperHB said: I was able to move all the checks to server-side. But how do I send data back to the client? I've been looking around and haven't been able to find how to receive the return from the onMessage Just send another packet. The return value of IMessageHandler#onMessage is largely useless now that packets are handled on a network thread and all the logic needs to be run on the main thread. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
July 6, 20178 yr Author 57 minutes ago, Choonster said: Just send another packet. The return value of IMessageHandler#onMessage is largely useless now that packets are handled on a network thread and all the logic needs to be run on the main thread. How do I get the packet data from my Gui class? MobDrops http://www.planetminecraft.com/mod/125-mobdrops/
July 6, 20178 yr 11 minutes ago, SuperHB said: How do I get the packet data from my Gui class? When the server-to-client packet is received by the client, you can access the current GUI from the Minecraft#currentScreen field. If it's an instance of your GUI class, you can update it with the data from the packet. Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
July 6, 20178 yr Author 11 hours ago, Choonster said: When the server-to-client packet is received by the client, you can access the current GUI from the Minecraft#currentScreen field. If it's an instance of your GUI class, you can update it with the data from the packet. Thank you! I got everything working now. MobDrops http://www.planetminecraft.com/mod/125-mobdrops/
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.