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
|
package gregtech.api.gui;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.api.interfaces.IFluidAccess;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicTank;
import gregtech.api.util.GT_Utility;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
/**
* NEVER INCLUDE THIS FILE IN YOUR MOD!!!
* <p/>
* The Container I use for all my Basic Tanks
*/
public class GT_Container_BasicTank extends GT_ContainerMetaTile_Machine {
public int mContent = 0;
private int oContent = 0;
public GT_Container_BasicTank(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity) {
super(aInventoryPlayer, aTileEntity);
}
/**
* Subclasses must ensure third slot (aSlotIndex==2) is drainable fluid display item slot.
* Otherwise, subclasses must intercept the appropriate the slotClick event and call super.slotClick(2, xxx) if necessary
*/
@Override
public void addSlots(InventoryPlayer aInventoryPlayer) {
addSlotToContainer(new Slot(mTileEntity, 0, 80, 17));
addSlotToContainer(new GT_Slot_Output(mTileEntity, 1, 80, 53));
addSlotToContainer(new GT_Slot_Render(mTileEntity, 2, 59, 42));
}
@Override
public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) {
if (aSlotIndex == 2 && aMouseclick < 2) {
if (mTileEntity.isClientSide()) {
/*
* While a logical client don't really need to process fluid cells upon click (it could have just wait
* for server side to send the result), doing so would result in every fluid interaction having a
* noticeable delay between clicking and changes happening even on single player.
* I'd imagine this lag to become only more severe when playing MP over ethernet, which would have much more latency
* than a memory connection
*/
GT_MetaTileEntity_BasicTank tTank = (GT_MetaTileEntity_BasicTank) mTileEntity.getMetaTileEntity();
tTank.setDrainableStack(GT_Utility.getFluidFromDisplayStack(tTank.getStackInSlot(2)));
}
GT_MetaTileEntity_BasicTank tTank = (GT_MetaTileEntity_BasicTank) mTileEntity.getMetaTileEntity();
BasicTankFluidAccess tDrainableAccess = BasicTankFluidAccess.from(tTank, false);
return handleFluidSlotClick(tDrainableAccess, aPlayer, aMouseclick == 0, true, !tTank.isDrainableStackSeparate());
}
return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer);
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
if (mTileEntity.isClientSide() || mTileEntity.getMetaTileEntity() == null) return;
if (((GT_MetaTileEntity_BasicTank) mTileEntity.getMetaTileEntity()).mFluid != null)
mContent = ((GT_MetaTileEntity_BasicTank) mTileEntity.getMetaTileEntity()).mFluid.amount;
else
mContent = 0;
for (Object crafter : this.crafters) {
ICrafting var1 = (ICrafting) crafter;
if (mTimer % 500 == 0 || oContent != mContent) {
var1.sendProgressBarUpdate(this, 100, mContent & 65535);
var1.sendProgressBarUpdate(this, 101, mContent >>> 16);
}
}
oContent = mContent;
}
@Override
@SideOnly(Side.CLIENT)
public void updateProgressBar(int par1, int par2) {
super.updateProgressBar(par1, par2);
switch (par1) {
case 100:
mContent = mContent & 0xffff0000 | par2 & 0x0000ffff;
break;
case 101:
mContent = mContent & 0xffff | par2 << 16;
break;
}
}
@Override
public int getSlotCount() {
return 2;
}
@Override
public int getShiftClickSlotCount() {
return 1;
}
static class BasicTankFluidAccess implements IFluidAccess {
private final GT_MetaTileEntity_BasicTank mTank;
private final boolean mIsFillableStack;
public BasicTankFluidAccess(GT_MetaTileEntity_BasicTank aTank, boolean aIsFillableStack) {
this.mTank = aTank;
this.mIsFillableStack = aIsFillableStack;
}
@Override
public void set(FluidStack stack) {
if (mIsFillableStack)
mTank.setFillableStack(stack);
else
mTank.setDrainableStack(stack);
}
@Override
public FluidStack get() {
return mIsFillableStack ? mTank.getFillableStack() : mTank.getDrainableStack();
}
@Override
public int getCapacity() {
return mTank.getCapacity();
}
static BasicTankFluidAccess from(GT_MetaTileEntity_BasicTank aTank, boolean aIsFillableStack) {
return new BasicTankFluidAccess(aTank, aIsFillableStack);
}
}
}
|