Files
AstraCauldron/src/main/java/online/astradev/cauldron/CauldronHeat.java
T

35 lines
1.8 KiB
Java
Raw Normal View History

package online.astradev.cauldron;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.CampfireBlock;
import net.minecraft.world.level.block.LayeredCauldronBlock;
/** Uses the existing campfire ticker; no scanning worlds or spawning persistent effects. */
public final class CauldronHeat {
private CauldronHeat() {}
public static boolean heated(LevelReader level, BlockPos cauldron) {
var below = cauldron.below();
if (!level.hasChunkAt(below)) return false;
var state = level.getBlockState(below);
return state.getBlock() instanceof CampfireBlock && state.getValue(CampfireBlock.LIT);
}
public static void tick(ServerLevel level, BlockPos campfire) {
var pos = campfire.above();
if ((level.getGameTime() + pos.asLong()) % 10 != 0 || !heated(level, pos)) return;
var state = level.getBlockState(pos);
double surface;
if (state.is(Blocks.WATER_CAULDRON)) surface = .375 + .1875 * state.getValue(LayeredCauldronBlock.LEVEL);
else {
var pot = AstraCauldron.pots() == null ? null : AstraCauldron.pots().get(level, pos);
if (!state.is(Blocks.CAULDRON) || pot == null || pot.soup().isEmpty() || pot.brewTicks() > 0) return;
surface = CauldronAnimation.liquidHeight(pot.servings(), pot.capacity());
}
level.sendParticles(ParticleTypes.BUBBLE_POP, pos.getX() + .5, pos.getY() + surface + .01, pos.getZ() + .5, 4, .18, .015, .18, 0);
level.sendParticles(ParticleTypes.SPLASH, pos.getX() + .5, pos.getY() + surface + .02, pos.getZ() + .5, 2, .16, 0, .16, 0);
}
}