Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.2][SOLVED] Can't change a ItemStack properties in my Custom GuiContainer


beaucoralk
 Share

Recommended Posts

Hello all,

 

I need your help for create a custom "GuiContainer" applied on an "ItemStack" with a Right Click. For my exemple, it's a "ItemStack" (item Plan) who will contain many others "ItemStack" to make a plan. I want use the "NBTTagCompound" of this item plan to save all the "ItemStack" who are containing into my item plan.

 

Here, my code : https://gist.github.com/beaucoralk/11235143

 

I realy need your help, because when I change the NBTTagCompound of my item in my Container, It don't change in real...

Please help me !

 

Sorry for my bad english.

Minecraftly, Kevin BEAUCORAL.

Link to comment
Share on other sites

http://www.minecraftforum.net/topic/1412300-147forgeblaueseichoerns-gui-tutorial/

 

Under the spoiler gui there should be an itemstack tutorial.

Thanks for you help but my problem it's not than I can't open a gui on a Right Click of ItemStack your link don't help me more. Look my code into the gist to understand my problem !

My problem it's that, after Right Click on my Item (ItemPlan) I want to change the properties of this Item who are RightClicked with my Gui, like a ItemBook, and I don't arrive to change it...

 

I think the problem it's the GuiHandler I don't do the good thing...

 

Someone else can help me ?

Link to comment
Share on other sites

You are changing the ItemStack from the GuiScreen. GuiScreen is only on the client side, but you need to change things on the server side. You will need to send packets.

Realy big thanks for your help diesieben07.

How and where ? Where in my GuiScreen I'm changing the ItemStack ? I changing the content of ItemStack into my Container who are used by the "public Object getServerGuiElement".

U can use my gist (modifiy) to show me :) !

Link to comment
Share on other sites

Done !!!

 

I help me by this page : http://www.minecraftforge.net/wiki/Netty_Packet_Handling

and this topic : http://www.minecraftforge.net/forum/index.php?topic=17242.0

 

I change my gist if someone want help about subject : https://gist.github.com/beaucoralk/11235143

 

In fact, we need to create a packet for send a modification of an item... it's strange, why minecraft don't already have a packet when changing a itemstack ? or I don't see it...

I create a PacketPipeline class, a PacketChangeItemStack class who read a decode a buffer ItemStack and encode a ItemStack to buffer.

And I use my PacketPipeline to send a new PacketChangeItemStack, and it's work fine :) !

Link to comment
Share on other sites

Just so you know: Your method is prone to hacks.

A hacked client can just send a PacketChangeItemStack at any point, without even having your GUI open. Now if that packet happens to contain an ItemStack with 64 diamonds, the server will happily give you 64 diamonds.

 

Never ever put logic like that on the client side. The client should not tell the server "Hey, this is the new ItemStack!", it should say "Hey, the user clicked this button on the gui!". Then the server does some validation that the player is actually viewing the GUI, that the button can be pressed right now and then performs the appropriate action.

Link to comment
Share on other sites

Looks good now. You can replace the .getClass() == XY.class check with an instanceof XY, that is going to perform better and looks nicer.

 

I've a question, why the function "onGuiClosed()" is called when I open my custom Gui ?

Because you are opening the GUI twice, once on the client, once on the server (
onItemRightClick

get's called both sides). You should only open on the server, it will then tell the client to open.

Link to comment
Share on other sites

Looks good now. You can replace the .getClass() == XY.class check with an instanceof XY, that is going to perform better and looks nicer.

 

I've a question, why the function "onGuiClosed()" is called when I open my custom Gui ?

Because you are opening the GUI twice, once on the client, once on the server (
onItemRightClick

get's called both sides). You should only open on the server, it will then tell the client to open.

Ok thanks realy big thanks for your help !!

 

I was wondering if you could help me to progress my plugin by testing when the versions are finished? U can see all features and the advancement to my github and on the plugin repo for my mod : https://github.com/beaucoralk/labnetwork-public/issues

Link to comment
Share on other sites

Never ever use @SideOnly!

If you do @SideOnly(Side.SERVER) the entire method will be deleted on the Dedicated Server. That is not what you want. You want to check for the logical side (Integrated Server is still serverside, but will not have @SideOnly(Side.SERVER)!). You do that via

world.isRemote

. It is true on the client, false on the server.

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

 Share



×
×
  • Create New...

Important Information

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