-
Notifications
You must be signed in to change notification settings - Fork 497
/
PipePowerWood.java
130 lines (102 loc) · 3.55 KB
/
PipePowerWood.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
/**
* 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 net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import buildcraft.BuildCraftTransport;
import buildcraft.api.power.IPowerProvider;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerFramework;
import buildcraft.core.IIconProvider;
import buildcraft.core.utils.Utils;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTransportPower;
import buildcraft.transport.TileGenericPipe;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class PipePowerWood extends Pipe implements IPowerReceptor {
private static final int MAX_OVERHEAT_TICKS = 100;
private IPowerProvider powerProvider;
protected int standardIconIndex = PipeIconProvider.PipePowerWood_Standard;
protected int solidIconIndex = PipeIconProvider.PipeAllWood_Solid;
private int overheatTicks;
public PipePowerWood(int itemID) {
super(new PipeTransportPower(), new PipeLogicWood(), itemID);
powerProvider = PowerFramework.currentFramework.createPowerProvider();
powerProvider.configure(50, 2, 1000, 1, 1000);
powerProvider.configurePowerPerdition(1, 100);
}
@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 = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
if (metadata == direction.ordinal())
return solidIconIndex;
else
return standardIconIndex;
}
}
@Override
public void setPowerProvider(IPowerProvider provider) {
powerProvider = provider;
}
@Override
public IPowerProvider getPowerProvider() {
if (overheatTicks > 0)
return null;
return powerProvider;
}
@Override
public void doWork() {
// TODO Auto-generated method stub
}
@Override
public void updateEntity() {
super.updateEntity();
if (worldObj.isRemote)
return;
if (powerProvider.getEnergyStored() == powerProvider.getMaxEnergyStored()) {
overheatTicks += overheatTicks < MAX_OVERHEAT_TICKS ? 1 : 0;
} else {
overheatTicks -= overheatTicks > 0 ? 1 : 0;
}
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
if (Utils.checkPipesConnections(container, container.getTile(o))) {
TileEntity tile = container.getTile(o);
if (tile instanceof TileGenericPipe) {
if (((TileGenericPipe) tile).pipe == null) {
continue; // Null pointer protection
}
PipeTransportPower trans = (PipeTransportPower) ((TileGenericPipe) tile).pipe.transport;
float energyToRemove;
if (powerProvider.getEnergyStored() > 40) {
energyToRemove = powerProvider.getEnergyStored() / 40 + 4;
} else if (powerProvider.getEnergyStored() > 10) {
energyToRemove = powerProvider.getEnergyStored() / 10;
} else {
energyToRemove = 1;
}
float energyUsed = powerProvider.useEnergy(1, energyToRemove, true);
trans.receiveEnergy(o.getOpposite(), energyUsed);
}
}
}
}
@Override
public int powerRequest() {
return getPowerProvider().getMaxEnergyReceived();
}
}