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

This is the class that this topic is about:

 

public class TileRuneInfuser extends TileEntity {

    private ItemStack rune;
    private ItemStack modifier;


    public void onUse(ItemStack heldItem, EntityPlayer player, EnumHand hand){
        if(heldItem.getItem() instanceof ItemRune){
            if(rune == null){
                ItemStack heldItem2 = heldItem.copy();

                heldItem2.stackSize = 1;
                setRune(heldItem2);

                heldItem.stackSize--;
                player.setHeldItem(hand, heldItem);
                System.out.println("Rune Added");
            }
        }
        else{
            if(modifier == null){
                ItemStack heldItem2 = heldItem.copy();

                heldItem2.stackSize = 1;
                setModifier(heldItem2);

                heldItem.stackSize--;
                player.setHeldItem(hand, heldItem);
                System.out.println("Modifier Added");
            }
        }

        checkRecipe();
    }

    public void extractItem(EntityPlayer player, EnumHand hand){
        if(modifier != null){
            player.inventory.addItemStackToInventory(modifier);
            System.out.println("Modifier Extracted:" + modifier.getDisplayName());
            setModifier(null);
        }
        else if(rune != null) {
            player.inventory.addItemStackToInventory(rune);
            setRune(null);
            System.out.println("Rune Extraced");
        }
    }

    public void checkRecipe(){
        if(rune != null && modifier != null){
            for(BiMap.Entry<ItemStack, InfuserRecipeRegister.InfuserRecipe> b : InfuserRecipeRegister.getRecipes().entrySet()){
                if(modifier.getItem() == b.getKey().getItem()){

                    ItemStack output = b.getValue().getOutput();
                    setModifier(output);
                    System.out.println("Output Set to: " + output.getDisplayName());

                    setRune(null);


                    System.out.println("Rune Removed");
                    return;
                }
            }
        }
    }


    public ItemStack getModifier() {
        return modifier;
    }

    public void setModifier(ItemStack modifier) {
        this.modifier = modifier;
    }

    public ItemStack getRune() {

        return rune;
    }

    public void setRune(ItemStack rune) {
        this.rune = rune;
    }

    @Override
    public NBTTagCompound writeToNBT(NBTTagCompound compound) {
        super.writeToNBT(compound);

        if(rune != null){
            NBTTagList tagList = new NBTTagList();
            NBTTagCompound itemCompound = new NBTTagCompound();
            rune.writeToNBT(itemCompound);
            tagList.appendTag(itemCompound);
            compound.setTag("rune", tagList);
        }

        if(modifier != null){
            NBTTagList itemList = new NBTTagList();
            NBTTagCompound modifierCompound = new NBTTagCompound();
            modifier.writeToNBT(modifierCompound);
            itemList.appendTag(modifierCompound);
            compound.setTag("modifier", itemList);
        }

        return compound;
    }
    
    @Override
    public void readFromNBT(NBTTagCompound compound) {
        super.readFromNBT(compound);

            NBTTagList tagList = (NBTTagList) compound.getTag("rune");
            NBTTagCompound tagCompound = tagList.getCompoundTagAt(0);
            rune = ItemStack.loadItemStackFromNBT(tagCompound);


            NBTTagList modifierList = (NBTTagList) compound.getTag("modifier");
            NBTTagCompound modifierCompound = modifierList.getCompoundTagAt(0);
            modifier = ItemStack.loadItemStackFromNBT(modifierCompound);


    }
}

 

 

So this is how it goes. I add an rune. It gets placed in the rune variable. I add a modifier like a diamond and it will get placed in the modifier variable. This all works with rightclicking

 

Then it looks for the recipe having the modifier and it finds it. It sets the rune value to null and the modifier to the item. I rightclick again and extract the item via the extractItem function and get the output.

 

Then when I do this all over again it does not seem to work. The item doesnt get added to my inventory anymore. It gives all the right information with the println's but just doesnt add the itemstack to the inventory.

 

Does anybody know a fix?

Sounds like an issue I had a week or so ago, with one of my blocks.

Are you sure that the itemstack is a new itemstack?

You cannot really add something to your inventory, which already exists in your inventory, because it IS already in your inventory.

 

Compare the ItemStacks. Either run a few System.out.println(stack.toString) or compare the stacks directly, and see if they equal eachother.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

  • Author

Sounds like an issue I had a week or so ago, with one of my blocks.

Are you sure that the itemstack is a new itemstack?

You cannot really add something to your inventory, which already exists in your inventory, because it IS already in your inventory.

 

Compare the ItemStacks. Either run a few System.out.println(stack.toString) or compare the stacks directly, and see if they equal eachother.

 

Thanks, problem found!

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.