-
Notifications
You must be signed in to change notification settings - Fork 497
/
Engine.java
208 lines (155 loc) · 4.08 KB
/
Engine.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
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
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.energy;
import net.minecraft.inventory.ICrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.LiquidStack;
import net.minecraftforge.liquids.LiquidTank;
import buildcraft.core.network.TileNetworkData;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.energy.gui.ContainerEngine;
public abstract class Engine {
public int maxEnergy;
protected float currentOutput = 0;
public @TileNetworkData
float progress;
public @TileNetworkData
ForgeDirection orientation;
public float energy;
public @TileNetworkData
EnergyStage energyStage = EnergyStage.Blue;
public int maxEnergyExtracted = 1;
protected TileEngine tile;
public enum EnergyStage {
Blue, Green, Yellow, Red, Explosion
}
public Engine(TileEngine tile) {
this.tile = tile;
}
protected void computeEnergyStage() {
double level = energy / (double) maxEnergy * 100.0;
if (level <= 25.0) {
energyStage = EnergyStage.Blue;
} else if (level <= 50.0) {
energyStage = EnergyStage.Green;
} else if (level <= 75.0) {
energyStage = EnergyStage.Yellow;
} else if (level <= 100.0) {
energyStage = EnergyStage.Red;
} else {
energyStage = EnergyStage.Explosion;
}
}
public final EnergyStage getEnergyStage() {
if (!CoreProxy.proxy.isRenderWorld(tile.worldObj)) {
computeEnergyStage();
}
return energyStage;
}
public void update() {
if (!tile.isRedstonePowered) {
if (energy >= 1) {
energy -= 1;
} else if (energy < 1) {
energy = 0;
}
}
}
public abstract String getTextureFile();
public abstract int explosionRange();
public int minEnergyReceived() {
return 2;
}
public abstract int maxEnergyReceived();
public abstract float getPistonSpeed();
public abstract boolean isBurning();
public abstract void delete();
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill) {
return 0;
}
public void addEnergy(float addition) {
energy += addition;
if (getEnergyStage() == EnergyStage.Explosion) {
tile.worldObj.createExplosion(null, tile.xCoord, tile.yCoord, tile.zCoord, explosionRange(), true);
}
if (energy > maxEnergy) {
energy = maxEnergy;
}
}
public float extractEnergy(int min, int max, boolean doExtract) {
if (energy < min)
return 0;
int actualMax;
if (max > maxEnergyExtracted) {
actualMax = maxEnergyExtracted;
} else {
actualMax = max;
}
if (actualMax < min)
return 0;
float extracted;
if (energy >= actualMax) {
extracted = actualMax;
if (doExtract) {
energy -= actualMax;
}
} else {
extracted = energy;
if (doExtract) {
energy = 0;
}
}
return extracted;
}
public abstract int getScaledBurnTime(int i);
public abstract void burn();
public void readFromNBT(NBTTagCompound nbttagcompound) {
}
public void writeToNBT(NBTTagCompound nbttagcompound) {
}
public void getGUINetworkData(int i, int j) {
}
public void sendGUINetworkData(ContainerEngine containerEngine, ICrafting iCrafting) {
}
public boolean isActive() {
return true;
}
public int getHeat() {
return 0;
}
public float getEnergyStored() {
return energy;
}
public float getCurrentOutput() {
return currentOutput;
}
/* ILIQUIDCONTAINER */
public LiquidTank[] getLiquidSlots() {
return new LiquidTank[0];
}
/* IINVENTORY */
public int getSizeInventory() {
return 0;
}
public ItemStack getStackInSlot(int i) {
return null;
}
public ItemStack decrStackSize(int i, int j) {
return null;
}
public ItemStack getStackInSlotOnClosing(int i) {
return getStackInSlot(i);
}
public void setInventorySlotContents(int i, ItemStack itemstack) {
}
public abstract ILiquidTank getTank(ForgeDirection direction, LiquidStack type);
}