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 2 commits
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;
private 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,6 +12,7 @@
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.state.BlockState;

Expand All @@ -22,39 +23,47 @@
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 = 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 };
public static final int COOLDOWN_ROLL_TOTAL;
private int ticksSinceFueled = 0;
private int heat;

static {
int acc = 0;
for (var i : COOLDOWN_ROLL_PDF) {
acc += i;
}
COOLDOWN_ROLL_TOTAL = acc;
public ThermalilyBlockEntity(BlockPos pos, BlockState state) {
super(BotaniaFlowerBlocks.THERMALILY, pos, state, FluidTags.LAVA, 600);
}

public ThermalilyBlockEntity(BlockPos pos, BlockState state) {
super(BotaniaFlowerBlocks.THERMALILY, pos, state, FluidTags.LAVA, 600, 45);
@Override
public int manaPerTick() {
return 45 + heat * 2;
}

@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);
var index = 0;
while (total >= COOLDOWN_ROLL_PDF[index]) {
total -= COOLDOWN_ROLL_PDF[index];
index++;
public static int rollNewCooldownStrength(RandomSource random, int bias) {
return Math.min(Math.max(Math.round(Mth.normal(random, 10 - bias / 3, 4 - bias / 10)), 1), 15);
}

@Override
public void tickFlower() {
super.tickFlower();
if (burnTime == 0 && cooldown == 0) {
ticksSinceFueled++;
} else if (burnTime == startBurnTime) {
if (ticksSinceFueled <= FAST_PROVIDE_TICKS) {
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

}
ticksSinceFueled = 0;
}
return index + 1;
}

@Override
Expand Down
Loading