Jump to content

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


Recommended Posts

Posted

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.

Posted
  On 4/24/2014 at 7:15 AM, Godis_apan said:

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 ?

Posted
  On 4/24/2014 at 5:25 PM, diesieben07 said:

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 :) !

Posted

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 :) !

Posted

Ok, so how I can do that ? Transform my PacketChangeItemStack to, PacketItemStackGui, and I just add the player, the gui.class, the itemstack and the slot number of the gui ? or not ?

Ok it's not that, how can I make that u say ?

Posted
  On 4/25/2014 at 12:52 PM, diesieben07 said:

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

 

  Quote
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

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Make a test with another Launcher like the Curseforge Launcher, MultiMC or AT Launcher
    • can anyone help me i am opening forge and add modpacks and then it says unable to update native luancher and i redownlaod java and the luancher it self?
    • The problem occurs also in 1.20.1 Forge, but with an "Error executing task on client" instead. I have "Sinytra Connector" installed. On 1.21.5 Fabric, there is no problem. When this happens, the chat message before the death screen appears gets sent, with an extra dash added.
    • Well, as usual, it was user error. Naming mismatch in sounds.json.  Please delete this post if you find it necessary. 
    • Hello Forge community.  I'm running into an issue with a mod I'm working on.  To preface, I can call /playsound modId:name music @a and I can hear the sound I registered being played in game. Great!  However, I cannot get it to trigger via my mod code.    Registration: public static final RegistryObject<SoundEvent> A_WORLD_OF_MADNESS = SOUND_EVENTS.register("a_world_of_madness", () -> new SoundEvent(new ResourceLocation("tetheredsouls", "a_world_of_madness")));   Playback: Minecraft mc = Minecraft.getInstance(); if (!(mc.player instanceof LocalPlayer) || mc.level == null) return; LocalPlayer player = (LocalPlayer) mc.player; BlockPos pos = player.blockPosition(); SoundEvent track = ModSounds.A_WORLD_OF_MADNESS.get(); System.out.println(track); System.out.println(pos); System.out.println(player); // play exactly like the tutorial: client-only, at the player's position try { mc.level.playLocalSound( player.getX(), player.getY(), player.getZ(), track, SoundSource.MUSIC, // Or MASTER if needed 1f, 1f, false ); System.out.println("[DEBUG] playSound success: " + track.getLocation()); } catch (Exception e) { System.err.println("[ERROR] Failed to play sound: " + track.getLocation()); e.printStackTrace(); } Sounds.json:   { "theme_of_laura": { "category": "music", "sounds": [ { "name": "tetheredsouls:a_world_of_madness", "stream": true } ] } } Things I have tried: - multiple .ogg files. Short .ogg files (5 seconds, <100KB).  - default minecraft sounds imported from import net.minecraft.sounds.SoundEvents; These work given my code. No idea why these are different.  - playSound() method, as well as several others in past iterations that did not work   I would be forever grateful if somebody could point me in the right direction. I've looked at several mod github repositories and found extremely similar code to what I'm doing. I've also found several threads in this forum that did not solve my issue. I just cannot figure out what I'm doing differently, and why I'm able to queue sounds manually with playsound but the code won't play it (despite confirming the code is being run with the debug statements.)
  • Topics

×
×
  • Create New...

Important Information

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