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
|
package GoodGenerator.Blocks.TEs.MetaTE;
import GoodGenerator.Blocks.TEs.YottaFluidTank;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch;
import gregtech.api.render.TextureFactory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
import static gregtech.api.enums.Textures.BlockIcons.OVERLAY_PIPE_OUT;
public class YottaFluidTankOutputHatch extends GT_MetaTileEntity_Hatch {
private String mFluidName = "";
private int mOutputSpeed = 0;
private int mX, mZ, mY;
private boolean isBound = false;
@Override
public void loadNBTData(NBTTagCompound aNBT) {
mFluidName = aNBT.getString("mFluidName");
mOutputSpeed = aNBT.getInteger("mOutputSpeed");
mX = aNBT.getInteger("mX");
mZ = aNBT.getInteger("mZ");
mY = aNBT.getInteger("mY");
isBound = aNBT.getBoolean("isBound");
super.loadNBTData(aNBT);
}
@Override
public void saveNBTData(NBTTagCompound aNBT) {
aNBT.setString("mFluidName", mFluidName);
aNBT.setInteger("mOutputSpeed", mOutputSpeed);
aNBT.setInteger("mX", mX);
aNBT.setInteger("mZ", mZ);
aNBT.setInteger("mY", mY);
aNBT.setBoolean("isBound", isBound);
super.saveNBTData(aNBT);
}
public YottaFluidTankOutputHatch(int aID, String aName, String aNameRegional, int aTier) {
super(aID, aName, aNameRegional, aTier, 0, "Output Fluid From YOTTank.");
}
public YottaFluidTankOutputHatch(String aName, int aTier, String[] aDescription, ITexture[][][] aTextures) {
super(aName, aTier, 0, aDescription, aTextures);
}
public void setFluid(FluidStack output) {
if (output == null) {
mFluidName = "";
mOutputSpeed = 0;
return;
}
mFluidName = output.getFluid().getName();
mOutputSpeed = output.amount;
}
public void setControl(int x, int y, int z) {
mX = x;
mY = y;
mZ = z;
isBound = true;
}
public void unBounded() {
isBound = false;
}
public boolean isBounded() {
return isBound;
}
@Override
public boolean isFacingValid(byte aFacing) {
return true;
}
@Override
public boolean isLiquidInput(byte aSide) {
return false;
}
@Override
public boolean isSimpleMachine() {
return true;
}
@Override
public boolean isAccessAllowed(EntityPlayer aPlayer) {
return true;
}
@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
super.onPostTick(aBaseMetaTileEntity, aTick);
if (aBaseMetaTileEntity.isServerSide()) {
IFluidHandler tTileEntity = aBaseMetaTileEntity.getITankContainerAtSide(aBaseMetaTileEntity.getFrontFacing());
FluidStack tOutput = FluidRegistry.getFluidStack(mFluidName, mOutputSpeed);
IGregTechTileEntity tController = aBaseMetaTileEntity.getIGregTechTileEntity(mX, mY, mZ);
if (tTileEntity != null && tOutput != null && tController.getMetaTileEntity() instanceof YottaFluidTank && isBound) {
int tAmount = Math.min(tTileEntity.fill(ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()), tOutput, false), mOutputSpeed);
if (tAmount > 0) {
tOutput.amount = tAmount;
if (((YottaFluidTank) tController).reduceFluid(tAmount))
tTileEntity.fill(ForgeDirection.getOrientation(aBaseMetaTileEntity.getBackFacing()), tOutput, true);
}
}
if (tController == null || !(tController.getMetaTileEntity() instanceof YottaFluidTank)) isBound = false;
}
}
@Override
public ITexture[] getTexturesActive(ITexture aBaseTexture) {
return new ITexture[]{aBaseTexture, TextureFactory.of(OVERLAY_PIPE_OUT)};
}
@Override
public ITexture[] getTexturesInactive(ITexture aBaseTexture) {
return new ITexture[]{aBaseTexture, TextureFactory.of(OVERLAY_PIPE_OUT)};
}
@Override
public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
return new YottaFluidTankOutputHatch(mName, mTier, mDescriptionArray, mTextures);
}
}
|