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

Hey everyone!

 

I have a problem with setting the nbt data of an item inside a gui. I am able to set the nbt data of the item in the Constructor and in the initGui() method, but when i try to set it in the onGuiClosed() method the nbt data isn't changed. Can someone explain why and how i can fix it?

 

Here the code of the onGuiClosed method:

 

@Override
    public void onGuiClosed() {
        super.onGuiClosed();
        String s = textField.getText();
        itemTest.stackTagCompound.setString("text", s);
        System.out.println(itemTest.stackTagCompound.getString("text")); //here it shows the right value
        PacketHandler.INSTANCE.sendToServer(new PacketTestItem(itemTest, s));
    }

  • Author
public class PacketTestItem implements IMessageHandler<PacketTestItem, IMessage>, IMessage {

    private ItemStack itemTest;
    private String text;

    public PacketTestItem () {
    }

    public PacketTestItem (ItemStack itemTest, String text) {
        this.itemTest= itemTest;
        this.text= text;
    }

    @Override
    public void fromBytes(ByteBuf buf) {
        itemTest= ByteBufUtils.readItemStack(buf);
        text= ByteBufUtils.readUTF8String(buf);
    }

    @Override
    public void toBytes(ByteBuf buf) {
        ByteBufUtils.writeItemStack(buf, itemTest);
        ByteBufUtils.writeUTF8String(buf, text);
    }

    @Override
    public IMessage onMessage(PacketTestItem message, MessageContext ctx) {
        message.itemTest.stackTagCompound.setString("text",message.text);
        return null;
    }
}

  • Author

If it helps here is the class of the ItemTest:

 

public class ItemTest extends Item {

    public static ItemTest create() {
        ItemTest result = new ItemTest ();
        result.init();
        return result;
    }

    protected ItemTest () {
        setCreativeTab(EnderIOTab.tabEnderIO);
        setUnlocalizedName("itemTest");
        setMaxDamage(0);
        setMaxStackSize(1);
    }

    @Override
    public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {
        if (itemStack.stackTagCompound==null){
            itemStack.stackTagCompound = new NBTTagCompound();
            itemStack.stackTagCompound.setString("text", "");
        }
        if (!world.isRemote){
            Minecraft.getMinecraft().displayGuiScreen(new TestGui(itemStack));
        }
        return itemStack;
    }

    @Override
    public void onCreated(ItemStack itemStack, World world, EntityPlayer entityPlayer) {
        if (itemStack.stackTagCompound==null){
            itemStack.stackTagCompound = new NBTTagCompound();
            itemStack.stackTagCompound.setString("text", "");
        }
        super.onCreated(itemStack, world, entityPlayer);
    }

    @Override
    public void addInformation(ItemStack itemStack, EntityPlayer entityPlayer, List list, boolean b) {
        if (itemStack.stackTagCompound==null){
            itemStack.stackTagCompound = new NBTTagCompound();
            itemStack.stackTagCompound.setString("text", "");
        }
        list.add(itemStack.stackTagCompound.getString("text"));
    }

    @Override
    @SideOnly(Side.CLIENT)
    public void registerIcons(IIconRegister IIconRegister) {
        itemIcon = IIconRegister.registerIcon("enderiofilters:itemTest");
    }

    private void init() {
        GameRegistry.registerItem(this, "itemTest");
    }

}

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.