power net tracker, fensu fix, dueterium tower rebalance

This commit is contained in:
Boblet 2023-05-11 16:55:07 +02:00
parent 3a4bf04aec
commit a397490424
7 changed files with 57 additions and 151 deletions

View File

@ -1,5 +1,6 @@
package api.hbm.energy; package api.hbm.energy;
import java.math.BigInteger;
import java.util.List; import java.util.List;
/** /**
@ -32,4 +33,5 @@ public interface IPowerNet {
public List<IEnergyConnector> getSubscribers(); public List<IEnergyConnector> getSubscribers();
public long transferPower(long power); public long transferPower(long power);
public BigInteger getTotalTransfer();
} }

View File

@ -1,5 +1,6 @@
package api.hbm.energy; package api.hbm.energy;
import java.math.BigInteger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -20,6 +21,9 @@ public class PowerNet implements IPowerNet {
private HashMap<Integer, IEnergyConductor> links = new HashMap(); private HashMap<Integer, IEnergyConductor> links = new HashMap();
private HashMap<Integer, Integer> proxies = new HashMap(); private HashMap<Integer, Integer> proxies = new HashMap();
private List<IEnergyConnector> subscribers = new ArrayList(); private List<IEnergyConnector> subscribers = new ArrayList();
public static List<PowerNet> trackingInstances = null;
protected BigInteger totalTransfer = BigInteger.ZERO;
@Override @Override
public void joinNetworks(IPowerNet network) { public void joinNetworks(IPowerNet network) {
@ -119,6 +123,11 @@ public class PowerNet implements IPowerNet {
public boolean isValid() { public boolean isValid() {
return this.valid; return this.valid;
} }
@Override
public BigInteger getTotalTransfer() {
return this.totalTransfer;
}
public long lastCleanup = System.currentTimeMillis(); public long lastCleanup = System.currentTimeMillis();
@ -129,7 +138,9 @@ public class PowerNet implements IPowerNet {
cleanup(this.subscribers); cleanup(this.subscribers);
lastCleanup = System.currentTimeMillis(); lastCleanup = System.currentTimeMillis();
}*/ }*/
trackingInstances = new ArrayList();
trackingInstances.add(this);
return fairTransfer(this.subscribers, power); return fairTransfer(this.subscribers, power);
} }
@ -149,6 +160,8 @@ public class PowerNet implements IPowerNet {
ConnectionPriority[] priorities = new ConnectionPriority[] {ConnectionPriority.HIGH, ConnectionPriority.NORMAL, ConnectionPriority.LOW}; ConnectionPriority[] priorities = new ConnectionPriority[] {ConnectionPriority.HIGH, ConnectionPriority.NORMAL, ConnectionPriority.LOW};
long totalTransfer = 0;
for(ConnectionPriority p : priorities) { for(ConnectionPriority p : priorities) {
List<IEnergyConnector> subList = new ArrayList(); List<IEnergyConnector> subList = new ArrayList();
@ -186,6 +199,15 @@ public class PowerNet implements IPowerNet {
} }
power -= totalGiven; power -= totalGiven;
totalTransfer += totalGiven;
}
if(trackingInstances != null) {
for(int i = 0; i < trackingInstances.size(); i++) {
PowerNet net = trackingInstances.get(i);
net.totalTransfer = net.totalTransfer.add(BigInteger.valueOf(totalTransfer));
}
} }
return power; return power;

View File

