Skip to content

Commit

Permalink
prepped small heat exchanger to have different tiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Nov 7, 2024
1 parent 241311d commit 3e53a89
Showing 1 changed file with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import muramasa.antimatter.recipe.IRecipe;
import muramasa.antimatter.util.Utils;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -21,8 +22,9 @@

public class BlockEntitySmallHeatExchanger extends BlockEntitySecondaryOutput<BlockEntitySmallHeatExchanger> {
boolean hadNoWater = false;
int rate = 16;

public BlockEntitySmallHeatExchanger(Machine type, BlockPos pos, BlockState state) {
public BlockEntitySmallHeatExchanger(Machine<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
heatHandler.set(() -> new DefaultHeatHandler(this, Integer.MAX_VALUE, 80, 0));
recipeHandler.set(() -> new MachineRecipeHandler<>(this){
Expand All @@ -34,17 +36,12 @@ protected boolean validateRecipe(IRecipe r) {

@Override
protected boolean canRecipeContinue() {
return super.canRecipeContinue() && heatHandler.map(h -> h.getHeat() + (activeRecipe.getTotalPower()) <= h.getHeatCap()).orElse(false);
return super.canRecipeContinue() && heatHandler.map(h -> h.getHeat() < rate * 2).orElse(false);
}

@Override
public boolean consumeResourceForRecipe(boolean simulate) {
return tile.heatHandler.map(e -> e.insert((int) getPower() / 5, simulate) >= getPower() / 5).orElse(false);
}

@Override
protected void calculateDurations() {
maxProgress = activeRecipe.getDuration() * 5;
return tile.heatHandler.map(e -> e.insert((int) getPower(), simulate) >= getPower()).orElse(false);
}

@Override
Expand All @@ -60,18 +57,27 @@ public boolean canFluidBeAutoOutput(FluidHolder fluid) {
});
}

int steamHeat = 0;

@Override
public void serverTick(Level level, BlockPos pos, BlockState state) {
super.serverTick(level, pos, state);
heatHandler.ifPresent(h -> {
if (h.getHeat() > 0){
int tempRate = Math.min(h.getHeat(), rate);
steamHeat += tempRate;
h.extractInternal(tempRate, false);
}
});
if (level.getGameTime() % 20 == 0){
fluidHandler.ifPresent(f -> {
heatHandler.ifPresent(h -> {
if (h.getHeat() >= 2560){
Utils.createExplosion(this.level, worldPosition, 6.0F, Explosion.BlockInteraction.DESTROY);
return;
}
if (h.getHeat() >= 80){
int heatMultiplier = Math.min(6, h.getHeat() / 80);
if (steamHeat >= 80){
int heatMultiplier = Math.min(6, steamHeat / 80);
int waterToExtract = 0;
int waterTankId = f.getInputTanks().getFirstAvailableTank(DistilledWater.getLiquid(1), true);
if (waterTankId < 0){
Expand Down Expand Up @@ -100,7 +106,7 @@ public void serverTick(Level level, BlockPos pos, BlockState state) {
waterToExtract = Math.min(waterToExtract, successfulSteam);
waterTank.internalExtract(Utils.ca(waterToExtract, waterTank.getStoredFluid()), false);
f.getOutputTanks().internalInsert(steam.getGas(waterToExtract * waterMultiplier), false);
h.extractInternal(waterToExtract * 80, false);
steamHeat -= waterToExtract * 80;
}
hadNoWater = false;
} else {
Expand All @@ -113,4 +119,16 @@ public void serverTick(Level level, BlockPos pos, BlockState state) {
}

}

@Override
public void load(CompoundTag tag) {
super.load(tag);
steamHeat = tag.getInt("steamHeat");
}

@Override
public void saveAdditional(CompoundTag tag) {
super.saveAdditional(tag);
tag.putInt("steamHeat", steamHeat);
}
}

0 comments on commit 3e53a89

Please sign in to comment.