mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
We must construct additional pylons!!
This commit is contained in:
parent
9c7a96d867
commit
be3147c80d
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
@ -123,14 +124,20 @@ public class PowerNetMK2 {
|
||||
long supply = 0;
|
||||
long demand = 0;
|
||||
|
||||
for(Entry<IEnergyProviderMK2, Long> entry : providerEntries.entrySet()) {
|
||||
IEnergyProviderMK2 provider = entry.getKey();
|
||||
if(provider.isLoaded() && timestamp - entry.getValue() < timeout) supply += Math.min(provider.getPower(), provider.getProviderSpeed());
|
||||
Iterator<Entry<IEnergyProviderMK2, Long>> provIt = providerEntries.entrySet().iterator();
|
||||
while(provIt.hasNext()) {
|
||||
Entry<IEnergyProviderMK2, Long> entry = provIt.next();
|
||||
if(timestamp - entry.getValue() > timeout) provIt.remove();
|
||||
supply += Math.min(entry.getKey().getPower(), entry.getKey().getProviderSpeed());
|
||||
}
|
||||
|
||||
for(Entry<IEnergyReceiverMK2, Long> entry : receiverEntries.entrySet()) {
|
||||
IEnergyReceiverMK2 receiver = entry.getKey();
|
||||
if(receiver.isLoaded() && timestamp - entry.getValue() < timeout) demand += Math.min(receiver.getMaxPower() - receiver.getPower(), receiver.getReceiverSpeed());
|
||||
if(supply <= 0) return;
|
||||
|
||||
Iterator<Entry<IEnergyReceiverMK2, Long>> recIt = receiverEntries.entrySet().iterator();
|
||||
while(recIt.hasNext()) {
|
||||
Entry<IEnergyReceiverMK2, Long> entry = recIt.next();
|
||||
if(timestamp - entry.getValue() > timeout) recIt.remove();
|
||||
demand += Math.min(entry.getKey().getMaxPower() - entry.getKey().getPower(), entry.getKey().getReceiverSpeed());
|
||||
}
|
||||
|
||||
double drainScale = 1D;
|
||||
@ -158,9 +165,13 @@ public class PowerNetMK2 {
|
||||
|
||||
IEnergyProviderMK2 src = providers.get(0);
|
||||
IEnergyReceiverMK2 dest = receivers.get(0);
|
||||
|
||||
long receiverShare = Math.min((long) ((double) (dest.getMaxPower() - dest.getPower()) * (double) supply / (double) demand), dest.getReceiverSpeed()) - prevDest;
|
||||
long providerShare = Math.min((long) ((double) src.getPower() * (double) demand / (double) supply), src.getProviderSpeed()) - prevSrc;
|
||||
|
||||
long toDrain = Math.min((long) (src.getPower() * drainScale), providerShare);
|
||||
long toFill = Math.min(dest.getMaxPower() - dest.getPower(), receiverShare);
|
||||
|
||||
long toDrain = Math.min((long) (src.getPower() * drainScale) + prevSrc, src.getProviderSpeed()) - prevSrc;
|
||||
long toFill = Math.min(dest.getMaxPower() - dest.getPower() + prevDest, dest.getReceiverSpeed()) - prevDest;
|
||||
long finalTransfer = Math.min(toDrain, toFill);
|
||||
|
||||
if(toDrain <= 0) { providers.remove(0); prevSrc = 0; continue; }
|
||||
|
||||
@ -150,7 +150,6 @@ public class MachineCapacitor extends BlockContainer implements ILookOverlay, IP
|
||||
|
||||
public long power;
|
||||
protected long maxPower;
|
||||
public long prevPower;
|
||||
public long powerReceived;
|
||||
public long powerSent;
|
||||
|
||||
@ -165,8 +164,6 @@ public class MachineCapacitor extends BlockContainer implements ILookOverlay, IP
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
long gain = power - prevPower;
|
||||
|
||||
ForgeDirection opp = ForgeDirection.getOrientation(this.getBlockMetadata());
|
||||
ForgeDirection dir = opp.getOpposite();
|
||||
|
||||
@ -188,26 +185,45 @@ public class MachineCapacitor extends BlockContainer implements ILookOverlay, IP
|
||||
pos = pos.offset(current);
|
||||
}
|
||||
|
||||
long preSend = power;
|
||||
if(pos != null && last != null) {
|
||||
this.tryUnsubscribe(worldObj, pos.getX(), pos.getY(), pos.getZ());
|
||||
this.tryProvide(worldObj, pos.getX(), pos.getY(), pos.getZ(), last);
|
||||
}
|
||||
long sent = preSend - power;
|
||||
|
||||
this.trySubscribe(worldObj, xCoord + opp.offsetX, yCoord+ opp.offsetY, zCoord + opp.offsetZ, opp);
|
||||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setLong("power", power);
|
||||
data.setLong("maxPower", maxPower);
|
||||
data.setLong("rec", gain);
|
||||
data.setLong("sent", sent);
|
||||
data.setLong("rec", powerReceived);
|
||||
data.setLong("sent", powerSent);
|
||||
INBTPacketReceiver.networkPack(this, data, 15);
|
||||
|
||||
this.prevPower = power;
|
||||
this.powerSent = 0;
|
||||
this.powerReceived = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long transferPower(long power) {
|
||||
if(power + this.getPower() <= this.getMaxPower()) {
|
||||
this.setPower(power + this.getPower());
|
||||
this.powerReceived += power;
|
||||
return 0;
|
||||
}
|
||||
long capacity = this.getMaxPower() - this.getPower();
|
||||
long overshoot = power - capacity;
|
||||
this.powerReceived += (this.getMaxPower() - this.getPower());
|
||||
this.setPower(this.getMaxPower());
|
||||
return overshoot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void usePower(long power) {
|
||||
this.powerSent += Math.min(this.getPower(), power);
|
||||
this.setPower(this.getPower() - power);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void networkUnpack(NBTTagCompound nbt) {
|
||||
this.power = nbt.getLong("power");
|
||||
|
||||
@ -29,7 +29,9 @@ public class TileEntityConnector extends TileEntityPylonBase {
|
||||
public PowerNode createNode() {
|
||||
TileEntity tile = (TileEntity) this;
|
||||
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata()).getOpposite();
|
||||
PowerNode node = new PowerNode(new BlockPos(tile.xCoord, tile.yCoord, tile.zCoord)).setConnections(new DirPos(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir));
|
||||
PowerNode node = new PowerNode(new BlockPos(tile.xCoord, tile.yCoord, tile.zCoord)).setConnections(
|
||||
new DirPos(xCoord, yCoord, zCoord, ForgeDirection.UNKNOWN),
|
||||
new DirPos(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, dir));
|
||||
for(int[] pos : this.connected) node.addConnection(new DirPos(pos[0], pos[1], pos[2], ForgeDirection.UNKNOWN));
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -30,6 +30,7 @@ public class TileEntityPylon extends TileEntityPylonBase {
|
||||
public PowerNode createNode() {
|
||||
TileEntity tile = (TileEntity) this;
|
||||
PowerNode node = new PowerNode(new BlockPos(tile.xCoord, tile.yCoord, tile.zCoord)).setConnections(
|
||||
new DirPos(xCoord, yCoord, zCoord, ForgeDirection.UNKNOWN),
|
||||
new DirPos(xCoord + 1, yCoord, zCoord, Library.POS_X),
|
||||
new DirPos(xCoord - 1, yCoord, zCoord, Library.NEG_X),
|
||||
new DirPos(xCoord, yCoord + 1, zCoord, Library.POS_Y),
|
||||
|
||||
@ -49,7 +49,7 @@ public abstract class TileEntityPylonBase extends TileEntityCableBaseNT {
|
||||
@Override
|
||||
public PowerNode createNode() {
|
||||
TileEntity tile = (TileEntity) this;
|
||||
PowerNode node = new PowerNode(new BlockPos(tile.xCoord, tile.yCoord, tile.zCoord));
|
||||
PowerNode node = new PowerNode(new BlockPos(tile.xCoord, tile.yCoord, tile.zCoord)).setConnections(new DirPos(xCoord, yCoord, zCoord, ForgeDirection.UNKNOWN));
|
||||
for(int[] pos : this.connected) node.addConnection(new DirPos(pos[0], pos[1], pos[2], ForgeDirection.UNKNOWN));
|
||||
return node;
|
||||
}
|
||||
@ -81,6 +81,7 @@ public abstract class TileEntityPylonBase extends TileEntityCableBaseNT {
|
||||
|
||||
if(te instanceof TileEntityPylonBase) {
|
||||
TileEntityPylonBase pylon = (TileEntityPylonBase) te;
|
||||
Nodespace.destroyNode(worldObj, pos[0], pos[1], pos[2]);
|
||||
|
||||
for(int i = 0; i < pylon.connected.size(); i++) {
|
||||
int[] conPos = pylon.connected.get(i);
|
||||
|
||||
@ -52,6 +52,7 @@ public class TileEntitySubstation extends TileEntityPylonBase {
|
||||
public PowerNode createNode() {
|
||||
TileEntity tile = (TileEntity) this;
|
||||
PowerNode node = new PowerNode(new BlockPos(tile.xCoord, tile.yCoord, tile.zCoord)).setConnections(
|
||||
new DirPos(xCoord, yCoord, zCoord, ForgeDirection.UNKNOWN),
|
||||
new DirPos(xCoord + 2, yCoord, zCoord - 1, Library.POS_X),
|
||||
new DirPos(xCoord + 2, yCoord, zCoord + 1, Library.POS_X),
|
||||
new DirPos(xCoord - 2, yCoord, zCoord - 1, Library.NEG_X),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user