@ -165,6 +165,7 @@ public class HbmChestContents {
public static WeightedRandomChestContent[] nuclear = new WeightedRandomChestContent[] { public static WeightedRandomChestContent[] nuclear = new WeightedRandomChestContent[] {
new WeightedRandomChestContent(ModItems.nugget_u235, 0, 3, 12, 5), new WeightedRandomChestContent(ModItems.nugget_u235, 0, 3, 12, 5),
new WeightedRandomChestContent(ModItems.nugget_pu238, 0, 3, 12, 5), new WeightedRandomChestContent(ModItems.nugget_pu238, 0, 3, 12, 5),
new WeightedRandomChestContent(ModItems.nugget_ra226, 0, 3, 6, 5),
new WeightedRandomChestContent(ModItems.rod, BreedingRodType.U235.ordinal(), 1, 1, 3), new WeightedRandomChestContent(ModItems.rod, BreedingRodType.U235.ordinal(), 1, 1, 3),
new WeightedRandomChestContent(ModItems.rod_dual, BreedingRodType.U235.ordinal(), 1, 1, 3), new WeightedRandomChestContent(ModItems.rod_dual, BreedingRodType.U235.ordinal(), 1, 1, 3),
new WeightedRandomChestContent(ModItems.rod_quad, BreedingRodType.U235.ordinal(), 1, 1, 3), new WeightedRandomChestContent(ModItems.rod_quad, BreedingRodType.U235.ordinal(), 1, 1, 3),

View File

@ -1,14 +1,7 @@
package com.hbm.tileentity.machine; package com.hbm.tileentity.machine;
import java.util.ArrayList;
import java.util.List;
import com.hbm.interfaces.IFluidAcceptor;
import com.hbm.interfaces.IFluidSource;
import com.hbm.inventory.fluid.FluidType;
import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.tank.FluidTank;
import com.hbm.lib.Library;
import com.hbm.tileentity.TileEntityMachineBase; import com.hbm.tileentity.TileEntityMachineBase;
import api.hbm.energy.IEnergyUser; import api.hbm.energy.IEnergyUser;
@ -16,17 +9,16 @@ import api.hbm.fluid.IFluidStandardTransceiver;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityDeuteriumExtractor extends TileEntityMachineBase implements IFluidAcceptor, IFluidSource, IEnergyUser, IFluidStandardTransceiver { public class TileEntityDeuteriumExtractor extends TileEntityMachineBase implements IEnergyUser, IFluidStandardTransceiver {
public long power = 0; public long power = 0;
public FluidTank[] tanks; public FluidTank[] tanks;
public List<IFluidAcceptor> list = new ArrayList();
public TileEntityDeuteriumExtractor() { public TileEntityDeuteriumExtractor() {
super(0); super(0);
tanks = new FluidTank[2]; tanks = new FluidTank[2];
tanks[0] = new FluidTank(Fluids.WATER, 1000, 0); tanks[0] = new FluidTank(Fluids.WATER, 1000);
tanks[1] = new FluidTank(Fluids.HEAVYWATER, 100, 1); tanks[1] = new FluidTank(Fluids.HEAVYWATER, 100);
} }
@Override @Override
@ -52,7 +44,6 @@ public class TileEntityDeuteriumExtractor extends TileEntityMachineBase implemen
this.subscribeToAllAround(tanks[0].getTankType(), this); this.subscribeToAllAround(tanks[0].getTankType(), this);
this.sendFluidToAll(tanks[1].getTankType(), this); this.sendFluidToAll(tanks[1].getTankType(), this);
fillFluidInit(tanks[1].getTankType());
NBTTagCompound data = new NBTTagCompound(); NBTTagCompound data = new NBTTagCompound();
data.setLong("power", power); data.setLong("power", power);
@ -99,66 +90,6 @@ public class TileEntityDeuteriumExtractor extends TileEntityMachineBase implemen
tanks[1].writeToNBT(nbt, "heavyWater"); tanks[1].writeToNBT(nbt, "heavyWater");
} }
@Override
public void fillFluidInit(FluidType type) {
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
fillFluid(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ, getTact(), type);
}
@Override
public void fillFluid(int x, int y, int z, boolean newTact, FluidType type) {
Library.transmitFluid(x, y, z, newTact, this, worldObj, type);
}
@Override
public boolean getTact() {
return worldObj.getTotalWorldTime() % 20 < 10;
}
@Override
public void setFluidFill(int i, FluidType type) {
if(type == tanks[0].getTankType())
tanks[0].setFill(i);
else if(type == tanks[1].getTankType())
tanks[1].setFill(i);
}
@Override
public int getFluidFill(FluidType type) {
if(type == tanks[0].getTankType())
return tanks[0].getFill();
else if(type == tanks[1].getTankType())
return tanks[1].getFill();
return 0;
}
@Override
public int getMaxFluidFill(FluidType type) {
if(type == tanks[0].getTankType())
return tanks[0].getMaxFill();
return 0;
}
@Override
public void setFillForSync(int fill, int index) { }
@Override
public void setTypeForSync(FluidType type, int index) { }
@Override
public List<IFluidAcceptor> getFluidList(FluidType type) {
return list;
}
@Override
public void clearFluidList(FluidType type) {
list.clear();
}
@Override @Override
public void setPower(long i) { public void setPower(long i) {
power = i; power = i;
@ -171,7 +102,7 @@ public class TileEntityDeuteriumExtractor extends TileEntityMachineBase implemen
@Override @Override
public long getMaxPower() { public long getMaxPower() {
return 100000; return 10_000;
} }
@Override @Override

View File

@ -20,56 +20,6 @@ public class TileEntityDeuteriumTower extends TileEntityDeuteriumExtractor {
tanks[0] = new FluidTank(Fluids.WATER, 50000, 0); tanks[0] = new FluidTank(Fluids.WATER, 50000, 0);
tanks[1] = new FluidTank(Fluids.HEAVYWATER, 5000, 1); tanks[1] = new FluidTank(Fluids.HEAVYWATER, 5000, 1);
} }
public void fillFluidInit(FluidType type) {
int offsetX = 0;
int offsetZ = 0;
ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - BlockDummyable.offset);
ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN);
offsetX = -dir.offsetX;
offsetZ = -rot.offsetZ;
if(dir == ForgeDirection.NORTH || dir == ForgeDirection.SOUTH) {
offsetX = rot.offsetX;
offsetZ = dir.offsetZ;
}
/*fillFluid(this.xCoord + rot.offsetX * 2, this.yCoord, this.zCoord - dir.offsetZ * 1, getTact(), type);
fillFluid(this.xCoord + rot.offsetX * 2, this.yCoord, this.zCoord - dir.offsetZ * 0, getTact(), type);
fillFluid(this.xCoord + rot.offsetX * 1, this.yCoord, this.zCoord - dir.offsetZ * 2, getTact(), type);
fillFluid(this.xCoord + rot.offsetX * 0, this.yCoord, this.zCoord - dir.offsetZ * 2, getTact(), type);
fillFluid(this.xCoord + rot.offsetX * 1, this.yCoord, this.zCoord + dir.offsetZ * 1, getTact(), type);
fillFluid(this.xCoord + rot.offsetX * 0, this.yCoord, this.zCoord + dir.offsetZ * 1, getTact(), type);
fillFluid(this.xCoord - rot.offsetX * 1, this.yCoord, this.zCoord + dir.offsetZ * 0, getTact(), type);
fillFluid(this.xCoord - rot.offsetX * 1, this.yCoord, this.zCoord - dir.offsetZ * 1, getTact(), type);*/
/*worldObj.setBlock(this.xCoord + rot.offsetX * 2, this.yCoord, this.zCoord - dir.offsetZ * 1, Blocks.dirt);
worldObj.setBlock(this.xCoord + rot.offsetX * 2, this.yCoord, this.zCoord - dir.offsetZ * 0, Blocks.dirt);
worldObj.setBlock(this.xCoord + rot.offsetX * 1, this.yCoord, this.zCoord - dir.offsetZ * 2, Blocks.dirt);
worldObj.setBlock(this.xCoord + rot.offsetX * 0, this.yCoord, this.zCoord - dir.offsetZ * 2, Blocks.dirt);
worldObj.setBlock(this.xCoord + rot.offsetX * 1, this.yCoord, this.zCoord + dir.offsetZ * 1, Blocks.dirt);
worldObj.setBlock(this.xCoord + rot.offsetX * 0, this.yCoord, this.zCoord + dir.offsetZ * 1, Blocks.dirt);
worldObj.setBlock(this.xCoord - rot.offsetX * 1, this.yCoord, this.zCoord + dir.offsetZ * 0, Blocks.dirt);
worldObj.setBlock(this.xCoord - rot.offsetX * 1, this.yCoord, this.zCoord - dir.offsetZ * 1, Blocks.dirt);*/
/* I'm never doing an even sided fluid machine ever again
*
* this was pain
*
* - pheo */
fillFluid(this.xCoord + offsetX * 2, this.yCoord, this.zCoord - offsetZ * 1, getTact(), type);
fillFluid(this.xCoord + offsetX * 2, this.yCoord, this.zCoord - offsetZ * 0, getTact(), type);
fillFluid(this.xCoord + offsetX * 1, this.yCoord, this.zCoord - offsetZ * 2, getTact(), type);
fillFluid(this.xCoord + offsetX * 0, this.yCoord, this.zCoord - offsetZ * 2, getTact(), type);
fillFluid(this.xCoord + offsetX * 1, this.yCoord, this.zCoord + offsetZ * 1, getTact(), type);
fillFluid(this.xCoord + offsetX * 0, this.yCoord, this.zCoord + offsetZ * 1, getTact(), type);
fillFluid(this.xCoord - offsetX * 1, this.yCoord, this.zCoord + offsetZ * 0, getTact(), type);
fillFluid(this.xCoord - offsetX * 1, this.yCoord, this.zCoord - offsetZ * 1, getTact(), type);
}
protected void updateConnections() { protected void updateConnections() {
@ -139,6 +89,6 @@ public class TileEntityDeuteriumTower extends TileEntityDeuteriumExtractor {
@Override @Override
public long getMaxPower() { public long getMaxPower() {
return 1000000; return 100_000;
} }
} }

View File

@ -227,6 +227,16 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
if(this.power > 0 && (mode == mode_buffer || mode == mode_output)) { if(this.power > 0 && (mode == mode_buffer || mode == mode_output)) {
List<IEnergyConnector> con = new ArrayList(); List<IEnergyConnector> con = new ArrayList();
con.addAll(consumers); con.addAll(consumers);
if(PowerNet.trackingInstances == null) {
PowerNet.trackingInstances = new ArrayList();
}
PowerNet.trackingInstances.clear();
nets.forEach(x -> {
if(x instanceof PowerNet) PowerNet.trackingInstances.add((PowerNet) x);
});
this.power = PowerNet.fairTransfer(con, this.power); this.power = PowerNet.fairTransfer(con, this.power);
} }
@ -256,9 +266,17 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
if(mode == mode_buffer || mode == mode_output) { if(mode == mode_buffer || mode == mode_output) {
if(te instanceof IEnergyConnector) { if(te instanceof IEnergyConnector) {
IEnergyConnector con = (IEnergyConnector) te; IEnergyConnector con = (IEnergyConnector) te;
long max = getMaxTransfer();
long toTransfer = Math.min(max, this.power);
long remainder = this.power - toTransfer;
this.power = toTransfer;
long oldPower = this.power; long oldPower = this.power;
long transfer = this.power - con.transferPower(this.power); long transfer = this.power - con.transferPower(this.power);
this.power = oldPower - transfer; this.power = oldPower - transfer;
power += remainder;
} }
} }
@ -278,6 +296,10 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
} }
} }
} }
public long getMaxTransfer() {
return this.getMaxPower();
}
@Override @Override
public void networkUnpack(NBTTagCompound nbt) { public void networkUnpack(NBTTagCompound nbt) {

View File

@ -1,12 +1,9 @@
package com.hbm.tileentity.machine.storage; package com.hbm.tileentity.machine.storage;
import com.hbm.lib.Library;
import api.hbm.energy.IEnergyConductor; import api.hbm.energy.IEnergyConductor;
import api.hbm.energy.IEnergyConnector; import api.hbm.energy.IEnergyConnector;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
@ -20,21 +17,9 @@ public class TileEntityMachineFENSU extends TileEntityMachineBattery {
@Override @Override
public void updateEntity() { public void updateEntity() {
super.updateEntity();
if(!worldObj.isRemote) { if(worldObj.isRemote) {
this.transmitPower();
power = Library.chargeTEFromItems(slots, 0, power, getMaxPower());
power = Library.chargeItemsFromTE(slots, 1, power, getMaxPower());
NBTTagCompound nbt = new NBTTagCompound();
nbt.setLong("power", power);
nbt.setShort("redLow", redLow);
nbt.setShort("redHigh", redHigh);
nbt.setByte("priority", (byte) this.priority.ordinal());
this.networkPack(nbt, 250);
} else {
this.prevRotation = this.rotation; this.prevRotation = this.rotation;
this.rotation += this.getSpeed(); this.rotation += this.getSpeed();
@ -42,16 +27,10 @@ public class TileEntityMachineFENSU extends TileEntityMachineBattery {
rotation -= 360; rotation -= 360;
prevRotation -= 360; prevRotation -= 360;
} }
for(int i = 1; i < this.log.length; i++) {
this.log[i - 1] = this.log[i];
}
this.log[19] = this.power;
} }
} }
protected void transmitPower() { @Deprecated protected void transmitPower() {
short mode = (short) this.getRelevantMode(); short mode = (short) this.getRelevantMode();
@ -127,8 +106,7 @@ public class TileEntityMachineFENSU extends TileEntityMachineBattery {
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared() public double getMaxRenderDistanceSquared() {
{
return 65536.0D; return 65536.0D;
} }
} }