-
Notifications
You must be signed in to change notification settings - Fork 497
/
TileEngineStone.java
169 lines (142 loc) · 4.27 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
/**
* Copyright (c) 2011-2014, 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 java.util.LinkedList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftEnergy;
import buildcraft.api.core.NetworkData;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.mj.IOMode;
import buildcraft.api.mj.MjBattery;
import buildcraft.core.GuiIds;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.utils.MathUtils;
import buildcraft.energy.gui.ContainerEngine;
public class TileEngineStone extends TileEngineWithInventory {
static final float MAX_OUTPUT = 1f;
static final float MIN_OUTPUT = MAX_OUTPUT / 3;
static final float TARGET_OUTPUT = 0.375f;
final float kp = 1f;
final float ki = 0.05f;
final double eLimit = (MAX_OUTPUT - MIN_OUTPUT) / ki;
int burnTime = 0;
int totalBurnTime = 0;
double esum = 0;
@MjBattery(mode = IOMode.SendActive, maxCapacity = 1000, maxSendedPerCycle = 500, minimumConsumption = 0)
@NetworkData
private double mjStored;
public TileEngineStone() {
super(1);
}
@Override
public boolean isActive() {
return isBurning();
}
@Override
public ResourceLocation getBaseTexture() {
return BASE_TEXTURES[1];
}
@Override
public ResourceLocation getChamberTexture() {
return CHAMBER_TEXTURES[1];
}
@Override
public boolean onBlockActivated(EntityPlayer player, ForgeDirection side) {
if (!worldObj.isRemote) {
player.openGui(BuildCraftEnergy.instance, GuiIds.ENGINE_STONE, worldObj, xCoord, yCoord, zCoord);
}
return true;
}
@Override
public float explosionRange() {
return 2;
}
@Override
public boolean isBurning() {
return burnTime > 0;
}
@Override
public void burn() {
if (burnTime > 0) {
burnTime--;
double output = TARGET_OUTPUT * mjStoredBattery.maxCapacity() - mjStored;
esum = MathUtils.clamp(esum + output, -eLimit, eLimit);
addEnergy(MathUtils.clamp(output * kp + esum * ki, MIN_OUTPUT, MAX_OUTPUT));
} else {
totalBurnTime = 0;
}
if (burnTime == 0 && isRedstonePowered) {
burnTime = totalBurnTime = getItemBurnTime(getStackInSlot(0));
if (burnTime > 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 {
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(ContainerEngine containerEngine, ICrafting iCrafting) {
super.sendGUINetworkData(containerEngine, iCrafting);
iCrafting.sendProgressBarUpdate(containerEngine, 15, burnTime);
iCrafting.sendProgressBarUpdate(containerEngine, 16, totalBurnTime);
}
@Override
public LinkedList<ITrigger> getTriggers() {
LinkedList<ITrigger> triggers = super.getTriggers();
triggers.add(BuildCraftCore.triggerEmptyInventory);
triggers.add(BuildCraftCore.triggerContainsInventory);
triggers.add(BuildCraftCore.triggerSpaceInventory);
triggers.add(BuildCraftCore.triggerFullInventory);
return triggers;
}
@Override
public boolean hasCustomInventoryName() {
return false;
}
}