Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ramping heat to the Thermalily #4665

Open
wants to merge 3 commits into
base: 1.20.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.tags.FluidTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BucketPickup;
import net.minecraft.world.level.block.entity.BlockEntityType;
Expand All @@ -37,15 +38,24 @@ public abstract class FluidGeneratorBlockEntity extends GeneratingFlowerBlockEnt
public static final int DECAY_TIME = 72000;
protected int burnTime, cooldown;
private final TagKey<Fluid> consumedFluid;
protected final int startBurnTime, manaPerTick;
protected final int startBurnTime;
private final Block allowedCaldron;

protected FluidGeneratorBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state, TagKey<Fluid> consumedFluid, int startBurnTime, int manaPerTick) {
protected FluidGeneratorBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state, TagKey<Fluid> consumedFluid, int startBurnTime) {
super(type, pos, state);
this.consumedFluid = consumedFluid;
this.startBurnTime = startBurnTime;
this.manaPerTick = manaPerTick;
if (consumedFluid.equals(FluidTags.WATER)) {
allowedCaldron = Blocks.WATER_CAULDRON;
} else if (consumedFluid.equals(FluidTags.LAVA)) {
allowedCaldron = Blocks.LAVA_CAULDRON;
} else {
allowedCaldron = null;
}
}

public abstract int manaPerTick();

@Override
public void tickFlower() {
super.tickFlower();
Expand All @@ -60,7 +70,7 @@ public void tickFlower() {

if (!getLevel().isClientSide) {
if (burnTime > 0 && ticksExisted % getGenerationDelay() == 0) {
addMana(manaPerTick);
addMana(manaPerTick());
sync();
}
}
Expand All @@ -75,8 +85,10 @@ public void tickFlower() {

BlockState bstate = getLevel().getBlockState(pos);
FluidState fstate = getLevel().getFluidState(pos);
if (fstate.is(consumedFluid) && fstate.isSource()) {
if (consumedFluid != FluidTags.WATER) {
if ((fstate.is(consumedFluid) && fstate.isSource()) || bstate.is(allowedCaldron)) {
if (bstate.is(allowedCaldron)) {
getLevel().setBlockAndUpdate(pos, Blocks.CAULDRON.defaultBlockState());
} else if (consumedFluid != FluidTags.WATER) {
getLevel().setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
} else {
int waterAround = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ public class HydroangeasBlockEntity extends FluidGeneratorBlockEntity {
private int passiveDecayTicks;

public HydroangeasBlockEntity(BlockPos pos, BlockState state) {
super(BotaniaFlowerBlocks.HYDROANGEAS, pos, state, FluidTags.WATER, 40, 1);
super(BotaniaFlowerBlocks.HYDROANGEAS, pos, state, FluidTags.WATER, 40);
}

@Override
public int manaPerTick() {
return 1;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,31 @@
import net.minecraft.nbt.CompoundTag;
import net.minecraft.sounds.SoundSource;
import net.minecraft.tags.FluidTags;
import net.minecraft.util.Mth;
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;
public static final int FAST_PROVIDE_TICKS = 10;
public static final int MAX_HEAT = 25;

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 };
private int ticksSinceFueled = 0;
private int heat;

public ThermalilyBlockEntity(BlockPos pos, BlockState state) {
super(BotaniaFlowerBlocks.THERMALILY, pos, state, FluidTags.LAVA, 600, 45);
super(BotaniaFlowerBlocks.THERMALILY, pos, state, FluidTags.LAVA, 600);
}

@Override
public int manaPerTick() {
return 45 + heat * 2;
}

@Override
Expand All @@ -45,22 +48,7 @@ public int getCooldownTime(boolean finishedPrevious) {
}

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 >= 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;
return Math.min(Math.max(Math.round(Mth.normal(random, 10 - bias / 3, 4 - bias / 10)), 1), 15);
}

@Override
Expand All @@ -70,7 +58,7 @@ public void tickFlower() {
ticksSinceFueled++;
} else if (burnTime == startBurnTime) {
if (ticksSinceFueled <= FAST_PROVIDE_TICKS) {
heat = heat < 10 ? heat + 1 : heat;
heat = heat < MAX_HEAT ? heat + 1 : heat;
} else {
heat = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell, this is the only place where heat is reset. If lava is provided before the end of the cooldown, the cooldown restarts (as intended), but heat does not reset. I'm not sure if that's a bad thing, as lava is still wasted, so fine by me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally I would have made it so that providing lava before the end of the cooldown would cause the thermalily to "burn" into a dead bush, but that would require either changing the logic in FluidGeneratingFlower (doable, requires some refactoring and moving of code), or use the call to getCooldownTime(false), (janky and prone to errors if other mods/addons/code calls that).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think just resetting the heat is an ok penalty here

}
Expand Down
Loading