Skip to content

Commit

Permalink
Thermalily and Hydroangea now can consume fluids from caldrons, and t…
Browse files Browse the repository at this point in the history
…he Thermalily's cooldown is based on the normal distribution
  • Loading branch information
NEstoll committed Jun 10, 2024
1 parent 3f00ea6 commit 7d859c3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
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;
}
Expand Down

0 comments on commit 7d859c3

Please sign in to comment.