Skip to content

Commit

Permalink
Fix magmator fuel energy being one order of magnitude too low. (#171)
Browse files Browse the repository at this point in the history
Fix fluids not being recognized as fuel by thermal generator.
  • Loading branch information
shartte authored Jul 28, 2024
1 parent 72669a5 commit fe13cf9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 30 deletions.
37 changes: 33 additions & 4 deletions src/main/java/owmii/powah/api/PowahAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState;

public class PowahAPI {
private PowahAPI() {
Expand All @@ -16,12 +18,12 @@ private PowahAPI() {
* @param fluid: the fluid used as fuel.
* @return the heat value;
**/
public static int getMagmaticFluidHeat(Fluid fluid) {
var config = BuiltInRegistries.FLUID.getData(PassiveHeatSourceConfig.FLUID_DATA_MAP, fluid.builtInRegistryHolder().key());
public static int getMagmaticFluidEnergyProduced(Fluid fluid) {
var config = BuiltInRegistries.FLUID.getData(MagmatorFuelValue.DATA_MAP_TYPE, fluid.builtInRegistryHolder().key());
if (config == null) {
return 0;
}
return config.temperature();
return config.energyProduced();
}

/**
Expand All @@ -45,13 +47,40 @@ public static OptionalInt getCoolant(Fluid fluid) {
* @return the heat of the block;
**/
public static int getHeatSource(Block block) {
var config = BuiltInRegistries.BLOCK.getData(PassiveHeatSourceConfig.BLOCK_DATA_MAP, block.builtInRegistryHolder().key());
var config = BuiltInRegistries.BLOCK.getData(PassiveHeatSourceConfig.BLOCK_DATA_MAP, BuiltInRegistries.BLOCK.wrapAsHolder(block).getKey());
if (config == null) {
return 0;
}
return config.temperature();
}

/**
* the heat of the heat source block/fluid block.
*
* @param fluid: the fluid used as heat source.
* @return the heat of the block;
**/
public static int getHeatSource(Fluid fluid) {
var config = BuiltInRegistries.FLUID.getData(PassiveHeatSourceConfig.FLUID_DATA_MAP, BuiltInRegistries.FLUID.wrapAsHolder(fluid).getKey());
if (config == null) {
return 0;
}
return config.temperature();
}

public static int getHeatSource(BlockState blockState) {
var heatFromBlock = 0;
var heatFromFluid = 0;
if (!blockState.isEmpty()) {
heatFromBlock = getHeatSource(blockState.getBlock());
}
var fluidState = blockState.getFluidState();
if (!fluidState.isEmpty()) {
heatFromFluid = getHeatSource(fluidState.holder().value()) * fluidState.getAmount() / FluidState.AMOUNT_FULL;
}
return Math.max(heatFromBlock, heatFromFluid);
}

/**
* the coldness of the solid coolant.
*
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/owmii/powah/block/magmator/MagmatorTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class MagmatorTile extends AbstractEnergyProvider<MagmatorBlock> implemen
public MagmatorTile(BlockPos pos, BlockState state, Tier variant) {
super(Tiles.MAGMATOR.get(), pos, state, variant);
this.tank.setCapacity(Util.bucketAmount() * 4)
.setValidator(stack -> PowahAPI.getMagmaticFluidHeat(stack.getFluid()) != 0)
.setValidator(stack -> PowahAPI.getMagmaticFluidEnergyProduced(stack.getFluid()) != 0)
.setChange(() -> MagmatorTile.this.sync(10));
this.inv.add(1);
}
Expand Down Expand Up @@ -54,12 +54,12 @@ protected int postTick(Level world) {
boolean flag = false;
if (this.buffer.isEmpty() && !this.tank.isEmpty()) {
FluidStack fluid = this.tank.getFluid();
int fluidHeat = PowahAPI.getMagmaticFluidHeat(fluid.getFluid());
if (fluidHeat > 0) {
var amountPerDrain = 100 * Util.millibucketAmount();
int energyProduced = PowahAPI.getMagmaticFluidEnergyProduced(fluid.getFluid());
if (energyProduced > 0) {
var amountPerDrain = 100;
var minStored = Math.min(this.tank.getFluidAmount(), amountPerDrain);
this.buffer.setStored((long) minStored * fluidHeat / amountPerDrain);
this.buffer.setCapacity((long) minStored * fluidHeat / amountPerDrain);
this.buffer.setStored((long) minStored * energyProduced / amountPerDrain);
this.buffer.setCapacity((long) minStored * energyProduced / amountPerDrain);
this.tank.drain(minStored, IFluidHandler.FluidAction.EXECUTE);
}
}
Expand Down
13 changes: 2 additions & 11 deletions src/main/java/owmii/powah/block/thermo/ThermoTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.fluids.FluidStack;
import net.neoforged.neoforge.fluids.capability.IFluidHandler;
Expand Down Expand Up @@ -56,19 +54,12 @@ protected int postTick(Level world) {
if (fluidCooling.isPresent()) {
BlockPos heatPos = this.worldPosition.below();
BlockState state = world.getBlockState(heatPos);
Block block = state.getBlock();
int heat = PowahAPI.getHeatSource(block);
int heat = PowahAPI.getHeatSource(state);
if (!this.energy.isFull() && heat != 0) {
if (block instanceof LiquidBlock) {
if (!state.getFluidState().isSource()) {
int level = state.getValue(LiquidBlock.LEVEL);
heat = (int) (heat / ((float) level + 1));
}
}
this.generating = (int) ((heat * Math.max(1D, (1D + fluidCooling.getAsInt()) / 2D) * getGeneration()) / 1000.0D);
this.energy.produce(this.generating);
if (world.getGameTime() % 40 == 0L) {
this.tank.drain(Util.millibucketAmount(), IFluidHandler.FluidAction.EXECUTE);
this.tank.drain(1, IFluidHandler.FluidAction.EXECUTE);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public MagmatorScreen(MagmatorContainer container, Inventory inv, Component titl
"info.lollipop.fluid",
(content, lines) -> {
lines.add(Component.translatable("info.lollipop.Gain").withStyle(ChatFormatting.GRAY).append(Text.COLON)
.append(Component.translatable("info.lollipop.fe.per.mb", PowahAPI.getMagmaticFluidHeat(content.getFluid()), "100")
.append(Component
.translatable("info.lollipop.fe.per.mb", PowahAPI.getMagmaticFluidEnergyProduced(content.getFluid()), "100")
.withStyle(ChatFormatting.DARK_GRAY)));
});
}
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/owmii/powah/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@ public static int bucketAmount() {
return 1000;
}

/**
* Amount of fluid in one millibucket.
* 1 on Forge.
*/
public static int millibucketAmount() {
return (int) (Util.bucketAmount() / 1000);
}

public static long amountToMillibuckets(long amount) {
var result = amount * 1000 / Util.bucketAmount();
if (result == 0 && amount != 0) {
Expand Down

0 comments on commit fe13cf9

Please sign in to comment.