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

Hello! I am rewriting my Transmutation mod, and I still cannot figure out how to leave an item in the craftMatrix. According to this post, I am supposed to call

matrix.setInventorySlotContents(int i, ItemStack k)

, but when I do so, the item does not stay in the crafting grid!

 

My event subscription method is as follows:

 

public class CraftingHandler
{
    @SubscribeEvent
    public void ItemCraftedEvent(PlayerEvent.ItemCraftedEvent e)
    {
        Transmutation.logger.info("Attempting to craft");
        for (int i = 0; i < e.craftMatrix.getSizeInventory(); i++)
        {
            if (e.craftMatrix.getStackInSlot(i) == null) continue;
            if (e.craftMatrix.getStackInSlot(i).getItem() == Recipes.tStone)
            {
                Transmutation.logger.info("Crafting with a transmutation stone");
                ItemStack stone = e.craftMatrix.getStackInSlot(i);
                if (!stone.hasTagCompound()) return; // debug stone
                Transmutation.logger.info("Crafting complete");
                stone.getTagCompound().setInteger("uses", stone.getTagCompound().getInteger("uses")-1);
                if (stone.getTagCompound().getInteger("uses") < 1) stone = new ItemStack(Blocks.air);
                else
                {
                    Transmutation.logger.info("Attempting to leave the itemstack in the matrix..");
                    e.craftMatrix.setInventorySlotContents(i, stone);
                }
                return;
            }
        }
    }
}

 

As you can see, I am calling

 e.craftMatrix.setInventorySlotContents(i, stone);

but the item does not stay in the crafting grid. How can I fix this?

 

 

On a side note, is there a way to "remove" an itemstack from the crafting grid? I don't know if setting it to an air block is something that's good or not.

  • Author

It seems that when I craft with the item (i set the container item to itself) that the NBT tags are erased, but the item stays in the crafting grid. How can I edit the NBT while crafting?

There is ItemStack version of getItemStack in the Item class:

    public ItemStack getContainerItem(ItemStack itemStack)

You can use it to migrate/modify NBT of the container item.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

  • Author

Where do I edit the nbt while crafting? The craft event?

 

Edit:

 

Never mind! I figured it out myself! Apparently you override the getContainerItem method and do what you wish with it. Here's my end result:

    @Override
    public ItemStack getContainerItem(ItemStack itemStack)
    {
        int uses = itemStack.getTagCompound().getInteger("uses")-1;
        String owner = itemStack.getTagCompound().getString("owner");
        if (uses < 1)
        {
            return null;
        }
        ItemStack cItem = new ItemStack(getContainerItem());
        cItem.setTagCompound(new NBTTagCompound());
        cItem.getTagCompound().setInteger("uses", uses);
        cItem.getTagCompound().setString("owner", owner);
        return cItem;
    }

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.