mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-22 05:02:25 +00:00
new cap banks integrate properly with conduits. Now uses interface so could add support for other power storage implementations.
This commit is contained in:
1 parent
0c71f07769
commit
1856abcc14
13 files changed
+298
-116
No files matched your search
@@ -18,8 +18,8 @@ import crazypants.enderio.conduit.ConduitNetworkTickHandler.TickListener;
|
||||
import crazypants.enderio.conduit.ConnectionMode;
|
||||
import crazypants.enderio.conduit.power.PowerConduitNetwork.ReceptorEntry;
|
||||
import crazypants.enderio.config.Config;
|
||||
import crazypants.enderio.machine.power.TileCapacitorBank;
|
||||
import crazypants.enderio.power.IPowerInterface;
|
||||
import crazypants.enderio.power.IPowerStorage;
|
||||
|
||||
public class NetworkPowerManager {
|
||||
|
||||
@@ -68,14 +68,14 @@ public class NetworkPowerManager {
|
||||
return maxEnergyStored;
|
||||
}
|
||||
|
||||
public int getPowerInCapacitorBanks() {
|
||||
public long getPowerInCapacitorBanks() {
|
||||
if(capSupply == null) {
|
||||
return 0;
|
||||
}
|
||||
return capSupply.stored;
|
||||
}
|
||||
|
||||
public int getMaxPowerInCapacitorBanks() {
|
||||
public long getMaxPowerInCapacitorBanks() {
|
||||
if(capSupply == null) {
|
||||
return 0;
|
||||
}
|
||||
@@ -301,8 +301,8 @@ public class NetworkPowerManager {
|
||||
storageReceptors.clear();
|
||||
for (ReceptorEntry rec : network.getPowerReceptors()) {
|
||||
if(rec.powerInterface.getDelegate() != null &&
|
||||
rec.powerInterface.getDelegate().getClass() == TileCapacitorBank.class &&
|
||||
!((TileCapacitorBank) rec.powerInterface.getDelegate()).isCreative()) {
|
||||
rec.powerInterface.getDelegate() instanceof IPowerStorage &&
|
||||
!((IPowerStorage) rec.powerInterface.getDelegate()).isCreative()) {
|
||||
storageReceptors.add(rec);
|
||||
} else {
|
||||
receptors.add(rec);
|
||||
@@ -342,11 +342,11 @@ public class NetworkPowerManager {
|
||||
|
||||
int canExtract;
|
||||
int canFill;
|
||||
Set<TileCapacitorBank> capBanks = new HashSet<TileCapacitorBank>();
|
||||
Set<IPowerStorage> capBanks = new HashSet<IPowerStorage>();
|
||||
|
||||
float filledRatio;
|
||||
int stored = 0;
|
||||
int maxCap = 0;
|
||||
double filledRatio;
|
||||
long stored = 0;
|
||||
long maxCap = 0;
|
||||
|
||||
List<CapBankSupplyEntry> enteries = new ArrayList<NetworkPowerManager.CapBankSupplyEntry>();
|
||||
|
||||
@@ -361,38 +361,38 @@ public class NetworkPowerManager {
|
||||
stored = 0;
|
||||
maxCap = 0;
|
||||
|
||||
float toBalance = 0;
|
||||
float maxToBalance = 0;
|
||||
double toBalance = 0;
|
||||
double maxToBalance = 0;
|
||||
|
||||
for (ReceptorEntry rec : storageReceptors) {
|
||||
TileCapacitorBank cb = (TileCapacitorBank) rec.powerInterface.getDelegate();
|
||||
IPowerStorage cb = (IPowerStorage) rec.powerInterface.getDelegate();
|
||||
|
||||
boolean processed = capBanks.contains(cb.getController());
|
||||
|
||||
if(!processed) {
|
||||
stored += cb.getEnergyStored();
|
||||
maxCap += cb.getMaxEnergyStored();
|
||||
stored += cb.getEnergyStoredL();
|
||||
maxCap += cb.getMaxEnergyStoredL();
|
||||
capBanks.add(cb.getController());
|
||||
}
|
||||
|
||||
if(rec.emmiter.getConnectionMode(rec.direction) == ConnectionMode.IN_OUT) {
|
||||
toBalance += cb.getEnergyStored();
|
||||
maxToBalance += cb.getMaxEnergyStored();
|
||||
toBalance += cb.getEnergyStoredL();
|
||||
maxToBalance += cb.getMaxEnergyStoredL();
|
||||
}
|
||||
|
||||
int canGet = 0;
|
||||
long canGet = 0;
|
||||
if(cb.isOutputEnabled(rec.direction.getOpposite())) {
|
||||
canGet = Math.min(cb.getEnergyStored(), cb.getMaxOutput());
|
||||
canGet = Math.min(cb.getEnergyStoredL(), cb.getMaxOutput());
|
||||
canGet = Math.min(canGet, rec.emmiter.getMaxEnergyRecieved(rec.direction));
|
||||
canExtract += canGet;
|
||||
}
|
||||
int canFill = 0;
|
||||
long canFill = 0;
|
||||
if(cb.isInputEnabled(rec.direction.getOpposite())) {
|
||||
canFill = Math.min(cb.getMaxEnergyStored() - cb.getEnergyStored(), cb.getMaxInput());
|
||||
canFill = Math.min(cb.getMaxEnergyStoredL() - cb.getEnergyStoredL(), cb.getMaxInput());
|
||||
canFill = Math.min(canFill, rec.emmiter.getMaxEnergyExtracted(rec.direction));
|
||||
this.canFill += canFill;
|
||||
}
|
||||
enteries.add(new CapBankSupplyEntry(cb, canGet, canFill, rec.emmiter, rec.direction));
|
||||
enteries.add(new CapBankSupplyEntry(cb, (int) canGet, (int) canFill, rec.emmiter, rec.direction));
|
||||
|
||||
}
|
||||
|
||||
@@ -452,11 +452,11 @@ public class NetworkPowerManager {
|
||||
double ratio = (double) amount / canExtract;
|
||||
|
||||
for (CapBankSupplyEntry entry : enteries) {
|
||||
int use = (int) Math.ceil(ratio * entry.canExtract);
|
||||
long use = (int) Math.ceil(ratio * entry.canExtract);
|
||||
use = Math.min(use, amount);
|
||||
use = Math.min(use, entry.canExtract);
|
||||
entry.capBank.addEnergy(-use);
|
||||
trackerRecieve(entry.emmiter, use, true);
|
||||
entry.capBank.addEnergy((int) -use);
|
||||
trackerRecieve(entry.emmiter, (int) use, true);
|
||||
amount -= use;
|
||||
if(amount == 0) {
|
||||
return;
|
||||
@@ -471,11 +471,11 @@ public class NetworkPowerManager {
|
||||
double ratio = (double) amount / canFill;
|
||||
|
||||
for (CapBankSupplyEntry entry : enteries) {
|
||||
int add = (int) Math.ceil(ratio * entry.canFill);
|
||||
long add = (int) Math.ceil(ratio * entry.canFill);
|
||||
add = Math.min(add, entry.canFill);
|
||||
add = Math.min(add, amount);
|
||||
entry.capBank.addEnergy(add);
|
||||
trackerSend(entry.emmiter, add, true);
|
||||
entry.capBank.addEnergy((int) add);
|
||||
trackerSend(entry.emmiter, (int) add, true);
|
||||
amount -= add;
|
||||
if(amount == 0) {
|
||||
return;
|
||||
@@ -487,14 +487,14 @@ public class NetworkPowerManager {
|
||||
|
||||
private static class CapBankSupplyEntry {
|
||||
|
||||
final TileCapacitorBank capBank;
|
||||
final IPowerStorage capBank;
|
||||
final int canExtract;
|
||||
final int canFill;
|
||||
int toBalance;
|
||||
IPowerConduit emmiter;
|
||||
ForgeDirection direction;
|
||||
|
||||
private CapBankSupplyEntry(TileCapacitorBank capBank, int available, int canFill, IPowerConduit emmiter, ForgeDirection direction) {
|
||||
private CapBankSupplyEntry(IPowerStorage capBank, int available, int canFill, IPowerConduit emmiter, ForgeDirection direction) {
|
||||
this.capBank = capBank;
|
||||
canExtract = available;
|
||||
this.canFill = canFill;
|
||||
@@ -502,13 +502,13 @@ public class NetworkPowerManager {
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
void calcToBalance(float targetRatio) {
|
||||
int targetAmount = (int) Math.floor(capBank.getMaxEnergyStored() * targetRatio);
|
||||
toBalance = targetAmount - capBank.getEnergyStored();
|
||||
if(toBalance < 0) {
|
||||
toBalance = Math.max(toBalance, -canExtract);
|
||||
void calcToBalance(double targetRatio) {
|
||||
long targetAmount = (long) Math.floor(capBank.getMaxEnergyStoredL() * targetRatio);
|
||||
long b = targetAmount - capBank.getEnergyStoredL();
|
||||
if(b < 0) {
|
||||
toBalance = -canExtract;
|
||||
} else {
|
||||
toBalance = Math.min(toBalance, canFill);
|
||||
toBalance = canFill;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -441,15 +441,15 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
|
||||
if(TooltipAddera.showAdvancedTooltips()) {
|
||||
tooltip.add(String.format("%s : %s%s%sRF/t ", Lang.localize("capbank.maxIO"), format, fmt.format(nw.getMaxIO()), Util.TAB + Util.ALIGNRIGHT));
|
||||
tooltip
|
||||
.add(String.format("%s : %s%s%sRF/t ", Lang.localize("capbank.maxIn"), format, fmt.format(nw.getMaxEnergyRecieved()), Util.TAB + Util.ALIGNRIGHT));
|
||||
.add(String.format("%s : %s%s%sRF/t ", Lang.localize("capbank.maxIn"), format, fmt.format(nw.getMaxInput()), Util.TAB + Util.ALIGNRIGHT));
|
||||
tooltip
|
||||
.add(String.format("%s : %s%s%sRF/t ", Lang.localize("capbank.maxOut"), format, fmt.format(nw.getMaxEnergySent()), Util.TAB + Util.ALIGNRIGHT));
|
||||
.add(String.format("%s : %s%s%sRF/t ", Lang.localize("capbank.maxOut"), format, fmt.format(nw.getMaxOutput()), Util.TAB + Util.ALIGNRIGHT));
|
||||
|
||||
tooltip.add("");
|
||||
}
|
||||
|
||||
long stored = nw.getEnergyStored();
|
||||
long max = nw.getMaxEnergyStored();
|
||||
long stored = nw.getEnergyStoredL();
|
||||
long max = nw.getMaxEnergyStoredL();
|
||||
tooltip.add(String.format("%s%s%s / %s%s%s RF", EnumChatFormatting.WHITE, fmt.format(stored), EnumChatFormatting.RESET, EnumChatFormatting.WHITE,
|
||||
fmt.format(max),
|
||||
EnumChatFormatting.RESET));
|
||||
|
||||
@@ -94,8 +94,8 @@ public class GuiCapBank extends GuiContainerBase {
|
||||
@Override
|
||||
protected void updateText() {
|
||||
text.clear();
|
||||
text.add(PowerDisplayUtil.formatPower(network.getEnergyStored()) + " " + PowerDisplayUtil.ofStr());
|
||||
text.add(EnumChatFormatting.WHITE + PowerDisplayUtil.formatPower(network.getMaxEnergyStored()) + " " + EnumChatFormatting.GRAY
|
||||
text.add(PowerDisplayUtil.formatPower(network.getEnergyStoredL()) + " " + PowerDisplayUtil.ofStr());
|
||||
text.add(EnumChatFormatting.WHITE + PowerDisplayUtil.formatPower(network.getMaxEnergyStoredL()) + " " + EnumChatFormatting.GRAY
|
||||
+ PowerDisplayUtil.abrevation());
|
||||
|
||||
float change = network.getAverageChangePerTick();
|
||||
@@ -234,27 +234,27 @@ public class GuiCapBank extends GuiContainerBase {
|
||||
|
||||
private void updateInputOutput() {
|
||||
int input = parsePower(maxInputTF);
|
||||
if(input >= 0 && network.getMaxEnergyRecieved() != input) {
|
||||
if(input >= 0 && network.getMaxInput() != input) {
|
||||
setMaxInput(input);
|
||||
}
|
||||
int output = parsePower(maxOutputTF);
|
||||
if(output >= 0 && network.getMaxEnergySent() != output) {
|
||||
if(output >= 0 && network.getMaxOutput() != output) {
|
||||
setMaxOutput(output);
|
||||
}
|
||||
}
|
||||
|
||||
private void setMaxOutput(int output) {
|
||||
if(output != network.getMaxEnergySent()) {
|
||||
network.setMaxEnergySend(output);
|
||||
maxOutputTF.setText(PowerDisplayUtil.formatPower(network.getMaxEnergySent()));
|
||||
if(output != network.getMaxOutput()) {
|
||||
network.setMaxOutput(output);
|
||||
maxOutputTF.setText(PowerDisplayUtil.formatPower(network.getMaxOutput()));
|
||||
sendUpdateToServer();
|
||||
}
|
||||
}
|
||||
|
||||
private void setMaxInput(int input) {
|
||||
if(input != network.getMaxEnergyRecieved()) {
|
||||
network.setMaxEnergyReccieved(input);
|
||||
maxInputTF.setText(PowerDisplayUtil.formatPower(network.getMaxEnergyRecieved()));
|
||||
if(input != network.getMaxInput()) {
|
||||
network.setMaxInput(input);
|
||||
maxInputTF.setText(PowerDisplayUtil.formatPower(network.getMaxInput()));
|
||||
sendUpdateToServer();
|
||||
}
|
||||
}
|
||||
@@ -414,8 +414,8 @@ public class GuiCapBank extends GuiContainerBase {
|
||||
}
|
||||
|
||||
private void updateFieldsFromState() {
|
||||
maxInputTF.setText(PowerDisplayUtil.formatPower(network.getMaxEnergyRecieved()));
|
||||
maxOutputTF.setText(PowerDisplayUtil.formatPower(network.getMaxEnergySent()));
|
||||
maxInputTF.setText(PowerDisplayUtil.formatPower(network.getMaxInput()));
|
||||
maxOutputTF.setText(PowerDisplayUtil.formatPower(network.getMaxOutput()));
|
||||
inputRsButton.setMode(network.getInputControlMode());
|
||||
outputRsButton.setMode(network.getOutputControlMode());
|
||||
}
|
||||
|
||||
@@ -34,13 +34,14 @@ import crazypants.enderio.machine.capbank.packet.PacketNetworkIdRequest;
|
||||
import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.power.IInternalPowerReceptor;
|
||||
import crazypants.enderio.power.IPowerInterface;
|
||||
import crazypants.enderio.power.IPowerStorage;
|
||||
import crazypants.enderio.power.PowerHandlerUtil;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.EntityUtil;
|
||||
import crazypants.util.Util;
|
||||
import crazypants.vecmath.Vector3d;
|
||||
|
||||
public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor, IInventory, IIoConfigurable {
|
||||
public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor, IInventory, IIoConfigurable, IPowerStorage {
|
||||
|
||||
private Map<ForgeDirection, IoMode> faceModes;
|
||||
|
||||
@@ -300,6 +301,58 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
|
||||
//----------- Power
|
||||
|
||||
@Override
|
||||
public IPowerStorage getController() {
|
||||
return network;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEnergyStoredL() {
|
||||
if(network == null) {
|
||||
return getEnergyStored();
|
||||
}
|
||||
return network.getEnergyStoredL();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaxEnergyStoredL() {
|
||||
if(network == null) {
|
||||
return getMaxEnergyStored();
|
||||
}
|
||||
return network.getMaxEnergyStoredL();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutputEnabled(ForgeDirection direction) {
|
||||
IoMode mode = getIoMode(direction);
|
||||
return mode == IoMode.PUSH || mode == IoMode.NONE && isOutputEnabled();
|
||||
}
|
||||
|
||||
private boolean isOutputEnabled() {
|
||||
if(network == null) {
|
||||
return true;
|
||||
}
|
||||
return network.isOutputEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInputEnabled(ForgeDirection direction) {
|
||||
IoMode mode = getIoMode(direction);
|
||||
return mode == IoMode.PULL || mode == IoMode.NONE && isInputEnabled();
|
||||
}
|
||||
|
||||
private boolean isInputEnabled() {
|
||||
if(network == null) {
|
||||
return true;
|
||||
}
|
||||
return network.isInputEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCreative() {
|
||||
return getType().isCreative();
|
||||
}
|
||||
|
||||
public List<EnergyReceptor> getReceptors() {
|
||||
if(receptorsDirty) {
|
||||
updateReceptors();
|
||||
@@ -348,6 +401,7 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEnergy(int energy) {
|
||||
if(network == null) {
|
||||
setEnergyStored(getEnergyStored() + energy);
|
||||
@@ -378,35 +432,41 @@ public class TileCapBank extends TileEntityEio implements IInternalPowerReceptor
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyRecieved(ForgeDirection dir) {
|
||||
return getMaxInput();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxInput() {
|
||||
if(network == null) {
|
||||
return getType().getMaxIO();
|
||||
}
|
||||
return network.getMaxEnergyRecieved();
|
||||
return network.getMaxInput();
|
||||
}
|
||||
|
||||
public int getMaxEnergySent() {
|
||||
if(network == null) {
|
||||
return getType().getMaxIO();
|
||||
}
|
||||
return network.getMaxEnergySent();
|
||||
}
|
||||
|
||||
public void setMaxEnergyRecieved(int maxInput) {
|
||||
public void setMaxInput(int maxInput) {
|
||||
this.maxInput = maxInput;
|
||||
}
|
||||
|
||||
public void setMaxEnergySend(int maxOutput) {
|
||||
public int getMaxInputOverride() {
|
||||
return maxInput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxOutput() {
|
||||
if(network == null) {
|
||||
return getType().getMaxIO();
|
||||
}
|
||||
return network.getMaxOutput();
|
||||
}
|
||||
|
||||
public void setMaxOutput(int maxOutput) {
|
||||
this.maxOutput = maxOutput;
|
||||
}
|
||||
|
||||
public int getMaxEnergySentOverride() {
|
||||
public int getMaxOutputOverride() {
|
||||
return maxOutput;
|
||||
}
|
||||
|
||||
public int getMaxEnergyRecievedOverride() {
|
||||
return maxInput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
|
||||
if(network == null) {
|
||||
|
||||
@@ -7,8 +7,10 @@ import java.util.List;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.power.IPowerStorage;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public class CapBankClientNetwork implements ICapBankNetwork {
|
||||
@@ -94,7 +96,7 @@ public class CapBankClientNetwork implements ICapBankNetwork {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaxEnergyStored() {
|
||||
public long getMaxEnergyStoredL() {
|
||||
return maxEnergyStored;
|
||||
}
|
||||
|
||||
@@ -103,35 +105,35 @@ public class CapBankClientNetwork implements ICapBankNetwork {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEnergyStored() {
|
||||
public long getEnergyStoredL() {
|
||||
return energyStored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergySent() {
|
||||
public int getMaxOutput() {
|
||||
return maxEnergySent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxEnergySend(int max) {
|
||||
public void setMaxOutput(int max) {
|
||||
maxEnergySent = MathHelper.clamp_int(max, 0, maxIO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyRecieved() {
|
||||
public int getMaxInput() {
|
||||
return maxEnergyRecieved;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxEnergyReccieved(int max) {
|
||||
public void setMaxInput(int max) {
|
||||
maxEnergyRecieved = MathHelper.clamp_int(max, 0, maxIO);
|
||||
}
|
||||
|
||||
public double getEnergyStoredRatio() {
|
||||
if(getMaxEnergyStored() <= 0) {
|
||||
if(getMaxEnergyStoredL() <= 0) {
|
||||
return 0;
|
||||
}
|
||||
return (double) getEnergyStored() / getMaxEnergyStored();
|
||||
return (double) getEnergyStoredL() / getMaxEnergyStoredL();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -198,4 +200,34 @@ public class CapBankClientNetwork implements ICapBankNetwork {
|
||||
public void updateRedstoneSignal(TileCapBank tileCapBank, boolean recievingSignal) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutputEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInputEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPowerStorage getController() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutputEnabled(ForgeDirection direction) {
|
||||
return isOutputEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInputEnabled(ForgeDirection direction) {
|
||||
return isInputEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCreative() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import java.util.Set;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.ServerTickEvent;
|
||||
import crazypants.enderio.EnderIO;
|
||||
@@ -22,6 +23,7 @@ import crazypants.enderio.machine.capbank.CapBankType;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.machine.capbank.packet.PacketNetworkStateResponse;
|
||||
import crazypants.enderio.power.IPowerInterface;
|
||||
import crazypants.enderio.power.IPowerStorage;
|
||||
import crazypants.enderio.power.PerTickIntAverageCalculator;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.RoundRobinIterator;
|
||||
@@ -62,7 +64,7 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
|
||||
private TickListener tickListener;
|
||||
|
||||
private PerTickIntAverageCalculator powerTracker = new PerTickIntAverageCalculator();
|
||||
private PerTickIntAverageCalculator powerTracker = new PerTickIntAverageCalculator(2);
|
||||
|
||||
private final InventoryImpl inventory = new InventoryImpl();
|
||||
|
||||
@@ -142,10 +144,10 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
energyStored += cap.getEnergyStored();
|
||||
maxEnergyStored += cap.getMaxEnergyStored();
|
||||
if(maxInput == -1) {
|
||||
maxInput = cap.getMaxEnergyRecievedOverride();
|
||||
maxInput = cap.getMaxInputOverride();
|
||||
}
|
||||
if(maxOutput == -1) {
|
||||
maxOutput = cap.getMaxEnergySentOverride();
|
||||
maxOutput = cap.getMaxOutputOverride();
|
||||
}
|
||||
cap.setInputControlMode(inputControlMode);
|
||||
cap.setOutputControlMode(outputControlMode);
|
||||
@@ -226,7 +228,7 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
return;
|
||||
}
|
||||
|
||||
int available = getEnergyAvailableForTick(getMaxEnergySent());
|
||||
int available = getEnergyAvailableForTick(getMaxOutput());
|
||||
if(available <= 0) {
|
||||
return;
|
||||
}
|
||||
@@ -336,7 +338,7 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
spaceAvailable = Integer.MAX_VALUE;
|
||||
}
|
||||
int res = Math.min(maxReceive, (int) spaceAvailable);
|
||||
res = Math.min(maxReceive, getMaxEnergyRecieved());
|
||||
res = Math.min(maxReceive, getMaxInput());
|
||||
if(!simulate) {
|
||||
if(!type.isCreative()) {
|
||||
addEnergy(res);
|
||||
@@ -385,12 +387,12 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEnergyStored() {
|
||||
public long getEnergyStoredL() {
|
||||
return energyStored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaxEnergyStored() {
|
||||
public long getMaxEnergyStoredL() {
|
||||
return maxEnergyStored;
|
||||
}
|
||||
|
||||
@@ -402,7 +404,7 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
//----- IO overrides
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyRecieved() {
|
||||
public int getMaxInput() {
|
||||
if(maxInput == -1) {
|
||||
return maxIO;
|
||||
}
|
||||
@@ -410,7 +412,7 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergySent() {
|
||||
public int getMaxOutput() {
|
||||
if(maxOutput == -1) {
|
||||
return maxIO;
|
||||
}
|
||||
@@ -418,7 +420,7 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxEnergyReccieved(int max) {
|
||||
public void setMaxInput(int max) {
|
||||
if(max >= maxIO) {
|
||||
maxInput = -1;
|
||||
} else if(max < 0) {
|
||||
@@ -427,12 +429,12 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
maxInput = max;
|
||||
}
|
||||
for (TileCapBank cb : capBanks) {
|
||||
cb.setMaxEnergyRecieved(maxInput);
|
||||
cb.setMaxInput(maxInput);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxEnergySend(int max) {
|
||||
public void setMaxOutput(int max) {
|
||||
if(max >= maxIO) {
|
||||
maxOutput = -1;
|
||||
} else if(max < 0) {
|
||||
@@ -441,7 +443,7 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
maxOutput = max;
|
||||
}
|
||||
for (TileCapBank cb : capBanks) {
|
||||
cb.setMaxEnergySend(maxOutput);
|
||||
cb.setMaxOutput(maxOutput);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -493,6 +495,16 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
updateRedstoneConditions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInputEnabled() {
|
||||
return inputRedstoneConditionMet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutputEnabled() {
|
||||
return outputRedstoneConditionMet;
|
||||
}
|
||||
|
||||
private void updateRedstoneConditions() {
|
||||
int powerLevel = redstoneRecievers.isEmpty() ? 0 : 15;
|
||||
inputRedstoneConditionMet = RedstoneControlMode.isConditionMet(inputControlMode, powerLevel);
|
||||
@@ -513,4 +525,24 @@ public class CapBankNetwork implements ICapBankNetwork {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPowerStorage getController() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutputEnabled(ForgeDirection direction) {
|
||||
return isOutputEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInputEnabled(ForgeDirection direction) {
|
||||
return isInputEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCreative() {
|
||||
return type.isCreative();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,8 +5,9 @@ import java.util.List;
|
||||
|
||||
import crazypants.enderio.machine.RedstoneControlMode;
|
||||
import crazypants.enderio.machine.capbank.TileCapBank;
|
||||
import crazypants.enderio.power.IPowerStorage;
|
||||
|
||||
public interface ICapBankNetwork {
|
||||
public interface ICapBankNetwork extends IPowerStorage {
|
||||
|
||||
//------ Network
|
||||
|
||||
@@ -25,23 +26,30 @@ public interface ICapBankNetwork {
|
||||
|
||||
//------ Energy
|
||||
|
||||
long getEnergyStored();
|
||||
@Override
|
||||
long getEnergyStoredL();
|
||||
|
||||
@Override
|
||||
void addEnergy(int energy);
|
||||
|
||||
int recieveEnergy(int maxReceive, boolean simulate);
|
||||
|
||||
long getMaxEnergyStored();
|
||||
@Override
|
||||
long getMaxEnergyStoredL();
|
||||
|
||||
int getMaxIO();
|
||||
|
||||
int getMaxEnergySent();
|
||||
@Override
|
||||
int getMaxOutput();
|
||||
|
||||
void setMaxEnergySend(int max);
|
||||
void setMaxOutput(int max);
|
||||
|
||||
int getMaxEnergyRecieved();
|
||||
@Override
|
||||
int getMaxInput();
|
||||
|
||||
void setMaxEnergyReccieved(int max);
|
||||
void setMaxInput(int max);
|
||||
|
||||
float getAverageChangePerTick();
|
||||
|
||||
void removeReceptors(Collection<EnergyReceptor> receptors);
|
||||
|
||||
@@ -65,7 +73,9 @@ public interface ICapBankNetwork {
|
||||
|
||||
void updateRedstoneSignal(TileCapBank tileCapBank, boolean recievingSignal);
|
||||
|
||||
public abstract float getAverageChangePerTick();
|
||||
boolean isOutputEnabled();
|
||||
|
||||
boolean isInputEnabled();
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -35,11 +35,11 @@ public class NetworkState {
|
||||
}
|
||||
|
||||
public NetworkState(ICapBankNetwork network) {
|
||||
energyStored = network.getEnergyStored();
|
||||
maxEnergyStored = network.getMaxEnergyStored();
|
||||
energyStored = network.getEnergyStoredL();
|
||||
maxEnergyStored = network.getMaxEnergyStoredL();
|
||||
maxIO = network.getMaxIO();
|
||||
maxInput = network.getMaxEnergyRecieved();
|
||||
maxOutput = network.getMaxEnergySent();
|
||||
maxInput = network.getMaxInput();
|
||||
maxOutput = network.getMaxOutput();
|
||||
inputMode = network.getInputControlMode();
|
||||
outputMode = network.getOutputControlMode();
|
||||
TileCapBank cb = network.getInventory().getCapBank();
|
||||
|
||||
@@ -20,8 +20,8 @@ public class PacketGuiChange extends PacketCapBank<PacketGuiChange, IMessage> {
|
||||
public PacketGuiChange(TileCapBank capBank) {
|
||||
super(capBank);
|
||||
ICapBankNetwork network = capBank.getNetwork();
|
||||
maxSend = network.getMaxEnergySent();
|
||||
maxRec = network.getMaxEnergyRecieved();
|
||||
maxSend = network.getMaxOutput();
|
||||
maxRec = network.getMaxInput();
|
||||
inputMode = network.getInputControlMode();
|
||||
outputMode = network.getOutputControlMode();
|
||||
}
|
||||
@@ -50,8 +50,8 @@ public class PacketGuiChange extends PacketCapBank<PacketGuiChange, IMessage> {
|
||||
if(net == null) {
|
||||
return null;
|
||||
}
|
||||
net.setMaxEnergySend(message.maxSend);
|
||||
net.setMaxEnergyReccieved(message.maxRec);
|
||||
net.setMaxOutput(message.maxSend);
|
||||
net.setMaxInput(message.maxRec);
|
||||
net.setInputControlMode(message.inputMode);
|
||||
net.setOutputControlMode(message.outputMode);
|
||||
return null;
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ public class PacketNetworkEnergyResponse implements IMessage, IMessageHandler<Pa
|
||||
|
||||
public PacketNetworkEnergyResponse(ICapBankNetwork network) {
|
||||
id = network.getId();
|
||||
energyStored = network.getEnergyStored();
|
||||
energyStored = network.getEnergyStoredL();
|
||||
avChange = network.getAverageChangePerTick();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ public class TilePowerMonitor extends AbstractMachineEntity implements IInternal
|
||||
|
||||
int powerInConduits;
|
||||
int maxPowerInCoduits;
|
||||
int powerInCapBanks;
|
||||
int maxPowerInCapBanks;
|
||||
long powerInCapBanks;
|
||||
long maxPowerInCapBanks;
|
||||
int powerInMachines;
|
||||
int maxPowerInMachines;
|
||||
float aveRfSent;
|
||||
@@ -216,8 +216,13 @@ public class TilePowerMonitor extends AbstractMachineEntity implements IInternal
|
||||
public void readPowerInfoFromNBT(NBTTagCompound nbtRoot) {
|
||||
powerInConduits = nbtRoot.getInteger("powerInConduits");
|
||||
maxPowerInCoduits = nbtRoot.getInteger("maxPowerInCoduits");
|
||||
powerInCapBanks = nbtRoot.getInteger("powerInCapBanks");
|
||||
maxPowerInCapBanks = nbtRoot.getInteger("maxPowerInCapBanks");
|
||||
if(nbtRoot.hasKey("powerInCapBanks")) {
|
||||
powerInCapBanks = nbtRoot.getInteger("powerInCapBanks");
|
||||
maxPowerInCapBanks = nbtRoot.getInteger("maxPowerInCapBanks");
|
||||
} else {
|
||||
powerInCapBanks = nbtRoot.getLong("powerInCapBanksL");
|
||||
maxPowerInCapBanks = nbtRoot.getLong("maxPowerInCapBanksL");
|
||||
}
|
||||
powerInMachines = nbtRoot.getInteger("powerInMachines");
|
||||
maxPowerInMachines = nbtRoot.getInteger("maxPowerInMachines");
|
||||
aveRfSent = nbtRoot.getFloat("aveRfSent");
|
||||
@@ -237,8 +242,8 @@ public class TilePowerMonitor extends AbstractMachineEntity implements IInternal
|
||||
public void writePowerInfoToNBT(NBTTagCompound nbtRoot) {
|
||||
nbtRoot.setInteger("powerInConduits", powerInConduits);
|
||||
nbtRoot.setInteger("maxPowerInCoduits", maxPowerInCoduits);
|
||||
nbtRoot.setInteger("powerInCapBanks", powerInCapBanks);
|
||||
nbtRoot.setInteger("maxPowerInCapBanks", maxPowerInCapBanks);
|
||||
nbtRoot.setLong("powerInCapBanksL", powerInCapBanks);
|
||||
nbtRoot.setLong("maxPowerInCapBanksL", maxPowerInCapBanks);
|
||||
nbtRoot.setInteger("powerInMachines", powerInMachines);
|
||||
nbtRoot.setInteger("maxPowerInMachines", maxPowerInMachines);
|
||||
nbtRoot.setFloat("aveRfSent", aveRfSent);
|
||||
|
||||
@@ -30,12 +30,13 @@ import crazypants.enderio.network.PacketHandler;
|
||||
import crazypants.enderio.power.BasicCapacitor;
|
||||
import crazypants.enderio.power.IInternalPowerReceptor;
|
||||
import crazypants.enderio.power.IPowerInterface;
|
||||
import crazypants.enderio.power.IPowerStorage;
|
||||
import crazypants.enderio.power.PowerHandlerUtil;
|
||||
import crazypants.util.BlockCoord;
|
||||
import crazypants.util.Util;
|
||||
import crazypants.vecmath.VecmathUtil;
|
||||
|
||||
public class TileCapacitorBank extends TileEntityEio implements IInternalPowerReceptor, IInventory, IIoConfigurable {
|
||||
public class TileCapacitorBank extends TileEntityEio implements IInternalPowerReceptor, IInventory, IIoConfigurable, IPowerStorage {
|
||||
|
||||
static final BasicCapacitor BASE_CAP = new BasicCapacitor(Config.capacitorBankMaxIoRF, Config.capacitorBankMaxStorageRF);
|
||||
|
||||
@@ -285,7 +286,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
int cur = chargable.getEnergyStored(item);
|
||||
int canUse = Math.min(available, max - cur);
|
||||
if(cur < max) {
|
||||
used = chargable.receiveEnergy(item, (int) canUse, false);
|
||||
used = chargable.receiveEnergy(item, canUse, false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -310,6 +311,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
return getController().outputEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOutputEnabled(ForgeDirection direction) {
|
||||
IoMode mode = getIoMode(direction);
|
||||
return mode == IoMode.PUSH || mode == IoMode.NONE && isOutputEnabled();
|
||||
@@ -319,6 +321,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
return getController().inputEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInputEnabled(ForgeDirection direction) {
|
||||
IoMode mode = getIoMode(direction);
|
||||
return mode == IoMode.PULL || mode == IoMode.NONE && isInputEnabled();
|
||||
@@ -454,6 +457,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
return getController().doGetEnergyStoredScaled(scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxInput() {
|
||||
return maxInput;
|
||||
}
|
||||
@@ -463,6 +467,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
updateBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxOutput() {
|
||||
return maxOutput;
|
||||
}
|
||||
@@ -477,6 +482,11 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
return getController().doGetEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEnergyStoredL() {
|
||||
return getEnergyStored();
|
||||
}
|
||||
|
||||
public double getEnergyStoredRatio() {
|
||||
return getController().doGetEnergyStoredRatio();
|
||||
}
|
||||
@@ -486,6 +496,11 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
return getController().doGetMaxEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaxEnergyStoredL() {
|
||||
return getMaxEnergyStored();
|
||||
}
|
||||
|
||||
public int getMaxIO() {
|
||||
return getController().doGetMaxIO();
|
||||
}
|
||||
@@ -545,6 +560,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
|
||||
// end rf power
|
||||
|
||||
@Override
|
||||
public void addEnergy(int add) {
|
||||
getController().doAddEnergy(add);
|
||||
}
|
||||
@@ -824,6 +840,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
render = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileCapacitorBank getController() {
|
||||
if(isMaster() || !isMultiblock()) {
|
||||
return this;
|
||||
@@ -983,7 +1000,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
doSetEnergyStored(nbtRoot.getInteger("storedEnergyRF"));
|
||||
|
||||
double newEnergy = storedEnergyRF;
|
||||
if(maxStoredEnergy != 0 && Math.abs(oldEnergy - newEnergy) / (double) maxStoredEnergy > 0.05 || nbtRoot.hasKey("render")) {
|
||||
if(maxStoredEnergy != 0 && Math.abs(oldEnergy - newEnergy) / maxStoredEnergy > 0.05 || nbtRoot.hasKey("render")) {
|
||||
render = true;
|
||||
}
|
||||
if(energyAtLastRender != -1 && maxStoredEnergy != 0) {
|
||||
@@ -1110,7 +1127,7 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
IoMode mode;
|
||||
|
||||
private Receptor(IPowerInterface rec, ForgeDirection fromDir, IoMode mode) {
|
||||
this.receptor = rec;
|
||||
receptor = rec;
|
||||
this.fromDir = fromDir;
|
||||
this.mode = mode;
|
||||
}
|
||||
@@ -1129,12 +1146,13 @@ public class TileCapacitorBank extends TileEntityEio implements IInternalPowerRe
|
||||
}
|
||||
|
||||
public void setCreativeMode() {
|
||||
this.isCreative = true;
|
||||
isCreative = true;
|
||||
maxIO = maxIO * 1000;
|
||||
maxInput = maxIO;
|
||||
maxOutput = maxIO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCreative() {
|
||||
return isCreative;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package crazypants.enderio.power;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public interface IPowerStorage {
|
||||
|
||||
IPowerStorage getController();
|
||||
|
||||
long getEnergyStoredL();
|
||||
|
||||
long getMaxEnergyStoredL();
|
||||
|
||||
boolean isOutputEnabled(ForgeDirection direction);
|
||||
|
||||
boolean isInputEnabled(ForgeDirection direction);
|
||||
|
||||
int getMaxOutput();
|
||||
|
||||
int getMaxInput();
|
||||
|
||||
void addEnergy(int amount);
|
||||
|
||||
boolean isCreative();
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user