ccsimon Posted September 17, 2015 Share Posted September 17, 2015 I'm trying to set the state of a GuiButton (and save it to NBT later), but when it triggers the '<TileEntity>.buttonClicked()'-function, the variable on the TileEntity itself is not saved (I assume it saves it in the 'copied'(?) TileEntity, not the actual one).. Here's my code so far: In GuiAlertBlock.java: public void actionPerformed(GuiButton button){ ((TileEntityAlertBlock)world.getTileEntity(this.x, this.y, this.z)).buttonClicked(); List<Entity> players = world.playerEntities; for(Entity e: players){ EntityPlayer player = (EntityPlayer)e; player.addChatMessage(new ChatComponentText(player.getDisplayName())); } } In TileEntityAlertBlock: public void buttonClicked(){ if(this.buttonState == this.BUTTON_OFF) this.buttonState = this.BUTTON_ON; else if(this.buttonState == this.BUTTON_ON) this.buttonState = this.BUTTON_OFF; System.out.println(); } Quote Link to comment Share on other sites More sharing options...
ItsAMysteriousYT Posted September 17, 2015 Share Posted September 17, 2015 Guis are ClientOnly. To set values in a tileentty(Both sides)from a Gui, youll need to use packethandling to send the value to the server. Diesieben07 has a nice Tutorial on that. Also for spoilers do [ spoiler ] [/ spoiler ] without the spaces Quote Link to comment Share on other sites More sharing options...
ccsimon Posted September 17, 2015 Author Share Posted September 17, 2015 Guis are ClientOnly. To set values in a tileentty(Both sides)from a Gui, youll need to use packethandling to send the value to the server. Diesieben07 has a nice Tutorial on that. Also for spoilers do [ spoiler ] [/ spoiler ] without the spaces Actually, I did do something with this block and packethandling before, but at that time, it wasn't necessary. (I tried it many different ways, the only thing which I didn't do was to go back using packethandlers.. ) Edit: so yeah, it does work now; thanks Quote Link to comment Share on other sites More sharing options...
ccsimon Posted September 17, 2015 Author Share Posted September 17, 2015 Well, the variable updating part works, but now it looks like it doesn't send that to the client because I either draw a red button when the value is 0, or a green one when it's 1, but in the gui the button is not updated at all. That's the line of code for drawing the button: this.drawTexturedModalRect(this.xPosition, this.yPosition, 176 + ((TileEntityAlertBlock)world.getTileEntity(this.TEx, this.TEy, this.TEz)).buttonState * 20, k * 20, this.width, this.height); Quote Link to comment Share on other sites More sharing options...
Draco18s Posted September 17, 2015 Share Posted September 17, 2015 they need to sync the data back from the server to the client again. Look for the methods getdescription packet and on description packet. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given. Link to comment Share on other sites More sharing options...
ccsimon Posted September 18, 2015 Author Share Posted September 18, 2015 I think these are the methods I searched for, I'll try them in the afternoon. Thank you Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.