Require lit campfires for soup cooking and bubble heated cauldrons

This commit is contained in:
2026-09-10 13:41:42 +03:00
parent 860b7a678e
commit cee738506d
8 changed files with 83 additions and 9 deletions
@@ -0,0 +1,34 @@
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);
}
}
@@ -137,7 +137,7 @@ public final class SoupPots implements AutoCloseable {
}
pot = Pot.raw(List.of());
}
if (pot.brewing()) { say(player, "Суп варится… Осталось: " + Math.max(1, (pot.brewTicks - elapsed.getOrDefault(pos, 0) + 19) / 20) + " с."); return true; }
if (pot.brewing()) { say(player, CauldronHeat.heated(level, blockPos) ? "Суп варится… Осталось: " + Math.max(1, (pot.brewTicks - elapsed.getOrDefault(pos, 0) + 19) / 20) + " с." : "Варка приостановлена. Зажгите костёр под котлом."); return true; }
if (pot.ready()) {
if (!held.is(Items.BOWL)) { say(player, "Суп готов. Порций: " + pot.servings + ". Возьмите его миской — ПКМ."); return true; }
int left = pot.servings - 1; var result = pot.soup.copy();
@@ -149,6 +149,7 @@ public final class SoupPots implements AutoCloseable {
say(player, left == 0 ? "Последняя порция собрана. Котёл пуст." : "Осталось порций: " + left + "."); return true;
}
if (pot.items.size() == 4 && (player.isShiftKeyDown() || !held.isEmpty())) {
if (!CauldronHeat.heated(level, blockPos)) { say(player, "Для варки нужен горящий костёр прямо под котлом."); return true; }
String rejection = ingredients.rejection(pot.items);
if (rejection != null) { say(player, rejection + " ПКМ пустой рукой возвращает последний ингредиент."); return true; }
var next = new Pot(pot.items, ingredients.brew(pot.items), (int)Math.round(config.brewSeconds * 20), config.servingsPerBrew, config.servingsPerBrew);
@@ -185,7 +186,8 @@ public final class SoupPots implements AutoCloseable {
var level = server.getLevel(ResourceKey.create(Registries.DIMENSION, Identifier.parse(pos.dimension)));
if (level == null || !level.hasChunkAt(pos.pos)) { removeVisuals(pos); continue; }
if (!valid(level.getBlockState(pos.pos), pot)) { breakPot(level, pos.pos); continue; }
if (pot.brewing()) {
boolean heated = CauldronHeat.heated(level, pos.pos);
if (pot.brewing() && heated) {
int time = elapsed.merge(pos, 1, Integer::sum);
if (time >= pot.brewTicks && (time - pot.brewTicks) % 20 == 0
&& change(pos, new Pot(List.of(), pot.soup, 0, pot.servings, pot.capacity))) {
@@ -199,9 +201,7 @@ public final class SoupPots implements AutoCloseable {
if (ticks % 2 == 0 && !pot.ready()) {
var displays = visuals.get(pos);
int water = level.getBlockState(pos.pos).getValue(LayeredCauldronBlock.LEVEL);
for (int i = 0; i < displays.size(); i++) displays.get(i).ingredient(i, water, ticks + 2, elapsed.getOrDefault(pos, 0) + 2, pot.brewTicks);
if (pot.brewing() && ticks % 10 == 0)
level.sendParticles(ParticleTypes.SPLASH, pos.pos.getX() + .5, pos.pos.getY() + .95, pos.pos.getZ() + .5, 2, .2, 0, .2, 0);
for (int i = 0; i < displays.size(); i++) displays.get(i).ingredient(i, water, ticks + 2, elapsed.getOrDefault(pos, 0) + (heated ? 2 : 0), pot.brewTicks);
}
}
if (ticks % 20 == 0) for (var player : server.getPlayerList().getPlayers()) {
@@ -0,0 +1,20 @@
package online.astradev.cauldron.mixin;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.crafting.*;
import net.minecraft.world.level.block.entity.CampfireBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(CampfireBlockEntity.class)
public abstract class CampfireHeatMixin {
@Inject(method = "cookTick", at = @At("TAIL"))
private static void astracauldron$heat(ServerLevel level, BlockPos pos, BlockState state, CampfireBlockEntity entity,
RecipeManager.CachedCheck<SingleRecipeInput, CampfireCookingRecipe> recipes, CallbackInfo ci) {
online.astradev.cauldron.CauldronHeat.tick(level, pos);
}
}
+1 -1
View File
@@ -2,6 +2,6 @@
"required": true,
"package": "online.astradev.cauldron.mixin",
"compatibilityLevel": "JAVA_25",
"server": ["CauldronWeatherMixin", "LayeredCauldronMixin", "SoupStackMixin"],
"server": ["CauldronWeatherMixin", "LayeredCauldronMixin", "SoupStackMixin", "CampfireHeatMixin"],
"injectors": {"defaultRequire": 1}
}