-
Notifications
You must be signed in to change notification settings - Fork 755
/
SmelteryComponent.java
125 lines (109 loc) · 3.96 KB
/
SmelteryComponent.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package tconstruct.library.component;
import java.util.ArrayList;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import tconstruct.library.crafting.Smeltery;
public class SmelteryComponent extends LogicComponent
{
World world;
IInventory master;
MultiFluidTank multitank;
int internalTemp;
public int useTime;
public int fuelGague;
public int fuelAmount;
boolean inUse;
public int[] activeTemps;
public int[] meltingTemps;
public SmelteryComponent(IInventory inventory, World world, MultiFluidTank multitank, int maxTemp)
{
master = inventory;
this.world = world;
this.multitank = multitank;
internalTemp = maxTemp;
}
public void adjustSize (int size, boolean forceAdjust)
{
if (size != activeTemps.length || forceAdjust)
{
int[] tempActive = activeTemps;
activeTemps = new int[size];
int activeLength = tempActive.length > activeTemps.length ? activeTemps.length : tempActive.length;
System.arraycopy(tempActive, 0, activeTemps, 0, activeLength);
int[] tempMelting = meltingTemps;
meltingTemps = new int[size];
int meltingLength = tempMelting.length > meltingTemps.length ? meltingTemps.length : tempMelting.length;
System.arraycopy(tempMelting, 0, meltingTemps, 0, meltingLength);
if (activeTemps.length > 0 && activeTemps.length > tempActive.length)
{
for (int i = tempActive.length; i < activeTemps.length; i++)
{
activeTemps[i] = 20;
meltingTemps[i] = 20;
}
}
}
}
void heatItems ()
{
if (useTime > 0)
{
boolean hasUse = false;
for (int i = 0; i < meltingTemps.length; i++)
{
ItemStack slot = master.getStackInSlot(i);
if (meltingTemps[i] > 20 && slot != null)
{
hasUse = true;
if (activeTemps[i] < internalTemp && activeTemps[i] < meltingTemps[i])
{
activeTemps[i] += 1;
}
else if (activeTemps[i] >= meltingTemps[i])
{
if (!world.isRemote)
{
FluidStack result = getResultFor(slot);
if (result != null)
{
if (multitank.addFluidToTank(result, false))
{
master.setInventorySlotContents(i, null);
activeTemps[i] = 20;
ArrayList alloys = Smeltery.mixMetals(multitank.moltenMetal);
for (int al = 0; al < alloys.size(); al++)
{
FluidStack liquid = (FluidStack) alloys.get(al);
multitank.addFluidToTank(liquid, true);
}
master.onInventoryChanged();
}
}
}
}
}
else
activeTemps[i] = 20;
}
inUse = hasUse;
}
}
public FluidStack getResultFor (ItemStack stack)
{
return Smeltery.instance.getSmelteryResult(stack);
}
public int getInternalTemperature ()
{
return internalTemp;
}
public int getTempForSlot (int slot)
{
return activeTemps[slot];
}
public int getMeltingPointForSlot (int slot)
{
return meltingTemps[slot];
}
}