63 lines
3.1 KiB
Java
63 lines
3.1 KiB
Java
package online.astradev.cauldron.mixing;
|
|||
|
|
|
||
|
|
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 MixingHeat {
|
||
|
|
private MixingHeat() {}
|
||
|
|
|
||
|
|
public static boolean heated(LevelReader level, BlockPos cauldron) {
|
||
|
|
if (!MixingCapabilities.active()) return false;
|
||
|
|
var below = cauldron.below();
|
||
|
|
if (!level.hasChunkAt(below)) return false;
|
||
|
|
var state = level.getBlockState(below);
|
||
|
|
return (state.is(MixingCapabilities.runtime().block("normalHeat")) || state.is(MixingCapabilities.runtime().block("soulHeat")))
|
||
|
|
&& state.hasProperty(CampfireBlock.LIT) && state.getValue(CampfireBlock.LIT);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static void tick(ServerLevel level, BlockPos campfire) {
|
||
|
|
if (!MixingCapabilities.active() || !MixingCapabilities.config().particles) return;
|
||
|
|
var runtime = MixingCapabilities.runtime();
|
||
|
|
var pos = campfire.above();
|
||
|
|
if ((level.getGameTime() + pos.asLong()) % runtime.integer("heatParticleIntervalTicks") != 0 || !heated(level, pos)) return;
|
||
|
|
var state = level.getBlockState(pos);
|
||
|
|
double surface;
|
||
|
|
if (state.is(MixingCapabilities.runtime().block("waterContainer")))
|
||
|
|
surface = runtime.decimal("waterBaseHeight") + runtime.decimal("waterStepHeight") * state.getValue(LayeredCauldronBlock.LEVEL);
|
||
|
|
else {
|
||
|
|
var pot = MixingCapabilities.pots() == null ? null : MixingCapabilities.pots().get(level, pos);
|
||
|
|
if (!state.is(MixingCapabilities.runtime().block("emptyContainer"))
|
||
|
|
|| pot == null
|
||
|
|
|| pot.soup().isEmpty()
|
||
|
|
|| pot.brewTicks() > 0) return;
|
||
|
|
surface = MixingAnimation.liquidHeight(pot.servings(), pot.capacity());
|
||
|
|
}
|
||
|
|
level.sendParticles(
|
||
|
|
runtime.particle("heatBubbleParticle"),
|
||
|
|
pos.getX() + .5,
|
||
|
|
pos.getY() + surface + runtime.decimal("heatBubbleOffset"),
|
||
|
|
pos.getZ() + .5,
|
||
|
|
runtime.integer("heatBubbleCount"),
|
||
|
|
runtime.decimal("heatBubbleHorizontal"),
|
||
|
|
runtime.decimal("heatBubbleVertical"),
|
||
|
|
runtime.decimal("heatBubbleHorizontal"),
|
||
|
|
runtime.decimal("heatBubbleSpeed"));
|
||
|
|
level.sendParticles(
|
||
|
|
runtime.particle("heatSplashParticle"),
|
||
|
|
pos.getX() + .5,
|
||
|
|
pos.getY() + surface + runtime.decimal("heatSplashOffset"),
|
||
|
|
pos.getZ() + .5,
|
||
|
|
runtime.integer("heatSplashCount"),
|
||
|
|
runtime.decimal("heatSplashHorizontal"),
|
||
|
|
runtime.decimal("heatSplashVertical"),
|
||
|
|
runtime.decimal("heatSplashHorizontal"),
|
||
|
|
runtime.decimal("heatSplashSpeed"));
|
||
|
|
}
|
||
|
|
}
|