Jump to content

Texasjake95

Members
  • Posts

    153
  • Joined

  • Last visited

Posts posted by Texasjake95

  1. Is it possible to extend the block metadata by using tile entities? And if it is where would I be able to find out how to do it?

     

    EDIT: Been doing some reading on tile entities and it looks like I don't want to do this because it would take more and more memory to do something like this so I am going to stick with the standard 0-15 block meta (for now)

     

    Although I would still like to know how to do this if just in case the need to do this ever arises...

  2. I got it working but one one recipe can use it... :-\

     

    Any ideas?

     

    package texasjake95.Core;
    
    import java.util.ArrayList;
    import java.util.Iterator;
    
    import net.minecraft.src.Block;
    import net.minecraft.src.EntityPlayer;
    import net.minecraft.src.IRecipe;
    import net.minecraft.src.InventoryCrafting;
    import net.minecraft.src.Item;
    import net.minecraft.src.ItemStack;
    
    public class ShapelessDamageRecipe implements IRecipe{
    
    private static int StackSize;
    private static ItemStack output = null;
        private static ArrayList input = new ArrayList();
    private int ItemDamage;
    
    public ShapelessDamageRecipe(Item  result, Object... recipe)
    {
    	this(new ItemStack(result), recipe); 
    }
    
    
    
    public ShapelessDamageRecipe(ItemStack result, Object... recipe)
        {
            StackSize = result.stackSize;
            for (Object in : recipe)
            {
                if (in instanceof ItemStack)
                {
                    input.add(((ItemStack)in).copy());
                    //ItemDamage = ItemDamage + ((ItemStack) in).getItemDamage();
                }
                else if (in instanceof Item)
                {
                    input.add(new ItemStack((Item)in));
                    //ItemDamage = ItemDamage + new ItemStack((Item)in).getItemDamage();
                }
                else if (in instanceof Block)
                {
                    input.add(new ItemStack((Block)in));
                   // ItemDamage = ItemDamage + new ItemStack((Block)in).getItemDamage();
                }
                else
                {
                    String ret = "Invalid shapeless damage recipe: ";
                    for (Object tmp :  recipe)
                    {
                        ret += tmp + ", ";
                    }
                    ret += output;
                    throw new RuntimeException(ret);
                }
            }
           output = result.copy();
        }
    
    @Override
    public boolean matches(InventoryCrafting var1) {
    
    	ArrayList required = new ArrayList(input);
    	int par1 = 0;
            for (int x = 0; x < var1.getSizeInventory(); x++)
            {
                ItemStack slot = var1.getStackInSlot(x);
    
                if (slot != null)
                {
                    boolean inRecipe = false;
                    Iterator req = required.iterator();
    
                    while (req.hasNext())
                    {
                        boolean match = false;
                        
                        Object next = req.next();
                        
                        if (next instanceof ItemStack)
                        {
                            match = checkItemEquals((ItemStack)next, slot);
                            
                        }
                        else if (next instanceof ArrayList)
                        {
                            for (ItemStack item : (ArrayList<ItemStack>)next)
                            {
                                match = match || checkItemEquals(item, slot);
                               
                            }
                        }
    
                        if (match)
                        {
                            inRecipe = true;
                            ItemDamage = ItemDamage + slot.getItemDamage();
                            required.remove(next);
                            break;
                        }
                    }
    
                    if (!inRecipe)
                    {
                        return false;
                    }
                }
            }
    
            return required.isEmpty();
    }
    
    @Override
    public ItemStack getCraftingResult(InventoryCrafting var1) {
    	ItemStack a = output.copy();
    	ItemStack b = new ItemStack (a.getItem(), 1, ItemDamage);		
    	 return b;
    }
    
    @Override
    public int getRecipeSize() {
    
    	return input.size();
    }
    
    @Override
    public ItemStack getRecipeOutput() {
    	ItemStack a = output.copy();
    	ItemStack b = new ItemStack (a.getItem(), 1, ItemDamage);		
    	 return b;
    }
     private static boolean checkItemEquals(ItemStack target, ItemStack input)
        {
            return (target.itemID == input.itemID);
        }
    }
    

     

  3. Sorry for the late reply

    Here's the Code:

     

    package texasjake95.mod;
    
    import java.util.ArrayList;
    import java.util.Iterator;
    
    import net.minecraft.src.Block;
    import net.minecraft.src.IRecipe;
    import net.minecraft.src.InventoryCrafting;
    import net.minecraft.src.Item;
    import net.minecraft.src.ItemStack;
    
    public class ShapelessDamageRecipe implements IRecipe{
    
    private int ItemDamage = 0;
    private int StackSize = 0;
    private ItemStack output = null;
        private ArrayList input = new ArrayList();    
    
    public ShapelessDamageRecipe(Item  result, Object... recipe){ this(new ItemStack(result), recipe); }
    
    public ShapelessDamageRecipe(ItemStack result, Object... recipe)
        {
            StackSize = result.stackSize;
            for (Object in : recipe)
            {
                if (in instanceof ItemStack)
                {
                    input.add(((ItemStack)in).copy());
                    ItemDamage = ItemDamage + ((ItemStack) in).getItemDamage();
                }
                else if (in instanceof Item)
                {
                    input.add(new ItemStack((Item)in));
                    ItemDamage = ItemDamage + new ItemStack((Item)in).getItemDamage();
                }
                else if (in instanceof Block)
                {
                    input.add(new ItemStack((Block)in));
                    ItemDamage = ItemDamage + new ItemStack((Block)in).getItemDamage();
                }
                else
                {
                    String ret = "Invalid shapeless damage recipe: ";
                    for (Object tmp :  recipe)
                    {
                        ret += tmp + ", ";
                    }
                    ret += output;
                    throw new RuntimeException(ret);
                }
            }
           output = new ItemStack(result.getItem(), StackSize, ItemDamage);
        }
    
    @Override
    public boolean matches(InventoryCrafting var1) {
    	// TODO Auto-generated method stub
    	ArrayList required = new ArrayList(input);
    
            for (int x = 0; x < var1.getSizeInventory(); x++)
            {
                ItemStack slot = var1.getStackInSlot(x);
    
                if (slot != null)
                {
                    boolean inRecipe = false;
                    Iterator req = required.iterator();
    
                    while (req.hasNext())
                    {
                        boolean match = false;
                        
                        Object next = req.next();
                        
                        if (next instanceof ItemStack)
                        {
                            match = checkItemEquals((ItemStack)next, slot);
                        }
                        else if (next instanceof ArrayList)
                        {
                            for (ItemStack item : (ArrayList<ItemStack>)next)
                            {
                                match = match || checkItemEquals(item, slot);
                            }
                        }
    
                        if (match)
                        {
                            inRecipe = true;
                            required.remove(next);
                            break;
                        }
                    }
    
                    if (!inRecipe)
                    {
                        return false;
                    }
                }
            }
    
            return required.isEmpty();
    }
    
    @Override
    public ItemStack getCraftingResult(InventoryCrafting var1) {
    	// TODO Auto-generated method stub
    	 return output.copy();
    }
    
    @Override
    public int getRecipeSize() {
    	// TODO Auto-generated method stub
    	return input.size();
    }
    
    @Override
    public ItemStack getRecipeOutput() {
    	// TODO Auto-generated method stub
    	return output;
    }
     private boolean checkItemEquals(ItemStack target, ItemStack input)
        {
            return (target.itemID == input.itemID && (target.getItemDamage() == -1 || target.getItemDamage() == input.getItemDamage()));
        }
    }
    

     

     

    Recipe using it:

    CraftingManager.getInstance().getRecipeList().add(new ShapelessDamageRecipe (new ItemStack(MultiWood), 
    new Object[] {new ItemStack(Item.pickaxeWood, 1 , -1), new ItemStack(Item.shovelWood, 1 , -1), new ItemStack(Item.axeWood, 1 , -1), new ItemStack(Item.swordWood, 1 , -1),}));

×
×
  • Create New...

Important Information

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