-
Notifications
You must be signed in to change notification settings - Fork 497
/
TileEngineStone.java
171 lines (147 loc) · 4.15 KB
/
TileEngineStone.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
/**
* Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team
* 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.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftEnergy;
import buildcraft.core.GuiIds;
import buildcraft.core.lib.engines.TileEngineWithInventory;
import buildcraft.core.lib.inventory.InvUtils;
import buildcraft.core.lib.utils.MathUtils;
public class TileEngineStone extends TileEngineWithInventory {
static final float MAX_OUTPUT = 10;
static final float MIN_OUTPUT = MAX_OUTPUT / 3;
static final float TARGET_OUTPUT = .375f;
final float kp = 1f;
final float ki = 0.05f;
final double eLimit = (MAX_OUTPUT - MIN_OUTPUT) / ki;
int burnTime = 0;
int totalBurnTime = 0;
ItemStack burnItem;
double esum = 0;
public TileEngineStone() {
super(1);
}
@Override
public String getResourcePrefix() {
return "buildcraftenergy:textures/blocks/engineStone";
}
@Override
public boolean onBlockActivated(EntityPlayer player, ForgeDirection side) {
if (super.onBlockActivated(player, side)) {
return true;
}
if (!worldObj.isRemote) {
player.openGui(BuildCraftEnergy.instance, GuiIds.ENGINE_STONE, worldObj, xCoord, yCoord, zCoord);
}
return true;
}
@Override
public boolean isBurning() {
return burnTime > 0;
}
@Override
public void overheat() {
super.overheat();
burnTime = 0;
}
@Override
public void burn() {
if (burnTime > 0) {
burnTime--;
if (isRedstonePowered) {
currentOutput = calculateCurrentOutput();
addEnergy(currentOutput);
}
} else {
currentOutput = 0;
}
if (burnTime == 0 && isRedstonePowered) {
burnTime = totalBurnTime = getItemBurnTime(getStackInSlot(0));
if (burnTime > 0) {
burnItem = getStackInSlot(0);
setInventorySlotContents(0, InvUtils.consumeItem(getStackInSlot(0)));
}
}
}
public int getScaledBurnTime(int i) {
return (int) (((float) burnTime / (float) totalBurnTime) * i);
}
private int getItemBurnTime(ItemStack itemstack) {
if (itemstack == null) {
return 0;
} else if (itemstack.getItem() == Items.paper) {
return 400;
} else {
return TileEntityFurnace.getItemBurnTime(itemstack);
}
}
/* SAVING & LOADING */
@Override
public void readFromNBT(NBTTagCompound data) {
super.readFromNBT(data);
burnTime = data.getInteger("burnTime");
totalBurnTime = data.getInteger("totalBurnTime");
}
@Override
public void writeToNBT(NBTTagCompound data) {
super.writeToNBT(data);
data.setInteger("burnTime", burnTime);
data.setInteger("totalBurnTime", totalBurnTime);
}
@Override
public void getGUINetworkData(int id, int value) {
super.getGUINetworkData(id, value);
switch (id) {
case 15:
burnTime = value;
break;
case 16:
totalBurnTime = value;
break;
}
}
@Override
public void sendGUINetworkData(Container containerEngine, ICrafting iCrafting) {
super.sendGUINetworkData(containerEngine, iCrafting);
iCrafting.sendProgressBarUpdate(containerEngine, 15, burnTime);
iCrafting.sendProgressBarUpdate(containerEngine, 16, totalBurnTime);
}
@Override
public int maxEnergyReceived() {
return 2000;
}
@Override
public int maxEnergyExtracted() {
return 1000;
}
@Override
public int getMaxEnergy() {
return 10000;
}
@Override
public int calculateCurrentOutput() {
if (burnItem != null && burnItem.getItem() == Items.paper) {
return 1;
}
double e = TARGET_OUTPUT * getMaxEnergy() - energy;
esum = MathUtils.clamp(esum + e, -eLimit, eLimit);
return (int) Math.round(MathUtils.clamp(e * kp + esum * ki, MIN_OUTPUT, MAX_OUTPUT));
}
@Override
public boolean hasCustomInventoryName() {
return false;
}
}