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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
package ihl.processing.chemistry;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import ic2.core.ContainerBase;
import ic2.core.block.invslot.InvSlot;
import ic2.core.block.invslot.InvSlotConsumableLiquid;
import ic2.core.block.invslot.InvSlotOutput;
import ihl.processing.invslots.InvSlotConsumableLiquidIHL;
import ihl.processing.metallurgy.BasicElectricMotorTileEntity;
import ihl.recipes.UniversalRecipeInput;
import ihl.recipes.UniversalRecipeManager;
import ihl.recipes.UniversalRecipeOutput;
import ihl.utils.IHLFluidTank;
import ihl.utils.IHLUtils;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class CryogenicDistillerTileEntity extends BasicElectricMotorTileEntity implements IFluidHandler {
public final InvSlotConsumableLiquidIHL fillInputSlotInput;
public final InvSlotOutput fluidItemsSlot;
public final InvSlotConsumableLiquidIHL fillInputSlotProducts;
private IHLFluidTank fluidTankInput = new IHLFluidTank(8000);
public IHLFluidTank fluidTankProducts = new IHLFluidTank(8000);
protected static final UniversalRecipeManager recipeManager = new UniversalRecipeManager("cryogenicdistiller");
public CryogenicDistillerTileEntity() {
super();
this.fillInputSlotInput = new InvSlotConsumableLiquidIHL(this, "fillInputSlotInput", -1, InvSlot.Access.I, 1,
InvSlot.InvSide.BOTTOM, InvSlotConsumableLiquid.OpType.Fill);
this.fillInputSlotProducts = new InvSlotConsumableLiquidIHL(this, "fillInputSlotProducts", -1, InvSlot.Access.I,
1, InvSlot.InvSide.BOTTOM, InvSlotConsumableLiquid.OpType.Fill);
this.fluidItemsSlot = new InvSlotOutput(this, "fluidCellsOutput", 2, 2);
}
@Override
public String getInventoryName() {
return "CryogenicDistiller";
}
@Override
public void updateEntityServer() {
super.updateEntityServer();
IHLUtils.handleFluidSlotsBehaviour(fillInputSlotProducts, null, fluidItemsSlot, fluidTankProducts);
}
@Override
public ItemStack getWrenchDrop(EntityPlayer player) {
return IHLUtils.getThisModItemStack("cryogenicDistiller");
}
@Override
@SideOnly(Side.CLIENT)
public GuiScreen getGui(EntityPlayer player, boolean arg1) {
return new CryogenicDistillerGui(new CryogenicDistillerContainer(player, this));
}
@Override
public ContainerBase<?> getGuiContainer(EntityPlayer player) {
return new CryogenicDistillerContainer(player, this);
}
@Override
public void operate() {
UniversalRecipeInput ri = CryogenicDistillerTileEntity.recipeManager.getRecipeInput(getInput());
this.fluidTankProducts.fill(getOutput().getFluidOutputs(), true);
this.fluidTankInput.drain(ri.getFluidInputs().get(0), true);
TileEntity teOnTop = worldObj.getTileEntity(xCoord, yCoord + 1, zCoord);
if (teOnTop instanceof IFluidHandler && this.fluidTankProducts.getLigthestFluid() != null) {
IFluidHandler topFH = (IFluidHandler) teOnTop;
if (topFH.canFill(ForgeDirection.DOWN, this.fluidTankProducts.getLigthestFluid().getFluid())) {
FluidStack fsToDrain = this.fluidTankProducts.getLigthestFluid().copy();
fsToDrain.amount = topFH.fill(ForgeDirection.DOWN, fsToDrain, true);
this.fluidTankProducts.drain(fsToDrain, true);
}
}
ForgeDirection orientation = ForgeDirection.getOrientation(this.getFacing());
TileEntity teOnFront = worldObj.getTileEntity(xCoord + orientation.offsetX, yCoord,
zCoord + orientation.offsetZ);
if (teOnFront instanceof IFluidHandler && this.fluidTankProducts.getFluid() != null) {
IFluidHandler frontFH = (IFluidHandler) teOnFront;
if (frontFH.canFill(orientation, this.fluidTankProducts.getFluid().getFluid())) {
FluidStack fsToDrain = this.fluidTankProducts.getFluid().copy();
fsToDrain.amount = frontFH.fill(orientation, fsToDrain, true);
this.fluidTankProducts.drain(fsToDrain, true);
}
}
}
public UniversalRecipeOutput getOutput() {
return CryogenicDistillerTileEntity.recipeManager.getOutputFor(this.getInput());
}
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public List[] getInput() {
return new List[] {Arrays.asList(new FluidStack[] {this.fluidTankInput.getLigthestFluid()}), null };
}
@Override
public boolean canOperate() {
return this.getOutput() != null;
}
@Override
public void onGuiClosed(EntityPlayer arg0) {
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
this.fluidTankInput.readFromNBT(nbttagcompound.getCompoundTag("fluidTankInput"));
this.fluidTankProducts.readFromNBT(nbttagcompound.getCompoundTag("fluidTankProducts"));
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
NBTTagCompound fluidTankInputTag = new NBTTagCompound();
this.fluidTankInput.writeToNBT(fluidTankInputTag);
nbttagcompound.setTag("fluidTankInput", fluidTankInputTag);
NBTTagCompound fluidTankProductsTag = new NBTTagCompound();
this.fluidTankProducts.writeToNBT(fluidTankProductsTag);
nbttagcompound.setTag("fluidTankProducts", fluidTankProductsTag);
}
public static void addRecipe(FluidStack input, FluidStack output, FluidStack output2, boolean specialCondition) {
if (output2 != null) {
recipeManager.addRecipe(new UniversalRecipeInput(new FluidStack[] { input }, null),
new UniversalRecipeOutput(new FluidStack[] { output, output2 }, null, 20, specialCondition));
} else {
recipeManager.addRecipe(new UniversalRecipeInput(new FluidStack[] { input }, null),
new UniversalRecipeOutput(new FluidStack[] { output }, null, 20, specialCondition));
}
}
public static Map<UniversalRecipeInput, UniversalRecipeOutput> getRecipes() {
return recipeManager.getRecipes();
}
public boolean canProcess() {
return this.energy >= this.energyConsume;
}
@Override
public boolean canDrain(ForgeDirection dir, Fluid arg1) {
return dir.equals(ForgeDirection.getOrientation(this.getFacing()))
|| dir.equals(ForgeDirection.UP);
}
@Override
public boolean canFill(ForgeDirection dir, Fluid fluid) {
return dir.equals(ForgeDirection.getOrientation(this.getFacing()).getOpposite());
}
@Override
public FluidStack drain(ForgeDirection dir, FluidStack fstack, boolean doDrain) {
if (this.canDrain(dir, null)) {
return this.fluidTankProducts.drain(fstack, doDrain);
}
return null;
}
@Override
public FluidStack drain(ForgeDirection dir, int amount, boolean doDrain) {
if (this.canDrain(dir, null)) {
if (dir.equals(ForgeDirection.UP)) {
return this.fluidTankProducts.drainLightest(amount, doDrain);
}
return this.fluidTankProducts.drain(amount, doDrain);
}
return null;
}
@Override
public int fill(ForgeDirection dir, FluidStack fstack, boolean doFill) {
if (fstack != null && fstack.getFluid() != null && this.canFill(dir, fstack.getFluid())) {
return this.fluidTankInput.fill(fstack, doFill);
}
return 0;
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection dir) {
return new FluidTankInfo[] { this.fluidTankInput.getInfo(), this.fluidTankProducts.getInfo() };
}
@Override
public void onNetworkEvent(EntityPlayer player, int event) {
switch (event) {
case 0:
this.fluidTankProducts.setEmpty();
break;
}
}
}
|