Skip to content

Commit

Permalink
Add ramping heat to the Thermalily, decreasing the average cooldown i…
Browse files Browse the repository at this point in the history
…f lava is provided promptly
  • Loading branch information
NEstoll committed Jun 5, 2024
1 parent 50d6a7c commit 3f00ea6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public abstract class FluidGeneratorBlockEntity extends GeneratingFlowerBlockEnt
public static final int DECAY_TIME = 72000;
protected int burnTime, cooldown;
private final TagKey<Fluid> consumedFluid;
private final int startBurnTime, manaPerTick;
protected final int startBurnTime, manaPerTick;

protected FluidGeneratorBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state, TagKey<Fluid> consumedFluid, int startBurnTime, int manaPerTick) {
super(type, pos, state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,24 @@
import net.minecraft.sounds.SoundSource;
import net.minecraft.tags.FluidTags;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;

import vazkii.botania.client.fx.WispParticleData;
import vazkii.botania.common.block.BotaniaFlowerBlocks;
import vazkii.botania.common.handler.BotaniaSounds;

import java.util.Arrays;

public class ThermalilyBlockEntity extends FluidGeneratorBlockEntity {
public static final int COOLDOWN_TICKS_MULTIPLER = 400;
public static final String TAG_COOLDOWN_MAGNITUDE = "cooldownStrength";
public static final int FAST_PROVIDE_TICKS = 200;

private int cooldownStrength = 15;
public static final int[] COOLDOWN_ROLL_PDF = { 10, 5, 3, 2, 1, 1, 3, 3, 3, 2, 1, 1, 1, 2, 2 };
public static final int COOLDOWN_ROLL_TOTAL;

static {
int acc = 0;
for (var i : COOLDOWN_ROLL_PDF) {
acc += i;
}
COOLDOWN_ROLL_TOTAL = acc;
}
private int ticksSinceFueled = 0;
private int heat;

public ThermalilyBlockEntity(BlockPos pos, BlockState state) {
super(BotaniaFlowerBlocks.THERMALILY, pos, state, FluidTags.LAVA, 600, 45);
Expand All @@ -42,21 +39,45 @@ public ThermalilyBlockEntity(BlockPos pos, BlockState state) {
@Override
public int getCooldownTime(boolean finishedPrevious) {
if (finishedPrevious) {
cooldownStrength = rollNewCooldownStrength(getLevel().getRandom());
cooldownStrength = rollNewCooldownStrength(getLevel().getRandom(), heat);
}
return COOLDOWN_TICKS_MULTIPLER * cooldownStrength;
}

public static int rollNewCooldownStrength(RandomSource random) {
var total = random.nextInt(COOLDOWN_ROLL_TOTAL);
public static int rollNewCooldownStrength(RandomSource random, int bias) {
int[] weights = weightCooldown(COOLDOWN_ROLL_PDF, bias);
var total = random.nextInt(Arrays.stream(weights).sum());
var index = 0;
while (total >= COOLDOWN_ROLL_PDF[index]) {
total -= COOLDOWN_ROLL_PDF[index];
while (total >= weights[index]) {
total -= weights[index];
index++;
}
return index + 1;
}

public static int[] weightCooldown(int[] originalWeights, int amount) {
int[] result = new int[originalWeights.length];
for (int i = 0; i < originalWeights.length; i++) {
result[i] = (int) Math.max(Math.ceil(originalWeights[i] * (12 - amount - Math.sqrt(originalWeights[i]))), 0);
}
return result;
}

@Override
public void tickFlower() {
super.tickFlower();
if (burnTime == 0 && cooldown == 0) {
ticksSinceFueled++;
} else if (burnTime == startBurnTime) {
if (ticksSinceFueled <= FAST_PROVIDE_TICKS) {
heat = heat < 10 ? heat + 1 : heat;
} else {
heat = 0;
}
ticksSinceFueled = 0;
}
}

@Override
public int getColor() {
return 0xD03C00;
Expand Down

0 comments on commit 3f00ea6

Please sign in to comment.