Jump to content

[1.11.2][Solved] Item NBT data does not update on gui button click


Recommended Posts

Posted (edited)

Hello i am trying to change items nbt data when a button is clicked in it's gui but when i click the button then the nbt data of item does not change (tested with /entitydata)

Code: 

@Override
	protected void actionPerformed(GuiButton button) throws IOException {
		switch(button.id) {
		
		case(0): //Assign camera with monitor button
			try {
				ItemStack stack = Minecraft.getMinecraft().player.getHeldItemMainhand();
				NBTTagCompound stacknbt = stack.getTagCompound();
				NBTTagList cams = (NBTTagList) stacknbt.getTag("Cameras");
				
				NBTTagCompound nbt = new NBTTagCompound();
				nbt.setUniqueId("UUID", UUID.randomUUID()); //Placeholder
				
				cams.appendTag(nbt);
				stacknbt.setTag("Cameras", cams);
				stack.setTagCompound(stacknbt);
				System.out.println("lol");
			} catch (Exception e) {
				e.printStackTrace();
			}
			
		}
		super.actionPerformed(button);
	}

log: 

  Reveal hidden contents

 

Edited by lukas2005
Posted

GUIs only exist on the client, but the server is in control of the game state. You need to send a custom packet to the server when the player clicks the button and make the changes to the player's held item in the packet's handler.

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.

Posted
  On 8/5/2017 at 2:55 PM, lukas2005 said:

i thought that item nbt sync automatically

Expand  

In one direction.

As Choonster said, the server controls the state of the game and item NBT is considered "state information." So yes, NBT is updated automatically and the server's copy overwrites the client's.

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.

Posted

You don't. You use a container, the container specifies the slots and the gui screen (the super class) uses the supplied container to draw them.

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.

Posted
  On 8/5/2017 at 4:26 PM, Draco18s said:

You don't. You use a container, the container specifies the slots and the gui screen (the super class) uses the supplied container to draw them.

Expand  

how do i implement a container ? i want to make a single slot wich is gonna be used just to link a camera item with monitor item

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.

Announcements



×
×
  • Create New...

Important Information

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