-
Notifications
You must be signed in to change notification settings - Fork 497
/
PipeColoringRecipe.java
85 lines (71 loc) · 2.12 KB
/
PipeColoringRecipe.java
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
package buildcraft.transport;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import buildcraft.core.utils.ColorUtils;
public class PipeColoringRecipe implements IRecipe {
private ItemStack getResult(InventoryCrafting crafting) {
ItemStack oneColorPipeStack = null;
ItemStack pipeStack = null;
boolean hasDifferentColorPipes = false;
boolean hasDifferentPipes = false;
boolean isBleach = false;
ItemStack dye = null;
for (int i = 0; i < 9; i++) {
ItemStack stack = crafting.getStackInSlot(i);
if (stack == null || stack.getItem() == null || stack.stackSize == 0) {
continue;
}
if (stack.getItem() instanceof ItemPipe) {
if (pipeStack == null) {
pipeStack = new ItemStack(stack.getItem(), 1, 0);
oneColorPipeStack = new ItemStack(stack.getItem(), 1, stack.getItemDamage());
} else {
if (stack.getItem() == pipeStack.getItem()) {
pipeStack.stackSize++;
if (oneColorPipeStack.getItemDamage() == oneColorPipeStack.getItemDamage()) {
oneColorPipeStack.stackSize++;
} else {
hasDifferentColorPipes = true;
}
} else {
hasDifferentColorPipes = true;
hasDifferentPipes = true;
}
}
} else if (stack.getItem() == Items.water_bucket) {
isBleach = true;
} else if (ColorUtils.isDye(stack)) {
dye = stack;
}
}
if (isBleach && dye != null) {
return null;
} else if ((isBleach || (dye != null && pipeStack.stackSize == 8)) && !hasDifferentPipes) {
ItemStack result = pipeStack;
if (dye != null) {
result.setItemDamage(ColorUtils.getColorIDFromDye(dye) + 1);
}
return result;
}
return null;
}
@Override
public boolean matches(InventoryCrafting crafting, World world) {
return getResult(crafting) != null;
}
@Override
public ItemStack getCraftingResult(InventoryCrafting crafting) {
return getResult(crafting);
}
@Override
public int getRecipeSize() {
return 10;
}
@Override
public ItemStack getRecipeOutput() {
return null;
}
}