fair battery output, prototype for balanced solidification recipes

This commit is contained in:
Boblet 2022-11-02 16:38:42 +01:00
parent 04cd4e8951
commit 36cef5e2fe
4 changed files with 108 additions and 8 deletions

View File

@ -126,14 +126,23 @@ public class PowerNet implements IPowerNet {
public long transferPower(long power) {
if(lastCleanup + 45 < System.currentTimeMillis()) {
this.subscribers.removeIf(x ->
x == null || !(x instanceof TileEntity) || ((TileEntity)x).isInvalid() || !x.isLoaded()
);
cleanup(this.subscribers);
lastCleanup = System.currentTimeMillis();
}
if(this.subscribers.isEmpty())
return fairTransfer(this.subscribers, power);
}
public static void cleanup(List<IEnergyConnector> subscribers) {
subscribers.removeIf(x ->
x == null || !(x instanceof TileEntity) || ((TileEntity)x).isInvalid() || !x.isLoaded()
);
}
public static long fairTransfer(List<IEnergyConnector> subscribers, long power) {
if(subscribers.isEmpty())
return power;
ConnectionPriority[] priorities = new ConnectionPriority[] {ConnectionPriority.HIGH, ConnectionPriority.NORMAL, ConnectionPriority.LOW};

View File

@ -12,6 +12,7 @@ import com.google.gson.stream.JsonWriter;
import com.hbm.inventory.FluidStack;
import com.hbm.inventory.OreDictManager.DictFrame;
import com.hbm.inventory.fluid.FluidType;
import com.hbm.inventory.fluid.trait.FT_Flammable;
import com.hbm.inventory.recipes.loader.SerializableRecipe;
import com.hbm.items.ItemEnums.EnumTarType;
import com.hbm.items.machine.ItemFluidIcon;
@ -89,7 +90,45 @@ public class SolidificationRecipes extends SerializableRecipe {
registerRecipe(BIOFUEL, SF_BIOFUEL, ModItems.solid_fuel);
registerRecipe(AROMATICS, SF_AROMA, ModItems.solid_fuel);
registerRecipe(UNSATURATEDS, SF_UNSAT, ModItems.solid_fuel);
registerRecipe(BALEFIRE, 250, ModItems.solid_fuel_bf);
//works flawlessly, but the new values are so high that they literally do not fit into the solidifier. some fuels do need a buff.
/*registerSFAuto(SMEAR);
registerSFAuto(HEATINGOIL);
registerSFAuto(RECLAIMED);
registerSFAuto(PETROIL);
//registerSFAuto(LUBRICANT);
registerSFAuto(NAPHTHA);
registerSFAuto(NAPHTHA_CRACK);
registerSFAuto(DIESEL);
registerSFAuto(DIESEL_CRACK);
registerSFAuto(LIGHTOIL);
registerSFAuto(LIGHTOIL_CRACK);
registerSFAuto(KEROSENE);
registerSFAuto(GAS);
registerSFAuto(PETROLEUM);
registerSFAuto(LPG);
registerSFAuto(BIOGAS);
registerSFAuto(BIOFUEL);
registerSFAuto(AROMATICS);
registerSFAuto(UNSATURATEDS);
registerSFAuto(BALEFIRE, 24000000L, ModItems.solid_fuel_bf); //holy shit this is energy dense*/
}
private static void registerSFAuto(FluidType fluid) {
registerSFAuto(fluid, 144000L, ModItems.solid_fuel); //3200 burntime * 1.5 burntime bonus * 300 TU/t
}
private static void registerSFAuto(FluidType fluid, long tuPerSF, Item fuel) {
long tuPerBucket = fluid.getTrait(FT_Flammable.class).getHeatEnergy();
double penalty = 1.5D;
int mB = (int) (tuPerSF * 1000L * penalty / tuPerBucket);
registerRecipe(fluid, mB, fuel);
}
private static void registerRecipe(FluidType type, int quantity, Item output) { registerRecipe(type, quantity, new ItemStack(output)); }

View File

@ -3227,8 +3227,8 @@ public class ModItems {
pellet_rtg_weak = new ItemRTGPellet(5).setDecays(DepletedRTGMaterial.LEAD, (long) (RTGUtil.getLifespan(1.0F, HalfLifeType.LONG, false) * 1.5)).setUnlocalizedName("pellet_rtg_weak").setCreativeTab(MainRegistry.controlTab).setMaxStackSize(1).setTextureName(RefStrings.MODID + ":pellet_rtg_weak");
pellet_rtg = new ItemRTGPellet(10).setDecays(DepletedRTGMaterial.LEAD, (long) (RTGUtil.getLifespan(87.7F, HalfLifeType.MEDIUM, false) * 1.5)).setUnlocalizedName("pellet_rtg").setCreativeTab(MainRegistry.controlTab).setMaxStackSize(1).setTextureName(RefStrings.MODID + ":pellet_rtg");
pellet_rtg_strontium = new ItemRTGPellet(15).setDecays(DepletedRTGMaterial.ZIRCONIUM, (long) (RTGUtil.getLifespan(29.0F, HalfLifeType.MEDIUM, false) * 1.5)).setUnlocalizedName("pellet_rtg_strontium").setCreativeTab(MainRegistry.controlTab).setTextureName(RefStrings.MODID + ":pellet_rtg_strontium");
pellet_rtg_cobalt = new ItemRTGPellet(15).setDecays(DepletedRTGMaterial.NICKEL, (long) (RTGUtil.getLifespan(29.0F, HalfLifeType.MEDIUM, false) * 1.5)).setUnlocalizedName("pellet_rtg_cobalt").setCreativeTab(MainRegistry.controlTab).setTextureName(RefStrings.MODID + ":pellet_rtg_cobalt");
pellet_rtg_actinium = new ItemRTGPellet(20).setDecays(DepletedRTGMaterial.LEAD, (long) (RTGUtil.getLifespan(5.3F, HalfLifeType.MEDIUM, false) * 1.5)).setUnlocalizedName("pellet_rtg_actinium").setCreativeTab(MainRegistry.controlTab).setTextureName(RefStrings.MODID + ":pellet_rtg_actinium");
pellet_rtg_cobalt = new ItemRTGPellet(15).setDecays(DepletedRTGMaterial.NICKEL, (long) (RTGUtil.getLifespan(5.3F, HalfLifeType.MEDIUM, false) * 1.5)).setUnlocalizedName("pellet_rtg_cobalt").setCreativeTab(MainRegistry.controlTab).setTextureName(RefStrings.MODID + ":pellet_rtg_cobalt");
pellet_rtg_actinium = new ItemRTGPellet(20).setDecays(DepletedRTGMaterial.LEAD, (long) (RTGUtil.getLifespan(21.8F, HalfLifeType.MEDIUM, false) * 1.5)).setUnlocalizedName("pellet_rtg_actinium").setCreativeTab(MainRegistry.controlTab).setTextureName(RefStrings.MODID + ":pellet_rtg_actinium");
pellet_rtg_americium = new ItemRTGPellet(20).setDecays(DepletedRTGMaterial.NEPTUNIUM, (long) (RTGUtil.getLifespan(4.7F, HalfLifeType.LONG, false) * 1.5)).setUnlocalizedName("pellet_rtg_americium").setCreativeTab(MainRegistry.controlTab).setMaxStackSize(1).setTextureName(RefStrings.MODID + ":pellet_rtg_americium");
pellet_rtg_berkelium = new ItemRTGPellet(20).setUnlocalizedName("pellet_rtg_berkelium").setCreativeTab(MainRegistry.controlTab).setMaxStackSize(1).setTextureName(RefStrings.MODID + ":pellet_rtg_berkelium");
pellet_rtg_polonium = new ItemRTGPellet(50).setDecays(DepletedRTGMaterial.LEAD, (long) (RTGUtil.getLifespan(138.0F, HalfLifeType.SHORT, false) * 1.5)).setUnlocalizedName("pellet_rtg_polonium").setCreativeTab(MainRegistry.controlTab).setMaxStackSize(1).setTextureName(RefStrings.MODID + ":pellet_rtg_polonium");

View File

@ -1,5 +1,10 @@
package com.hbm.tileentity.machine.storage;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.hbm.blocks.machine.MachineBattery;
import com.hbm.lib.Library;
import com.hbm.tileentity.IPersistentNBT;
@ -9,6 +14,8 @@ import api.hbm.energy.IBatteryItem;
import api.hbm.energy.IEnergyConductor;
import api.hbm.energy.IEnergyConnector;
import api.hbm.energy.IEnergyUser;
import api.hbm.energy.IPowerNet;
import api.hbm.energy.PowerNet;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@ -152,7 +159,7 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
long prevPower = this.power;
//////////////////////////////////////////////////////////////////////
this.transmitPower();
this.transmitPowerFairly();
//////////////////////////////////////////////////////////////////////
byte comp = this.getComparatorPower();
@ -182,6 +189,51 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
}
}
protected void transmitPowerFairly() {
short mode = (short) this.getRelevantMode();
//HasSets to we don'T have any duplicates
Set<IPowerNet> nets = new HashSet();
Set<IEnergyConnector> consumers = new HashSet();
//iterate over all sides
for(ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity te = worldObj.getTileEntity(xCoord + dir.offsetX, yCoord + dir.offsetY, zCoord + dir.offsetZ);
//if it's a cable, buffer both the network and all subscribers of the net
if(te instanceof IEnergyConductor) {
IEnergyConductor con = (IEnergyConductor) te;
if(con.getPowerNet() != null) {
nets.add(con.getPowerNet());
consumers.addAll(con.getPowerNet().getSubscribers());
}
//if it's just a consumer, buffer it as a subscriber
} else if(te instanceof IEnergyConnector) {
consumers.add((IEnergyConnector) te);
}
}
//ubsubscribe from all nets
nets.forEach(x -> x.unsubscribe(this));
//send power to buffered consumers, independent of nets
if(mode == mode_buffer || mode == mode_output) {
long oldPower = this.power;
List<IEnergyConnector> con = new ArrayList();
con.addAll(consumers);
long transfer = this.power - PowerNet.fairTransfer(con, this.power);
this.power = oldPower - transfer;
}
//resubscribe to buffered nets, if necessary
if(mode == mode_buffer || mode == mode_input) {
nets.forEach(x -> x.subscribe(this));
}
}
protected void transmitPower() {
short mode = (short) this.getRelevantMode();