Jump to content

[SOLVED][1.7.10] Variable is not saved to TileEntity


ccsimon

Recommended Posts

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();
}

Link to comment
Share on other sites

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 :D

 

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 :)

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

they need to sync the data back from the server to the client again. Look for the methods getdescription packet and on description packet.

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

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.

×
×
  • Create New...

Important Information

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