-
Notifications
You must be signed in to change notification settings - Fork 497
/
PipeFluidsWood.java
166 lines (137 loc) · 4.77 KB
/
PipeFluidsWood.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
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
/**
* BuildCraft is open-source. It is distributed under the terms of the
* BuildCraft Open Source License. It grants rights to read, modify, compile or
* run the code. It does *NOT* grant the right to redistribute this software or
* its modifications in any form, binary or source, except if expressively
* granted by the copyright holder.
*/
package buildcraft.transport.pipes;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.api.transport.IPipeTile;
import buildcraft.api.transport.PipeManager;
import buildcraft.core.network.NetworkData;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTransportFluids;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidHandler;
public class PipeFluidsWood extends Pipe<PipeTransportFluids> implements IPowerReceptor {
public @NetworkData
int liquidToExtract;
private PowerHandler powerHandler;
protected int standardIconIndex = PipeIconProvider.TYPE.PipeFluidsWood_Standard.ordinal();
protected int solidIconIndex = PipeIconProvider.TYPE.PipeAllWood_Solid.ordinal();
long lastMining = 0;
boolean lastPower = false;
private PipeLogicWood logic = new PipeLogicWood(this) {
@Override
protected boolean isValidConnectingTile(TileEntity tile) {
if(tile instanceof IPipeTile)
return false;
if (!(tile instanceof IFluidHandler))
return false;
if (!PipeManager.canExtractFluids(pipe, tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord))
return false;
return true;
}
};
public PipeFluidsWood(int itemID) {
super(new PipeTransportFluids(), itemID);
powerHandler = new PowerHandler(this, Type.MACHINE);
powerHandler.configure(1, 100, 1, 250);
powerHandler.configurePowerPerdition(0, 0);
}
@Override
public boolean blockActivated(EntityPlayer entityplayer) {
return logic.blockActivated(entityplayer);
}
@Override
public void onNeighborBlockChange(int blockId) {
logic.onNeighborBlockChange(blockId);
super.onNeighborBlockChange(blockId);
}
@Override
public void initialize() {
logic.initialize();
super.initialize();
}
/**
* Extracts a random piece of item outside of a nearby chest.
*/
@Override
public void doWork(PowerHandler workProvider) {
if (powerHandler.getEnergyStored() <= 0)
return;
World w = container.worldObj;
int meta = container.getBlockMetadata();
if (meta > 5)
return;
TileEntity tile = container.getTile(ForgeDirection.getOrientation(meta));
if (tile instanceof IFluidHandler) {
if (!PipeManager.canExtractFluids(this, tile.worldObj, tile.xCoord, tile.yCoord, tile.zCoord))
return;
if (liquidToExtract <= FluidContainerRegistry.BUCKET_VOLUME) {
liquidToExtract += powerHandler.useEnergy(1, 1, true) * FluidContainerRegistry.BUCKET_VOLUME;
}
}
powerHandler.useEnergy(1, 1, true);
}
@Override
public PowerReceiver getPowerReceiver(ForgeDirection side) {
return powerHandler.getPowerReceiver();
}
@Override
public void updateEntity() {
super.updateEntity();
int meta = container.getBlockMetadata();
if (liquidToExtract > 0 && meta < 6) {
ForgeDirection side = ForgeDirection.getOrientation(meta);
TileEntity tile = container.getTile(side);
if (tile instanceof IFluidHandler) {
IFluidHandler fluidHandler = (IFluidHandler) tile;
int flowRate = transport.flowRate;
FluidStack extracted = fluidHandler.drain(side.getOpposite(), liquidToExtract > flowRate ? flowRate : liquidToExtract, false);
int inserted = 0;
if (extracted != null) {
inserted = transport.fill(side, extracted, true);
fluidHandler.drain(side.getOpposite(), inserted, true);
}
liquidToExtract -= inserted;
}
}
}
@Override
@SideOnly(Side.CLIENT)
public IIconProvider getIconProvider() {
return BuildCraftTransport.instance.pipeIconProvider;
}
@Override
public int getIconIndex(ForgeDirection direction) {
if (direction == ForgeDirection.UNKNOWN)
return standardIconIndex;
else {
int metadata = container.getBlockMetadata();
if (metadata == direction.ordinal())
return solidIconIndex;
else
return standardIconIndex;
}
}
@Override
public boolean outputOpen(ForgeDirection to) {
int meta = container.getBlockMetadata();
return super.outputOpen(to) && meta != to.ordinal();
}
}