Posted February 1, 201510 yr Hey so I'm having a little trouble with GUI buttons. I new to GUI and I can't seem to get this to work. I have the button set so that if the player has a poison effect and the button is pressed then it will remove the poison effect. I pressed the button and my players hearts turn from that green color back to a red but the poison effect doesn't actually get removed. This also happens if I try to apply invisibility, it shows the effect in the players inventory but the player isn't actually invisible. Any help would be greatly appreciated. Here is the code in my GUI class that involves removing the potion effect: public void initGui() { this.buttonList.clear(); int posX = ((this.width - xSOT) / 2); int posY = ((this.height - ySOT) / 2); this.buttonList.add(new GuiButton(0, posX + 40, posY + 40, 100, 20, "Remove Posion" )); } public void actionPerformed(GuiButton button) { switch(button.id) { case 0: this.mc.thePlayer.removePotionEffect(Potion.poison.id); } } [/Code]
February 1, 201510 yr GUIs are client side only - potion effects are handled on the server, so you need to send a packet informing the server that the player clicked that specific button, then let the server decide what to do (e.g. remove poison). http://i.imgur.com/NdrFdld.png[/img]
February 1, 201510 yr Author Okay, my knowledge on packets is very limited so ill look into them. Thanks for the help and very fast reply.
February 1, 201510 yr I dont know if this would be different for buttons but I have an item that when right clicked removes all potion effects. Here is the code. for(int i = 0; i <20; i++) { player.removePotionEffect(i); } This takes away the actual effect and the display on the side of the inventory GUI. You can get rid of the for statement and just put in the number of the potion effect you want to remove. (Don't know what poison is off the top of my head)
February 1, 201510 yr Author Yeah that won't for buttons like coolAlias said. I could just use your method but I'm gonna stick with packet's and GUI's so I can extend my knowledge of the two. Thanks for adding though.
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.