Skip to content

Commit

Permalink
Merge pull request #1960 from 70000hp/windows-95
Browse files Browse the repository at this point in the history
rotary furnace fuel thing
  • Loading branch information
HbmMods authored Feb 28, 2025
2 parents 4c2639e + 1574f90 commit 299f514
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 39 deletions.
63 changes: 36 additions & 27 deletions src/main/java/com/hbm/module/ModuleBurnTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -105,34 +107,34 @@ 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<String> names = ItemStackUtil.getOreDictNames(stack);

for(String name : names) {
if(name.contains("Coke")) return mod[modCoke];
if(name.contains("Coal")) return mod[modCoal];
if(name.contains("Lignite")) return mod[modLignite];
if(name.startsWith("log")) return mod[modLog];
if(name.contains("Wood")) return mod[modWood];
}

return 1;
}

public List<String> getDesc() {
List<String> desc = new ArrayList();
desc.addAll(getTimeDesc());
desc.addAll(getHeatDesc());
return desc;
}

public List<String> getTimeDesc() {
List<String> 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]);
Expand All @@ -141,18 +143,18 @@ public List<String> 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<String> getHeatDesc() {
List<String> 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]);
Expand All @@ -161,31 +163,38 @@ public List<String> 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<String> 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; }
Expand All @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,12 +20,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;
Expand All @@ -42,7 +43,7 @@
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;
Expand All @@ -52,17 +53,29 @@ public class TileEntityMachineRotaryFurnace extends TileEntityMachinePolluting i
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)

.setSolidHeatMod(1.5)
.setRocketHeatMod(3)
.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
Expand Down Expand Up @@ -118,15 +131,19 @@ public void updateEntity() {
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)(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;

if(this.progress >= 1F) {
Expand Down Expand Up @@ -188,7 +205,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);
}
}
}
Expand Down Expand Up @@ -244,6 +261,9 @@ public void readFromNBT(NBTTagCompound nbt) {
NTMMaterial mat = Mats.matById.get(nbt.getInteger("outType"));
this.output = new MaterialStack(mat, nbt.getInteger("outAmount"));
}
ItemStack nbtFuel = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("lastFuel"));
if(nbtFuel != null)
this.lastFuel = nbtFuel;
}

@Override
Expand All @@ -255,6 +275,7 @@ public void writeToNBT(NBTTagCompound nbt) {
nbt.setFloat("prog", progress);
nbt.setInteger("burn", burnTime);
nbt.setInteger("maxBurn", maxBurnTime);
nbt.setTag("lastFuel", lastFuel.writeToNBT(new NBTTagCompound()));
if (this.output != null) {
nbt.setInteger("outType", this.output.material.id);
nbt.setInteger("outAmount", this.output.amount);
Expand Down Expand Up @@ -392,4 +413,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();
}
}

0 comments on commit 299f514

Please sign in to comment.