From 36cef5e2fece323cd952befbce907eb4b322523c Mon Sep 17 00:00:00 2001 From: Boblet Date: Wed, 2 Nov 2022 16:38:42 +0100 Subject: [PATCH] fair battery output, prototype for balanced solidification recipes --- src/main/java/api/hbm/energy/PowerNet.java | 19 +++++-- .../recipes/SolidificationRecipes.java | 39 ++++++++++++++ src/main/java/com/hbm/items/ModItems.java | 4 +- .../storage/TileEntityMachineBattery.java | 54 ++++++++++++++++++- 4 files changed, 108 insertions(+), 8 deletions(-) diff --git a/src/main/java/api/hbm/energy/PowerNet.java b/src/main/java/api/hbm/energy/PowerNet.java index be5194fb9..e58536a8d 100644 --- a/src/main/java/api/hbm/energy/PowerNet.java +++ b/src/main/java/api/hbm/energy/PowerNet.java @@ -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 subscribers) { + + subscribers.removeIf(x -> + x == null || !(x instanceof TileEntity) || ((TileEntity)x).isInvalid() || !x.isLoaded() + ); + } + + public static long fairTransfer(List subscribers, long power) { + + if(subscribers.isEmpty()) return power; ConnectionPriority[] priorities = new ConnectionPriority[] {ConnectionPriority.HIGH, ConnectionPriority.NORMAL, ConnectionPriority.LOW}; diff --git a/src/main/java/com/hbm/inventory/recipes/SolidificationRecipes.java b/src/main/java/com/hbm/inventory/recipes/SolidificationRecipes.java index cb7d1ed18..830c1e809 100644 --- a/src/main/java/com/hbm/inventory/recipes/SolidificationRecipes.java +++ b/src/main/java/com/hbm/inventory/recipes/SolidificationRecipes.java @@ -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)); } diff --git a/src/main/java/com/hbm/items/ModItems.java b/src/main/java/com/hbm/items/ModItems.java index e30e7820a..9f76c05a6 100644 --- a/src/main/java/com/hbm/items/ModItems.java +++ b/src/main/java/com/hbm/items/ModItems.java @@ -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"); diff --git a/src/main/java/com/hbm/tileentity/machine/storage/TileEntityMachineBattery.java b/src/main/java/com/hbm/tileentity/machine/storage/TileEntityMachineBattery.java index ed23114be..8c7abbdbd 100644 --- a/src/main/java/com/hbm/tileentity/machine/storage/TileEntityMachineBattery.java +++ b/src/main/java/com/hbm/tileentity/machine/storage/TileEntityMachineBattery.java @@ -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 nets = new HashSet(); + Set 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 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();