Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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?

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.

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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.