From 89fe899f2a0ac5ca83f8960daddd1347c9fe872b Mon Sep 17 00:00:00 2001 From: 70000hp <105080577+70000hp@users.noreply.github.com> Date: Tue, 11 Feb 2025 17:46:39 -0500 Subject: [PATCH 1/2] Rotary Furnace Fuel Tweak Better fuels speed up the rotary furnace, but require more steam Steam requirements scale with speed nonlinearly, being x^1.5 --- .../java/com/hbm/module/ModuleBurnTime.java | 63 ++++--- .../TileEntityMachineRotaryFurnace.java | 176 ++++++++++-------- 2 files changed, 139 insertions(+), 100 deletions(-) diff --git a/src/main/java/com/hbm/module/ModuleBurnTime.java b/src/main/java/com/hbm/module/ModuleBurnTime.java index 7b8db83219..f4a5ec3db8 100644 --- a/src/main/java/com/hbm/module/ModuleBurnTime.java +++ b/src/main/java/com/hbm/module/ModuleBurnTime.java @@ -30,9 +30,11 @@ public class ModuleBurnTime { private static final int modRocket = 6; private static final int modBalefire = 7; + private double[] modTime = new double[8]; + private double[] modHeat = new double[8]; - + public ModuleBurnTime() { for(int i = 0; i < modTime.length; i++) { modTime[i] = 1.0D; @@ -78,23 +80,23 @@ public void writeConfig(JsonWriter writer) throws IOException { writer.name("D:heatRocket").value(modHeat[modRocket]); writer.name("D:heatBalefie").value(modHeat[modBalefire]); } - + public int getBurnTime(ItemStack stack) { //int fuel = TileEntityFurnace.getItemBurnTime(stack); int fuel = FuelHandler.getBurnTimeFromCache(stack); - + if(fuel == 0) return 0; - + return (int) (fuel * getMod(stack, modTime)); } - + public int getBurnHeat(int base, ItemStack stack) { return (int) (base * getMod(stack, modHeat)); } - + public double getMod(ItemStack stack, double[] mod) { - + if(stack == null) return 0; @@ -105,11 +107,11 @@ public double getMod(ItemStack stack, double[] mod) { if(stack.getItem() == ModItems.solid_fuel_bf) return mod[modBalefire]; if(stack.getItem() == ModItems.solid_fuel_presto_bf) return mod[modBalefire]; if(stack.getItem() == ModItems.solid_fuel_presto_triplet_bf) return mod[modBalefire]; - + if(stack.getItem() == ModItems.rocket_fuel) return mod[modRocket]; - + List names = ItemStackUtil.getOreDictNames(stack); - + for(String name : names) { if(name.contains("Coke")) return mod[modCoke]; if(name.contains("Coal")) return mod[modCoal]; @@ -117,22 +119,22 @@ public double getMod(ItemStack stack, double[] mod) { if(name.startsWith("log")) return mod[modLog]; if(name.contains("Wood")) return mod[modWood]; } - + return 1; } - + public List getDesc() { List desc = new ArrayList(); desc.addAll(getTimeDesc()); desc.addAll(getHeatDesc()); return desc; } - + public List getTimeDesc() { List list = new ArrayList(); list.add(EnumChatFormatting.GOLD + "Burn time bonuses:"); - + addIf(list, "Logs", modTime[modLog]); addIf(list, "Wood", modTime[modWood]); addIf(list, "Coal", modTime[modCoal]); @@ -141,18 +143,18 @@ public List getTimeDesc() { addIf(list, "Solid Fuel", modTime[modSolid]); addIf(list, "Rocket Fuel", modTime[modRocket]); addIf(list, "Balefire", modTime[modBalefire]); - + if(list.size() == 1) list.clear(); - + return list; } - + public List getHeatDesc() { List list = new ArrayList(); list.add(EnumChatFormatting.RED + "Burn heat bonuses:"); - + addIf(list, "Logs", modHeat[modLog]); addIf(list, "Wood", modHeat[modWood]); addIf(list, "Coal", modHeat[modCoal]); @@ -161,31 +163,38 @@ public List getHeatDesc() { addIf(list, "Solid Fuel", modHeat[modSolid]); addIf(list, "Rocket Fuel", modHeat[modRocket]); addIf(list, "Balefire", modHeat[modBalefire]); - + if(list.size() == 1) list.clear(); - + return list; } - + private void addIf(List list, String name, double mod) { - + if(mod != 1.0D) list.add(EnumChatFormatting.YELLOW + "- " + name + ": " + getPercent(mod)); } - + private String getPercent(double mod) { mod -= 1D; String num = ((int) (mod * 100)) + "%"; - + if(mod < 0) num = EnumChatFormatting.RED + num; else num = EnumChatFormatting.GREEN + "+" + num; - + return num; } - + public double[] getModHeat() { + return modHeat; + } + public double[] getModTime() { + return modTime; + } + + public ModuleBurnTime setLogTimeMod(double mod) { this.modTime[modLog] = mod; return this; } public ModuleBurnTime setWoodTimeMod(double mod) { this.modTime[modWood] = mod; return this; } public ModuleBurnTime setCoalTimeMod(double mod) { this.modTime[modCoal] = mod; return this; } @@ -194,7 +203,7 @@ private String getPercent(double mod) { public ModuleBurnTime setSolidTimeMod(double mod) { this.modTime[modSolid] = mod; return this; } public ModuleBurnTime setRocketTimeMod(double mod) { this.modTime[modRocket] = mod; return this; } public ModuleBurnTime setBalefireTimeMod(double mod) { this.modTime[modBalefire] = mod; return this; } - + public ModuleBurnTime setLogHeatMod(double mod) { this.modHeat[modLog] = mod; return this; } public ModuleBurnTime setWoodHeatMod(double mod) { this.modHeat[modWood] = mod; return this; } public ModuleBurnTime setCoalHeatMod(double mod) { this.modHeat[modCoal] = mod; return this; } diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineRotaryFurnace.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineRotaryFurnace.java index f9fef29304..20993eb729 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineRotaryFurnace.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineRotaryFurnace.java @@ -1,7 +1,10 @@ package com.hbm.tileentity.machine; +import java.io.IOException; import java.util.Random; +import com.google.gson.JsonObject; +import com.google.gson.stream.JsonWriter; import com.hbm.handler.pollution.PollutionHandler; import com.hbm.handler.pollution.PollutionHandler.PollutionType; import com.hbm.inventory.RecipesCommon.AStack; @@ -16,12 +19,10 @@ import com.hbm.inventory.recipes.RotaryFurnaceRecipes.RotaryFurnaceRecipe; import com.hbm.lib.Library; import com.hbm.main.MainRegistry; +import com.hbm.module.ModuleBurnTime; import com.hbm.packet.PacketDispatcher; import com.hbm.packet.toclient.AuxParticlePacketNT; -import com.hbm.tileentity.IConditionalInvAccess; -import com.hbm.tileentity.IFluidCopiable; -import com.hbm.tileentity.IGUIProvider; -import com.hbm.tileentity.TileEntityMachinePolluting; +import com.hbm.tileentity.*; import com.hbm.util.CrucibleUtil; import com.hbm.util.fauxpointtwelve.BlockPos; import com.hbm.util.fauxpointtwelve.DirPos; @@ -41,27 +42,39 @@ import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting implements IFluidStandardTransceiver, IGUIProvider, IFluidCopiable, IConditionalInvAccess { - +public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting implements IFluidStandardTransceiver, IGUIProvider, IFluidCopiable, IConditionalInvAccess, IConfigurableMachine { + public FluidTank[] tanks; public boolean isProgressing; public float progress; public int burnTime; public int maxBurnTime; - public int steamUsed = 0; public boolean isVenting; public MaterialStack output; + public ItemStack lastFuel; public static final int maxOutput = MaterialShapes.BLOCK.q(16); - + public int anim; public int lastAnim; + /**Given this has no heat, the heat mod instead affects the progress per fuel **/ + public static ModuleBurnTime burnModule = new ModuleBurnTime() + .setCokeTimeMod(1.25) + .setRocketTimeMod(1.5) + .setSolidTimeMod(1.5) + .setBalefireTimeMod(1.5) + + .setCokeHeatMod(1.25) + .setSolidHeatMod(1.5) + .setRocketHeatMod(2.5) + .setBalefireHeatMod(10); + public TileEntityMachineRotaryFurnace() { super(5, 50); tanks = new FluidTank[3]; tanks[0] = new FluidTank(Fluids.NONE, 16_000); - tanks[1] = new FluidTank(Fluids.STEAM, 4_000); - tanks[2] = new FluidTank(Fluids.SPENTSTEAM, 40); + tanks[1] = new FluidTank(Fluids.STEAM, 12_000); + tanks[2] = new FluidTank(Fluids.SPENTSTEAM, 120); } @Override @@ -71,12 +84,12 @@ public String getName() { @Override public void updateEntity() { - + ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN); - + if(!worldObj.isRemote) { - + tanks[0].setType(3, slots); for(DirPos pos : getSteamPos()) { @@ -86,16 +99,16 @@ public void updateEntity() { if(tanks[0].getTankType() != Fluids.NONE) for(DirPos pos : getFluidPos()) { this.trySubscribe(tanks[0].getTankType(), worldObj, pos.getX(), pos.getY(), pos.getZ(), pos.getDir()); } - + if(smoke.getFill() > 0) this.sendFluid(smoke, worldObj, xCoord + rot.offsetX, yCoord + 5, zCoord + rot.offsetZ, Library.POS_Y); - + if(this.output != null) { - + int prev = this.output.amount; Vec3 impact = Vec3.createVectorHelper(0, 0, 0); MaterialStack leftover = CrucibleUtil.pourSingleStack(worldObj, xCoord + 0.5D + rot.offsetX * 2.875D, yCoord + 1.25D, zCoord + 0.5D + rot.offsetZ * 2.875D, 6, true, this.output, MaterialShapes.INGOT.q(1), impact); this.output = leftover; - + if(prev != this.output.amount) { this.output = leftover; NBTTagCompound data = new NBTTagCompound(); @@ -107,31 +120,35 @@ public void updateEntity() { data.setFloat("len", Math.max(1F, yCoord + 1 - (float) (Math.ceil(impact.yCoord) - 1.125))); PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, xCoord + 0.5D + rot.offsetX * 2.875D, yCoord + 0.75, zCoord + 0.5D + rot.offsetZ * 2.875D), new TargetPoint(worldObj.provider.dimensionId, xCoord + 0.5, yCoord + 1, zCoord + 0.5, 50)); } - + if(output.amount <= 0) this.output = null; } - + RotaryFurnaceRecipe recipe = RotaryFurnaceRecipes.getRecipe(slots[0], slots[1], slots[2]); this.isProgressing = false; - + if(recipe != null) { - + if(this.burnTime <= 0 && slots[4] != null && TileEntityFurnace.isItemFuel(slots[4])) { - this.maxBurnTime = this.burnTime = TileEntityFurnace.getItemBurnTime(slots[4]) / 2; + lastFuel = slots[4]; + this.maxBurnTime = this.burnTime = burnModule.getBurnTime(lastFuel) / 2; this.decrStackSize(4, 1); this.markChanged(); } - + if(this.canProcess(recipe)) { - this.progress += 1F / recipe.duration; - tanks[1].setFill(tanks[1].getFill() - recipe.steam); - steamUsed += recipe.steam; + float speed = Math.max((float) burnModule.getMod(lastFuel, burnModule.getModHeat()), 1); + this.progress += speed / recipe.duration; + + speed = (float) Math.pow(speed, 1.5); + tanks[1].setFill((int) (tanks[1].getFill() - recipe.steam * speed)); + tanks[2].setFill((int) (tanks[2].getFill() + recipe.steam * speed / 100)); this.isProgressing = true; - + if(this.progress >= 1F) { this.progress -= 1F; this.consumeItems(recipe); - + if(this.output == null) { this.output = recipe.output.copy(); } else { @@ -139,40 +156,31 @@ public void updateEntity() { } this.markDirty(); } - + } else { this.progress = 0; } - - if(this.steamUsed >= 100) { - int steamReturn = this.steamUsed / 100; - int canReturn = tanks[2].getMaxFill() - tanks[2].getFill(); - int doesReturn = Math.min(steamReturn, canReturn); - this.steamUsed -= doesReturn * 100; - tanks[2].setFill(tanks[2].getFill() + doesReturn); - } - } else { this.progress = 0; } - + this.isVenting = false; if(this.burnTime > 0) { this.pollute(PollutionType.SOOT, PollutionHandler.SOOT_PER_SECOND / 10F); this.burnTime--; } - + this.networkPackNT(50); - + } else { - + if(this.burnTime > 0 && MainRegistry.proxy.me().getDistance(xCoord, yCoord, zCoord) < 25) { Random rand = worldObj.rand; worldObj.spawnParticle("flame", xCoord + 0.5 + dir.offsetX * 0.5 + rot.offsetX + rand.nextGaussian() * 0.25, yCoord + 0.375, zCoord + 0.5 + dir.offsetZ * 0.5 + rot.offsetZ + rand.nextGaussian() * 0.25, 0, 0, 0); } if(isVenting && worldObj.getTotalWorldTime() % 2 == 0) { - + NBTTagCompound fx = new NBTTagCompound(); fx.setString("type", "tower"); fx.setFloat("lift", 10F); @@ -187,7 +195,7 @@ public void updateEntity() { } this.lastAnim = this.anim; if(this.isProgressing) { - this.anim++; + this.anim += (int) Math.max(burnModule.getMod(slots[4], burnModule.getModHeat()), 1); } } } @@ -202,7 +210,7 @@ public void updateEntity() { buf.writeFloat(progress); buf.writeInt(burnTime); buf.writeInt(maxBurnTime); - + if(this.output != null) { buf.writeBoolean(true); buf.writeInt(this.output.material.id); @@ -211,7 +219,7 @@ public void updateEntity() { buf.writeBoolean(false); } } - + @Override public void deserialize(ByteBuf buf) { super.deserialize(buf); tanks[0].deserialize(buf); @@ -222,14 +230,14 @@ public void updateEntity() { progress = buf.readFloat(); burnTime = buf.readInt(); maxBurnTime = buf.readInt(); - + if(buf.readBoolean()) { this.output = new MaterialStack(Mats.matById.get(buf.readInt()), buf.readInt()); } else { this.output = null; } } - + @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); @@ -239,8 +247,11 @@ public void readFromNBT(NBTTagCompound nbt) { this.progress = nbt.getFloat("prog"); this.burnTime = nbt.getInteger("burn"); this.maxBurnTime = nbt.getInteger("maxBurn"); + ItemStack nbtFuel = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("lastFuel")); + if(nbtFuel != null) + this.lastFuel = nbtFuel; } - + @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); @@ -250,32 +261,33 @@ public void writeToNBT(NBTTagCompound nbt) { nbt.setFloat("prog", progress); nbt.setInteger("burn", burnTime); nbt.setInteger("maxBurn", maxBurnTime); + nbt.setTag("lastFuel", lastFuel.writeToNBT(new NBTTagCompound())); } - + public DirPos[] getSteamPos() { ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN); - + return new DirPos[] { new DirPos(xCoord - dir.offsetX * 2 - rot.offsetX * 2, yCoord, zCoord - dir.offsetZ * 2 - rot.offsetZ * 2, dir.getOpposite()), new DirPos(xCoord - dir.offsetX * 2 - rot.offsetX, yCoord, zCoord - dir.offsetZ * 2 - rot.offsetZ, dir.getOpposite()) }; } - + public DirPos[] getFluidPos() { ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection rot = dir.getRotation(ForgeDirection.DOWN); - + return new DirPos[] { new DirPos(xCoord + dir.offsetX + rot.offsetX * 3, yCoord, zCoord + dir.offsetZ + rot.offsetZ * 3, rot), new DirPos(xCoord - dir.offsetX + rot.offsetX * 3, yCoord, zCoord - dir.offsetZ + rot.offsetZ * 3, rot) }; } - + public boolean canProcess(RotaryFurnaceRecipe recipe) { - + if(this.burnTime <= 0) return false; - + if(recipe.fluid != null) { if(this.tanks[0].getTankType() != recipe.fluid.type) return false; if(this.tanks[0].getFill() < recipe.fluid.fill) return false; @@ -283,20 +295,19 @@ public boolean canProcess(RotaryFurnaceRecipe recipe) { if(tanks[1].getFill() < recipe.steam) return false; if(tanks[2].getMaxFill() - tanks[2].getFill() < recipe.steam / 100) return false; - if(this.steamUsed > 100) return false; - + if(this.output != null) { if(this.output.material != recipe.output.material) return false; if(this.output.amount + recipe.output.amount > this.maxOutput) return false; } - + return true; } - + public void consumeItems(RotaryFurnaceRecipe recipe) { - + for(AStack aStack : recipe.ingredients) { - + for(int i = 0; i < 3; i++) { ItemStack stack = slots[i]; if(aStack.matchesRecipe(stack, true) && stack.stackSize >= aStack.stacksize) { @@ -305,19 +316,19 @@ public void consumeItems(RotaryFurnaceRecipe recipe) { } } } - + if(recipe.fluid != null) { this.tanks[0].setFill(tanks[0].getFill() - recipe.fluid.fill); } } - + @Override public void pollute(PollutionType type, float amount) { FluidTank tank = type == PollutionType.SOOT ? smoke : type == PollutionType.HEAVYMETAL ? smoke_leaded : smoke_poison; - + int fluidAmount = (int) Math.ceil(amount * 100); tank.setFill(tank.getFill() + fluidAmount); - + if(tank.getFill() > tank.getMaxFill()) { int overflow = tank.getFill() - tank.getMaxFill(); tank.setFill(tank.getMaxFill()); @@ -332,12 +343,12 @@ public void pollute(PollutionType type, float amount) { @Override public boolean isItemValidForSlot(int x, int y, int z, int slot, ItemStack stack) { return slot < 3 || slot == 4; } @Override public boolean canExtractItem(int x, int y, int z, int slot, ItemStack stack, int side) { return false; } - + AxisAlignedBB bb = null; - + @Override public AxisAlignedBB getRenderBoundingBox() { - + if(bb == null) { bb = AxisAlignedBB.getBoundingBox( xCoord - 2, @@ -348,10 +359,10 @@ public AxisAlignedBB getRenderBoundingBox() { zCoord + 3 ); } - + return bb; } - + @Override @SideOnly(Side.CLIENT) public double getMaxRenderDistanceSquared() { @@ -364,7 +375,7 @@ public int[] getAccessibleSlotsFromSide(int x, int y, int z, int side) { ForgeDirection dir = ForgeDirection.getOrientation(this.getBlockMetadata() - 10); ForgeDirection rot = dir.getRotation(ForgeDirection.UP); BlockPos core = new BlockPos(xCoord, yCoord, zCoord); - + //Red if(side == dir.getOpposite().ordinal() && pos.equals(core.clone().offset(dir, -1).offset(rot, -2))) return new int[] {0}; //Yellow @@ -373,7 +384,7 @@ public int[] getAccessibleSlotsFromSide(int x, int y, int z, int side) { if(side == dir.getOpposite().ordinal() && pos.equals(core.clone().offset(dir, -1))) return new int[] {2}; //Fuel if(side == dir.ordinal() && pos.equals(core.clone().offset(dir, 1).offset(rot, -1))) return new int[] {4}; - + return new int[] { }; } @@ -383,4 +394,23 @@ public int[] getAccessibleSlotsFromSide(int x, int y, int z, int side) { @Override public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) { return new ContainerMachineRotaryFurnace(player.inventory, this); } @Override public Object provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) { return new GUIMachineRotaryFurnace(player.inventory, this); } + + @Override + public String getConfigName() { + return "rotaryfurnace"; + } + + @Override + public void readIfPresent(JsonObject obj) { + if(obj.has("burnModule")) { + burnModule.readIfPresent(obj.get("M:burnModule").getAsJsonObject()); + } + } + + @Override + public void writeConfig(JsonWriter writer) throws IOException { + writer.name("M:burnModule").beginObject(); + burnModule.writeConfig(writer); + writer.endObject(); + } } From 3a7e9745416b5f863628844c6836e1eb143a3201 Mon Sep 17 00:00:00 2001 From: 70000hp <105080577+70000hp@users.noreply.github.com> Date: Tue, 11 Feb 2025 18:17:29 -0500 Subject: [PATCH 2/2] adjustments --- .../tileentity/machine/TileEntityMachineRotaryFurnace.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineRotaryFurnace.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineRotaryFurnace.java index 20993eb729..a8cf4ac5fc 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineRotaryFurnace.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineRotaryFurnace.java @@ -64,9 +64,8 @@ public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting i .setSolidTimeMod(1.5) .setBalefireTimeMod(1.5) - .setCokeHeatMod(1.25) .setSolidHeatMod(1.5) - .setRocketHeatMod(2.5) + .setRocketHeatMod(3) .setBalefireHeatMod(10); public TileEntityMachineRotaryFurnace() { @@ -140,7 +139,7 @@ public void updateEntity() { float speed = Math.max((float) burnModule.getMod(lastFuel, burnModule.getModHeat()), 1); this.progress += speed / recipe.duration; - speed = (float) Math.pow(speed, 1.5); + speed = (float)(13 * Math.log10(speed) + 1); tanks[1].setFill((int) (tanks[1].getFill() - recipe.steam * speed)); tanks[2].setFill((int) (tanks[2].getFill() + recipe.steam * speed / 100)); this.isProgressing = true;