-
Notifications
You must be signed in to change notification settings - Fork 497
/
CrafterCopy.java
100 lines (78 loc) · 2.1 KB
/
CrafterCopy.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core.inventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import buildcraft.api.recipes.IFlexibleCrafter;
public class CrafterCopy implements IFlexibleCrafter {
private ItemStack[] items;
private FluidStack[] fluids;
public CrafterCopy(IFlexibleCrafter origin) {
items = new ItemStack[origin.getCraftingItemStackSize()];
for (int i = 0; i < items.length; ++i) {
ItemStack s = origin.getCraftingItemStack(i);
if (s != null) {
items[i] = s.copy();
} else {
items[i] = null;
}
}
fluids = new FluidStack[origin.getCraftingFluidStackSize()];
for (int i = 0; i < fluids.length; ++i) {
FluidStack f = origin.getCraftingFluidStack(i);
if (f != null) {
fluids[i] = origin.getCraftingFluidStack(i).copy();
} else {
fluids[i] = null;
}
}
}
@Override
public int getCraftingItemStackSize() {
return items.length;
}
@Override
public ItemStack getCraftingItemStack(int slotid) {
return items[slotid];
}
@Override
public ItemStack decrCraftingItemStack(int slotid, int val) {
ItemStack result;
if (val >= items[slotid].stackSize) {
result = items[slotid];
items[slotid] = null;
} else {
result = items[slotid].copy();
result.stackSize = val;
items[slotid].stackSize -= val;
}
return result;
}
@Override
public FluidStack getCraftingFluidStack(int tankid) {
return fluids[tankid];
}
@Override
public FluidStack decrCraftingFluidStack(int tankid, int val) {
FluidStack result;
if (val >= fluids[tankid].amount) {
result = fluids[tankid];
fluids[tankid] = null;
} else {
result = fluids[tankid].copy();
result.amount = val;
fluids[tankid].amount -= val;
}
return result;
}
@Override
public int getCraftingFluidStackSize() {
return fluids.length;
}
}