Jump to content

Recommended Posts

Posted (edited)

I made a recipe in an older version that adds a string as NBT to tools. Right now I'm having a hard time updating the code to 1.12. Crafting recipes are now registered as json files, which is obviously not possible in a case like this.

 

I have fourproblems that I can't figure out right now:

1) What code do I need to register the recipe?

2) In the recipe class I have an error on the return type of #getRemainingItems. What do I need to change there?

3) #getRecipeSize is apparently not a method of the implemented interface. So I still need this?

4) The interface implemented has got 4 new methods with return values that I have no idea what to make of. What do they need to return?

 

Any help is appreciated. Thanks in advance.

 

Registering:

GameRegistry.addRecipe(new RecipeChecksum()); 

 

Recipe class:

 

	package anagkai.biodiversity.crafting;
	import java.util.List;
import javax.annotation.Nullable;
import com.google.common.collect.Lists;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPickaxe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
	public class RecipeChecksum implements IRecipe
{
    /**
     * Used to check if a recipe matches current crafting inventory
     */
    public boolean matches(InventoryCrafting inv, World worldIn)
    {
        ItemStack itemstack = null;
        List<ItemStack> list = Lists.<ItemStack>newArrayList();
	        for (int i = 0; i < inv.getSizeInventory(); ++i)
        {
            ItemStack itemstack1 = inv.getStackInSlot(i);
	            if (itemstack1 != null)
            {
                if (itemstack1.getItem() instanceof ItemPickaxe)
                {
                    ItemPickaxe itemarmor = (ItemPickaxe)itemstack1.getItem();
	                    if (itemstack != null)
                    {
                        return false;
                    }
	                    itemstack = itemstack1;
                }
                else
                {
                    if (!isCodeItem(itemstack1.getItem(), itemstack1.getMetadata()))
                    {
                        return false;
                    }
	                    list.add(itemstack1);
                }
            }
        }
	        return itemstack != null && !list.isEmpty();
    }
    
    public boolean isCodeItem(Item item, int meta){
        if(item == Items.POISONOUS_POTATO){
            return true;
        }
        if(item == Items.FEATHER){
            return true;
        }
        if(item == Items.GUNPOWDER){
            return true;
        }
        if(item == Items.FISH && meta == 2){
            return true;
        }
        if(item == Items.FISH && meta == 3){
            return true;
        }
        return false;
    }
    
    public String getCodeForItem(Item item, int meta){
        if(item == Items.POISONOUS_POTATO){
            return "P";
        }
        if(item == Items.FEATHER){
            return "F";
        }
        if(item == Items.GUNPOWDER){
            return "G";
        }
        if(item == Items.FISH && meta == 2){
            return "C";
        }
        if(item == Items.FISH && meta == 3){
            return "U";
        }
        return "";
    }
	    /**
     * Returns an Item that is the result of this recipe
     */
    @Nullable
    public ItemStack getCraftingResult(InventoryCrafting inv)
    {
        ItemStack itemstack = null;
        String checksum = "";
        ItemPickaxe itempickaxe = null;
	        for (int k = 0; k < inv.getSizeInventory(); ++k)
        {
            ItemStack itemstack1 = inv.getStackInSlot(k);
	            if (itemstack1 != null)
            {
                if (itemstack1.getItem() instanceof ItemPickaxe)
                {
                    itempickaxe = (ItemPickaxe)itemstack1.getItem();
	                    if (itemstack != null)
                    {
                        return null;
                    }
	                    itemstack = new ItemStack(itemstack1.getItem(), 1);
                }
                else
                {
                    if (!isCodeItem(itemstack1.getItem(), itemstack1.getMetadata()))
                    {
                        return null;
                    }
                    
                    checksum += getCodeForItem(itemstack1.getItem(), itemstack1.getMetadata());
                    
                }
            }
        }
	        if (itempickaxe == null)
        {
            return null;
        }
        else
        {
            if(itemstack.getTagCompound() != null){
            itemstack.getTagCompound().setString("checksum", checksum);
            }else{
                itemstack.setTagCompound(new NBTTagCompound());
                itemstack.getTagCompound().setString("checksum", checksum);
            }
            return itemstack;
        }
    }
	    /**
     * Returns the size of the recipe area
     */
    public int getRecipeSize()
    {
        return 10;
    }
	    @Nullable
    public ItemStack getRecipeOutput()
    {
        return null;
    }
	    public ItemStack[] getRemainingItems(InventoryCrafting inv)
    {
        ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()];
	        for (int i = 0; i < aitemstack.length; ++i)
        {
            ItemStack itemstack = inv.getStackInSlot(i);
            aitemstack[i] = net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack);
        }
	        return aitemstack;
    }
	    @Override
    public IRecipe setRegistryName(ResourceLocation name) {
        return null;
    }
	    @Override
    public ResourceLocation getRegistryName() {
        return null;
    }
	    @Override
    public Class<IRecipe> getRegistryType() {
        return null;
    }
	    @Override
    public boolean canFit(int width, int height) {
        return false;
    }
}
	

 

Edited by Anagkai
Posted

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.

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.