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 !

I'm creating a small GUI mod to edit some item stats, like it's name, lore, enchantments etc...

The GUI opens if the player has an item in his main hand.

But now I'm in trouble with using the NBT system to change an ItemStack's name.

After pressing a "Done" button, in the

actionPerformed(GuiButton button)

, this is what I did :

 

if (button == this.doneButton) { // If it's the correct button
if(itemStack.getTagCompound() == null) // If the itemstack doesn't have a TagCompound...
	itemStack.setTagCompound(new NBTTagCompound()); // ...I'll create an empty one
[color=red]itemStack.getTagCompound().getCompoundTag("tag").getCompoundTag("display").setString("Name", name.getText()); // This is where I'm wrong ('name' is the GuiTextField I'm using)[/color]
Minecraft.getMinecraft().thePlayer.openGui(ItemEditorMod.instance, ItemEditorGuiHandler.ITEM_EDITOR_MENU, Minecraft.getMinecraft().theWorld, // This is the method to go to the previous GuiScreen
(int) Minecraft.getMinecraft().thePlayer.posX, (int) Minecraft.getMinecraft().thePlayer.posY,
(int) Minecraft.getMinecraft().thePlayer.posZ);
} 

 

When I check the NBT tag of the selected item using NBTExplorer, no new compound appears. Can someone help me ?

 

 

When I check the NBT tag of the selected item using NBTExplorer, no new compound appears. Can someone help me ?

 

This is because you've edited the client-side object, and as soon as you open the player's inventory again, the server's version overwrites your changes.  You need to send a packet to the server and make the change there.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

Ok, so my Network setup is working. Thanks to Draco18s for his link and diesieben07 for his tutorial (http://www.minecraftforge.net/forum/index.php?topic=20135.0). This is in my Message Handler class :

@Override
public IMessage onMessage(final EditItemMessage message, final MessageContext ctx) {
IThreadListener mainThread = (WorldServer) ctx.getServerHandler().playerEntity.worldObj;
        mainThread.addScheduledTask(new Runnable() {
                @Override
                public void run() {
                	System.out.println("New Name : " + message.text);
                	// Help
                }
        });
        return null;
}

I know I can get the ItemStack I want by using

ctx.getServerHandler().playerEntity.getHeldItemMainhand()

, but then I don't know what to do. I just want to change the ItemStack's name using NBT.

  • Author

Well, didn't you say that it wasn't good ? Because if I do the same same thing...

if(ctx.getServerHandler().playerEntity.getHeldItemMainhand().getTagCompound() == null) ctx.getServerHandler().playerEntity.getHeldItemMainhand().setTagCompound(new NBTTagCompound());
ctx.getServerHandler().playerEntity.getHeldItemMainhand().getTagCompound().getCompoundTag("tag").getCompoundTag("display").setString("Name", message.text);

...I'm getting the same object with an empty "tag" Tag Compound.

  • Author

I have a

stack.getSubCompound()

method, but no

stack.getOrCreateSubCompound()

method. And of course when I use the first one I get a NullPointerException.

ItemStack#getOrCreateSubCompound

has the SRG name

func_190925_c

, so that's probably the method name you'll need to use.

 

I suggest you update your MCP mappings so this is deobfuscated for you.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.