Jump to content

Shapeless recipe with multiplied input


AlekBardzo

Recommended Posts

Hi, this is probalby rather basic :

GameRegistry.addShapelessRecipe(new ItemStack(CommonProxy.largeGoldCoin,1), new ItemStack(CommonProxy.goldCoin,10));

My intention is to make a recipe that will turn 10 normal coins into one large, but when I test it, it only "eats" one normal coin for each large given. What am I doing wrong ? Is it even possible this way or do I need to handle this stuff differently ?

Link to comment
Share on other sites

You have to make a new implementation of

IRecipe

. Then you have to register your recipe class with

GameRegistry.registerRecipe(new YourRecipe())

.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Where can I change how are inputs processed after crafting ? They are only decremented by amount of 1, no matter what I change.

 

My current code (sloppy, I know) :

public class MultipleInputRecipe implements IRecipe
{
    /** Is the ItemStack that you get when craft the recipe. */
    private final ItemStack recipeOutput;
    
public final Item recipeInput;

private int multiplier;

    public MultipleInputRecipe(ItemStack outputStack, Item item, int multi)
    {
        this.recipeOutput = outputStack;
        this.recipeInput = item;
        this.multiplier = multi;
    }

    public ItemStack getRecipeOutput()
    {
        return this.recipeOutput;
    }

    public ItemStack[] func_179532_b(InventoryCrafting inventory)
    {System.out.println("fired!");
        ItemStack[] aitemstack = new ItemStack[inventory.getSizeInventory()];

        return aitemstack;
    }

    /**
     * Used to check if a recipe matches current crafting inventory
     */
    public boolean matches(InventoryCrafting inventory, World worldIn)
    {
        int amount = 0;
        for (int i = 0; i < inventory.func_174923_h(); ++i)
        {
            for (int j = 0; j < inventory.func_174922_i(); ++j)
            {
                ItemStack itemstack = inventory.getStackInRowAndColumn(j, i);

                if (itemstack != null)
                {
                    if(itemstack.getItem() instanceof SilverCoin && this.recipeInput instanceof SilverCoin)amount+=itemstack.stackSize;
                    if(itemstack.getItem() instanceof GoldCoin && this.recipeInput instanceof GoldCoin)amount+=itemstack.stackSize;
                    if(itemstack.getItem() instanceof LargeGoldCoin && this.recipeInput instanceof LargeGoldCoin)amount+=itemstack.stackSize;
                }
            }
        }
        
        if(amount>=this.multiplier)return true;
        return false;
    }

    /**
     * Returns an Item that is the result of this recipe
     */
    public ItemStack getCraftingResult(InventoryCrafting p_77572_1_)
    {
        return this.recipeOutput.copy();
    }

    /**
     * Returns the size of the recipe area
     */
    public int getRecipeSize()
    {
        return 2;
    }
}

Link to comment
Share on other sites

In 1.8, IRecipe conveniently provides

ItemStack[] getRemainingItems(InventoryCrafting p_179532_1_);

to do exactly this.

In 1.7.10 I think you might have to do something clever with

ItemCraftedEvent  (i.e. modify the crafting matrix to remove "extra" itemstacks).

 

See SlotCrafting.onPickupFromSlot() for the vanilla code where it all happens.  Never tried it myself, it may not work...

 

-TGG

Link to comment
Share on other sites

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



×
×
  • Create New...

Important Information

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