Guest Posted June 5, 2015 Posted June 5, 2015 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? Quote
Ernio Posted June 5, 2015 Posted June 5, 2015 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 Quote 1.7.10 is no longer supported by forge, you are on your own.
Guest Posted June 5, 2015 Posted June 5, 2015 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)? Quote
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.