summaryrefslogtreecommitdiff
path: root/ihl/recipes/RecipeInputDie.java
blob: 8fbd4dbe0f2e78ddfb2b3703000e27a4defc2d1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package ihl.recipes;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import ic2.api.recipe.IRecipeInput;
import ihl.interfaces.IWire;
import ihl.utils.IHLUtils;
import net.minecraft.item.ItemStack;

public class RecipeInputDie  implements IRecipeInput
{
    public final ItemStack input;
    public final int transverseSection;

    public RecipeInputDie(String string, int transverseSection) 
    {
    	this(IHLUtils.getItemStackWithTag(string, "transverseSection", transverseSection));
	}
    
	public RecipeInputDie(ItemStack itemStack) 
	{
		input=itemStack;
		transverseSection=itemStack.stackTagCompound.getInteger("transverseSection");
	}

	@Override
	public boolean matches(ItemStack subject)
    {
		return subject.getItem() == this.input.getItem() && (subject.getItemDamage() == this.input.getItemDamage() || this.input.getItemDamage() == 32767);
    }

    @Override
	public int getAmount()
    {
        return 1;
    }

    @Override
	public List<ItemStack> getInputs()
    {
        return Arrays.asList(new ItemStack[] {this.input});
    }

    @Override
	public String toString()
    {
        ItemStack stack = this.input.copy();
        return "RInputDice<" + stack + ">";
    }

	public List<ItemStack> transformOutput(ItemStack matchedItemStack,	List<ItemStack> outputs) 
	{
		List<ItemStack> newOutputs = new ArrayList<ItemStack>();
		int misTS = matchedItemStack.stackTagCompound.getInteger("transverseSection");
		ItemStack material;
		for(ItemStack material1:outputs)
		{
			if(material1.getItem() instanceof IWire)
			{
				material=material1.copy();
				int length = material.stackTagCompound.getInteger("length");
				length = length * transverseSection / misTS;
				material.stackTagCompound.setInteger("length", length);
				material.stackTagCompound.setInteger("fullLength", length);
				material.stackTagCompound.setInteger("transverseSection", misTS);
				newOutputs.add(material);
			}
			else
			{
				newOutputs.add(material1);
			}
		}
		return newOutputs;
	}
	
	public int transformOutput(ItemStack matchedItemStack, ItemStack material) 
	{
		int consumeAmountMultiplier=1;
		int misTS = matchedItemStack.stackTagCompound.getInteger("transverseSection");
		if(misTS<=transverseSection)
		{
			int length = material.stackTagCompound.getInteger("length");
			length = length * transverseSection / misTS;
			material.stackTagCompound.setInteger("length", length);
			material.stackTagCompound.setInteger("fullLength", length);
		}
		else
		{
			consumeAmountMultiplier=misTS/transverseSection+1;
		}
		material.stackTagCompound.setInteger("transverseSection", misTS);
		return consumeAmountMultiplier;
	}
}