Jump to content

[1.7.10] ItemStack only changing clientside


ccsimon

Recommended Posts

Hi,

to continue my previous question: now that I got some buttons to work, I want one to change the ItemStack in the (currently only) slot, but as soon as I pull the item out of this slot, it loses its enchantments (so it just changes back to the previous item). I don't know if this has something to do with networking or if I just missed something (clearly it's something with this client-server-thing).

 

That's inside my Gui's class:

public void actionPerformed(GuiButton button){
	switch(button.id){
		case 0:	teetp = worldObj.getTileEntity(posX, posY, posZ);

				if(teetp.getStackInSlot(0) != null){
					tempItem = teetp.getStackInSlot(0).copy();
					if(tempItem.getItem() instanceof ItemSword)
					{
						tempItem.addEnchantment(Enchantment.sharpness, 4);
						tempItem.addEnchantment(Enchantment.fireAspect, 1);
					}
					else if(tempItem.getItem() instanceof ItemPickaxe)
					{
						tempItem.addEnchantment(Enchantment.efficiency, 4);
						tempItem.addEnchantment(Enchantment.unbreaking, 3);
					}
					teetp.setInventorySlotContents(0, tempItem);
				}
				break;
	}
}

 

What did I do wrong?

Link to comment
Share on other sites

Buttons and anything that belongs to Gui stuff is CLIENT side.

 

Doing anything directly in gui will change stuff only on client. To set stuff on server you need to setup packets that will send info that you clicked button and change ItemStack on server.

 

Tricks:

While being a normal player the network system (of ItemStack updates) is sided - updates go from server to client (always), thus cahnging on client will do nothing. BUT, the Vanilla has its own system that if the player is in creative mode - the ItemStacks updates are bipolar - that means if you change something in client - it will also change on server.

 

Notes:

You shouldn't allow any players to tell server what to do. Make sure your stuff will work securily and apply some limits.

 

Links:

http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/2137055-1-7-x-1-8-customizing-packet-handling-with

Short: http://www.minecraftforge.net/forum/index.php/topic,20135.0.html

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Doing anything directly in gui will change stuff only on client. To set stuff on server you need to setup packets that will send info that you clicked button and change ItemStack on server.

 

But how do I transmit the 'worldObj' to the server to access the TileEntity? (So far I only know about sending Integers, Strings and ItemStacks)?

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.