FEnSU fix, power priorisation

This commit is contained in:
Bob 2022-06-27 23:31:00 +02:00
parent 4537a6e214
commit 10c9f7a121
5 changed files with 68 additions and 29 deletions

View File

@ -107,4 +107,14 @@ public interface IEnergyConnector extends ILoadedTile {
Vec3 vec = Vec3.createVectorHelper(te.xCoord + 0.5, te.yCoord + 1, te.zCoord + 0.5); Vec3 vec = Vec3.createVectorHelper(te.xCoord + 0.5, te.yCoord + 1, te.zCoord + 0.5);
return vec; return vec;
} }
public default ConnectionPriority getPriority() {
return ConnectionPriority.NORMAL;
}
public enum ConnectionPriority {
LOW,
NORMAL,
HIGH
}
} }

View File

@ -6,6 +6,7 @@ import java.util.List;
import com.hbm.config.GeneralConfig; import com.hbm.config.GeneralConfig;
import api.hbm.energy.IEnergyConnector.ConnectionPriority;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
/** /**
@ -135,33 +136,48 @@ public class PowerNet implements IPowerNet {
if(this.subscribers.isEmpty()) if(this.subscribers.isEmpty())
return power; return power;
List<IEnergyConnector> subList = new ArrayList(subscribers); ConnectionPriority[] priorities = new ConnectionPriority[] {ConnectionPriority.HIGH, ConnectionPriority.NORMAL, ConnectionPriority.LOW};
List<Long> weight = new ArrayList(); for(ConnectionPriority p : priorities) {
long totalReq = 0;
for(IEnergyConnector con : subList) { List<IEnergyConnector> subList = new ArrayList();
long req = con.getTransferWeight(); subscribers.forEach(x -> {
weight.add(req); if(x.getPriority() == p) {
totalReq += req; 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;
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;
} }
@Override @Override

View File

@ -120,7 +120,7 @@ public class AssemblerRecipes {
ComparableStack compStack = ItemAssemblyTemplate.readType(stack); ComparableStack compStack = ItemAssemblyTemplate.readType(stack);
if(compStack != null) { if(compStack != null) {
AStack[] ret = recipes.get(compStack); AStack[] ret = recipes.get(compStack);
return Arrays.asList(ret); return ret == null ? null : Arrays.asList(ret);
} }
//LEGACY //LEGACY
@ -131,7 +131,7 @@ public class AssemblerRecipes {
if(out != null) { if(out != null) {
ComparableStack comp = new ComparableStack(out); ComparableStack comp = new ComparableStack(out);
AStack[] ret = recipes.get(comp); AStack[] ret = recipes.get(comp);
return Arrays.asList(ret); return ret == null ? null : Arrays.asList(ret);
} }
} }
} }

View File

@ -8,6 +8,7 @@ import api.hbm.energy.IBatteryItem;
import api.hbm.energy.IEnergyConductor; import api.hbm.energy.IEnergyConductor;
import api.hbm.energy.IEnergyConnector; import api.hbm.energy.IEnergyConnector;
import api.hbm.energy.IEnergyUser; import api.hbm.energy.IEnergyUser;
import api.hbm.energy.IEnergyConnector.ConnectionPriority;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -303,6 +304,11 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
this.power = power; this.power = power;
} }
@Override
public ConnectionPriority getPriority() {
return ConnectionPriority.LOW;
}
// do some opencomputer stuff // do some opencomputer stuff
@Override @Override
public String getComponentName() { public String getComponentName() {

View File

@ -16,6 +16,8 @@ public class TileEntityMachineFENSU extends TileEntityMachineBattery {
public float prevRotation = 0F; public float prevRotation = 0F;
public float rotation = 0F; public float rotation = 0F;
public static final long maxTransfer = 10_000_000_000_000_000L;
@Override @Override
public void updateEntity() { public void updateEntity() {
@ -68,7 +70,7 @@ public class TileEntityMachineFENSU extends TileEntityMachineBattery {
if(te instanceof IEnergyConnector) { if(te instanceof IEnergyConnector) {
IEnergyConnector con = (IEnergyConnector) te; IEnergyConnector con = (IEnergyConnector) te;
long max = 10_000_000_000_000_000L; long max = maxTransfer;
long toTransfer = Math.min(max, this.power); long toTransfer = Math.min(max, this.power);
long remainder = this.power - toTransfer; long remainder = this.power - toTransfer;
this.power = toTransfer; this.power = toTransfer;
@ -109,6 +111,11 @@ public class TileEntityMachineFENSU extends TileEntityMachineBattery {
return Long.MAX_VALUE; return Long.MAX_VALUE;
} }
@Override
public long getTransferWeight() {
return Math.min(Math.max(this.getMaxPower() - getPower(), 0), maxTransfer);
}
public float getSpeed() { public float getSpeed() {
return (float) Math.pow(Math.log(power * 0.75 + 1) * 0.05F, 5); 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 the name because when connecting the machine to opencomputers it's gonna say "ntm_energy_storage"
@Override @Override
public String getComponentName() { public String getComponentName() {
return "ntm_fensu"; return "ntm_fensu";
} }
} }