mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
FEnSU fix, power priorisation
This commit is contained in:
parent
4537a6e214
commit
10c9f7a121
@ -107,4 +107,14 @@ public interface IEnergyConnector extends ILoadedTile {
|
||||
Vec3 vec = Vec3.createVectorHelper(te.xCoord + 0.5, te.yCoord + 1, te.zCoord + 0.5);
|
||||
return vec;
|
||||
}
|
||||
|
||||
public default ConnectionPriority getPriority() {
|
||||
return ConnectionPriority.NORMAL;
|
||||
}
|
||||
|
||||
public enum ConnectionPriority {
|
||||
LOW,
|
||||
NORMAL,
|
||||
HIGH
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import java.util.List;
|
||||
|
||||
import com.hbm.config.GeneralConfig;
|
||||
|
||||
import api.hbm.energy.IEnergyConnector.ConnectionPriority;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
/**
|
||||
@ -135,33 +136,48 @@ public class PowerNet implements IPowerNet {
|
||||
if(this.subscribers.isEmpty())
|
||||
return power;
|
||||
|
||||
List<IEnergyConnector> subList = new ArrayList(subscribers);
|
||||
ConnectionPriority[] priorities = new ConnectionPriority[] {ConnectionPriority.HIGH, ConnectionPriority.NORMAL, ConnectionPriority.LOW};
|
||||
|
||||
List<Long> weight = new ArrayList();
|
||||
long totalReq = 0;
|
||||
|
||||
for(IEnergyConnector con : subList) {
|
||||
long req = con.getTransferWeight();
|
||||
weight.add(req);
|
||||
totalReq += req;
|
||||
for(ConnectionPriority p : priorities) {
|
||||
|
||||
List<IEnergyConnector> subList = new ArrayList();
|
||||
subscribers.forEach(x -> {
|
||||
if(x.getPriority() == p) {
|
||||
subList.add(x);
|
||||
}
|
||||
});
|
||||
|
||||
if(subList.isEmpty())
|
||||
continue;
|
||||
|
||||
List<Long> weight = new ArrayList();
|
||||
long totalReq = 0;
|
||||
|
||||
for(IEnergyConnector con : subList) {
|
||||
long req = con.getTransferWeight();
|
||||
weight.add(req);
|
||||
totalReq += req;
|
||||
}
|
||||
|
||||
if(totalReq == 0)
|
||||
continue;
|
||||
|
||||
long totalGiven = 0;
|
||||
|
||||
for(int i = 0; i < subList.size(); i++) {
|
||||
IEnergyConnector con = subList.get(i);
|
||||
long req = weight.get(i);
|
||||
double fraction = (double)req / (double)totalReq;
|
||||
|
||||
long given = (long) Math.floor(fraction * power);
|
||||
|
||||
totalGiven += (given - con.transferPower(given));
|
||||
}
|
||||
|
||||
power -= totalGiven;
|
||||
}
|
||||
|
||||
if(totalReq == 0)
|
||||
return power;
|
||||
|
||||
long totalGiven = 0;
|
||||
|
||||
for(int i = 0; i < subList.size(); i++) {
|
||||
IEnergyConnector con = subList.get(i);
|
||||
long req = weight.get(i);
|
||||
double fraction = (double)req / (double)totalReq;
|
||||
|
||||
long given = (long) Math.floor(fraction * power);
|
||||
|
||||
totalGiven += (given - con.transferPower(given));
|
||||
}
|
||||
|
||||
return power - totalGiven;
|
||||
return power;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -120,7 +120,7 @@ public class AssemblerRecipes {
|
||||
ComparableStack compStack = ItemAssemblyTemplate.readType(stack);
|
||||
if(compStack != null) {
|
||||
AStack[] ret = recipes.get(compStack);
|
||||
return Arrays.asList(ret);
|
||||
return ret == null ? null : Arrays.asList(ret);
|
||||
}
|
||||
|
||||
//LEGACY
|
||||
@ -131,7 +131,7 @@ public class AssemblerRecipes {
|
||||
if(out != null) {
|
||||
ComparableStack comp = new ComparableStack(out);
|
||||
AStack[] ret = recipes.get(comp);
|
||||
return Arrays.asList(ret);
|
||||
return ret == null ? null : Arrays.asList(ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import api.hbm.energy.IBatteryItem;
|
||||
import api.hbm.energy.IEnergyConductor;
|
||||
import api.hbm.energy.IEnergyConnector;
|
||||
import api.hbm.energy.IEnergyUser;
|
||||
import api.hbm.energy.IEnergyConnector.ConnectionPriority;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@ -302,6 +303,11 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
|
||||
public void setPower(long power) {
|
||||
this.power = power;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionPriority getPriority() {
|
||||
return ConnectionPriority.LOW;
|
||||
}
|
||||
|
||||
// do some opencomputer stuff
|
||||
@Override
|
||||
|
||||
@ -16,6 +16,8 @@ public class TileEntityMachineFENSU extends TileEntityMachineBattery {
|
||||
public float prevRotation = 0F;
|
||||
public float rotation = 0F;
|
||||
|
||||
public static final long maxTransfer = 10_000_000_000_000_000L;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
@ -68,7 +70,7 @@ public class TileEntityMachineFENSU extends TileEntityMachineBattery {
|
||||
if(te instanceof IEnergyConnector) {
|
||||
IEnergyConnector con = (IEnergyConnector) te;
|
||||
|
||||
long max = 10_000_000_000_000_000L;
|
||||
long max = maxTransfer;
|
||||
long toTransfer = Math.min(max, this.power);
|
||||
long remainder = this.power - toTransfer;
|
||||
this.power = toTransfer;
|
||||
@ -108,6 +110,11 @@ public class TileEntityMachineFENSU extends TileEntityMachineBattery {
|
||||
public long getMaxPower() {
|
||||
return Long.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTransferWeight() {
|
||||
return Math.min(Math.max(this.getMaxPower() - getPower(), 0), maxTransfer);
|
||||
}
|
||||
|
||||
public float getSpeed() {
|
||||
return (float) Math.pow(Math.log(power * 0.75 + 1) * 0.05F, 5);
|
||||
@ -127,7 +134,7 @@ public class TileEntityMachineFENSU extends TileEntityMachineBattery {
|
||||
|
||||
// override the name because when connecting the machine to opencomputers it's gonna say "ntm_energy_storage"
|
||||
@Override
|
||||
public String getComponentName() {
|
||||
return "ntm_fensu";
|
||||
public String getComponentName() {
|
||||
return "ntm_fensu";
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user