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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
package ihl.processing.metallurgy;
import ic2.api.energy.event.EnergyTileLoadEvent;
import ic2.api.energy.event.EnergyTileUnloadEvent;
import ic2.api.energy.tile.IEnergySink;
import ic2.core.ContainerBase;
import ic2.core.IC2;
import ic2.core.IHasGui;
import ic2.core.block.TileEntityInventory;
import ic2.core.block.invslot.InvSlot.Access;
import ihl.processing.chemistry.ApparatusProcessableInvSlot;
import ihl.recipes.UniversalRecipeOutput;
import java.util.List;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public abstract class MachineBaseTileEntity extends TileEntityInventory implements IHasGui, IEnergySink
{
public short progress;
protected short operationLength=200;
protected double energy;
public int maxStorage;
public int energyConsume;
public final ApparatusProcessableInvSlot input;
private boolean addedToEnergyNet=false;
public MachineBaseTileEntity(int inputCount)
{
input = new ApparatusProcessableInvSlot(this, "input", 0, Access.IO, inputCount, 64);
maxStorage=128;
energyConsume=5;
}
@Override
public List<String> getNetworkedFields()
{
List<String> fields = super.getNetworkedFields();
return fields;
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound)
{
super.readFromNBT(nbttagcompound);
this.progress = nbttagcompound.getShort("progress");
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound)
{
super.writeToNBT(nbttagcompound);
nbttagcompound.setShort("progress", this.progress);
}
@Override
public void onLoaded()
{
super.onLoaded();
if (IC2.platform.isSimulating()&&!this.addedToEnergyNet)
{
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
this.addedToEnergyNet = true;
}
}
@Override
public void onUnloaded()
{
if (IC2.platform.isSimulating()&&this.addedToEnergyNet)
{
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
this.addedToEnergyNet = false;
}
super.onUnloaded();
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
return this.getFacing()!=(short)side;
}
@Override
public void setFacing(short facing1)
{
if (IC2.platform.isSimulating()&&this.addedToEnergyNet)
{
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
this.addedToEnergyNet = false;
}
super.setFacing(facing1);
if (IC2.platform.isSimulating()&&!this.addedToEnergyNet)
{
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
this.addedToEnergyNet = true;
}
}
public boolean enableUpdateEntity()
{
return IC2.platform.isSimulating();
}
public abstract String getStartSoundFile();
public abstract String getLoopSoundFile();
public abstract String getStopSoundFile();
@Override
public void updateEntityServer()
{
if(this.energy>this.maxStorage)
{
this.energy=this.maxStorage;
}
if (this.canOperate() && this.energy >= this.energyConsume)
{
this.setActive(true);
if (this.progress == 0)
{
IC2.network.get().initiateTileEntityEvent(this, 0, true);
}
++this.progress;
this.energy -= this.energyConsume;
if (this.progress >= this.operationLength)
{
this.operate();
this.progress = 0;
IC2.network.get().initiateTileEntityEvent(this, 2, true);
}
}
else
{
if (this.progress != 0 && this.getActive())
{
IC2.network.get().initiateTileEntityEvent(this, 1, true);
}
if (!this.canOperate())
{
this.progress = 0;
}
this.setActive(false);
}
}
protected int mX()
{
switch(this.getFacing())
{
case 4:
return 1;
case 5:
return -1;
default:
return 0;
}
}
protected int mY()
{
switch(this.getFacing())
{
case 0:
return -1;
case 1:
return 1;
default:
return 0;
}
}
protected int mZ()
{
switch(this.getFacing())
{
case 2:
return 1;
case 3:
return -1;
default:
return 0;
}
}
@Override
public abstract String getInventoryName();
@Override
@SideOnly(Side.CLIENT)
public abstract GuiScreen getGui(EntityPlayer arg0, boolean arg1);
@Override
public abstract ContainerBase<?> getGuiContainer(EntityPlayer arg0);
@Override
public void onGuiClosed(EntityPlayer arg0) {}
public int gaugeProgressScaled(int i)
{
return this.progress * i / this.operationLength;
}
public boolean canOperate()
{
return getOutput()!=null;
}
public abstract UniversalRecipeOutput getOutput();
@SuppressWarnings("rawtypes")
public List[] getInput()
{
return new List[]{null, this.input.getItemStackList()};
}
@Override
public double getDemandedEnergy()
{
return this.maxStorage - this.energy;
}
@Override
public int getSinkTier()
{
return 4;
}
@Override
public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage)
{
if (this.energy >= this.maxStorage)
{
return amount;
}
else
{
this.energy += amount;
return 0.0D;
}
}
@Override
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
{
return true;
}
public abstract void operate();
public short getEnergy() {
return (short)this.energy;
}
public void setEnergy(int value)
{
this.energy=value;
}
public int getGUIEnergy(int i) {
if(this.energy<Float.MAX_VALUE)
{
return Math.round((float)this.energy/this.maxStorage*i);
}
else
{
return Math.round((float)(this.energy/this.maxStorage)*i);
}
}
}
|