2026-09-08 19:44:45 +03:00
|
|
|
package online.astradev.cauldron;
|
|
|
|
|
|
|
|
|
|
import com.google.gson.*;
|
2026-09-13 20:05:38 +03:00
|
|
|
|
2026-09-08 19:44:45 +03:00
|
|
|
import net.minecraft.ChatFormatting;
|
|
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
|
import net.minecraft.core.registries.Registries;
|
|
|
|
|
import net.minecraft.network.chat.Component;
|
|
|
|
|
import net.minecraft.resources.*;
|
|
|
|
|
import net.minecraft.server.MinecraftServer;
|
|
|
|
|
import net.minecraft.server.level.*;
|
|
|
|
|
import net.minecraft.sounds.*;
|
|
|
|
|
import net.minecraft.world.InteractionHand;
|
|
|
|
|
import net.minecraft.world.item.*;
|
|
|
|
|
import net.minecraft.world.item.alchemy.Potions;
|
|
|
|
|
import net.minecraft.world.level.block.*;
|
|
|
|
|
import net.minecraft.world.level.storage.LevelResource;
|
2026-09-13 20:05:38 +03:00
|
|
|
|
2026-09-08 19:44:45 +03:00
|
|
|
import online.astradev.plus.api.*;
|
|
|
|
|
|
2026-09-13 20:05:38 +03:00
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.nio.file.*;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Persistent dyed water and potion storage; all item transformations and rendering use AstraPlus
|
|
|
|
|
* API.
|
|
|
|
|
*/
|
2026-09-08 19:44:45 +03:00
|
|
|
public final class LiquidPots implements AutoCloseable {
|
|
|
|
|
private record Position(String dimension, BlockPos pos) {
|
2026-09-13 20:05:38 +03:00
|
|
|
static Position at(ServerLevel level, BlockPos pos) {
|
|
|
|
|
return new Position(level.dimension().identifier().toString(), pos.immutable());
|
|
|
|
|
}
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
2026-09-13 20:05:38 +03:00
|
|
|
|
2026-09-08 19:44:45 +03:00
|
|
|
public record Liquid(int levels, int rgb, CauldronApi.Potion potion) {
|
|
|
|
|
public Liquid {
|
2026-09-13 20:05:38 +03:00
|
|
|
if (levels < 1 || levels > 3 || rgb < 0 || rgb > 0xFFFFFF)
|
|
|
|
|
throw new IllegalArgumentException("Invalid liquid");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Liquid withLevels(int value) {
|
|
|
|
|
return new Liquid(value, rgb, potion);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String source() {
|
|
|
|
|
if (potion == null) return "dyed_water";
|
|
|
|
|
return potion.contents()
|
|
|
|
|
.potion()
|
|
|
|
|
.flatMap(holder -> holder.unwrapKey())
|
|
|
|
|
.map(key -> key.identifier().toString())
|
|
|
|
|
.orElse("astracauldron:custom_potion");
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
|
|
|
|
}
|
2026-09-13 20:05:38 +03:00
|
|
|
|
2026-09-08 19:44:45 +03:00
|
|
|
private static final Identifier OWNER = Identifier.parse("astracauldron:liquids");
|
|
|
|
|
private final MinecraftServer server;
|
|
|
|
|
private final CauldronApi api;
|
|
|
|
|
private final Path file;
|
|
|
|
|
private final Map<Position, Liquid> liquids = new LinkedHashMap<>();
|
2026-09-13 20:05:38 +03:00
|
|
|
|
2026-09-08 19:44:45 +03:00
|
|
|
public LiquidPots(MinecraftServer server) throws IOException {
|
|
|
|
|
this.server = server;
|
|
|
|
|
api = AstraPlusApi.current().flatMap(AstraPlusApi::cauldrons).orElseThrow();
|
|
|
|
|
file = server.getWorldPath(LevelResource.ROOT).resolve("astracauldron/liquids.json");
|
|
|
|
|
if (Files.exists(file)) {
|
|
|
|
|
var json = JsonParser.parseString(Files.readString(file)).getAsJsonObject();
|
2026-09-13 20:05:38 +03:00
|
|
|
if (json.get("version").getAsInt() != 1)
|
|
|
|
|
throw new IllegalArgumentException("Unknown liquid data version");
|
2026-09-08 19:44:45 +03:00
|
|
|
for (var entry : json.getAsJsonArray("cauldrons")) {
|
|
|
|
|
var c = entry.getAsJsonObject();
|
2026-09-13 20:05:38 +03:00
|
|
|
var pos =
|
|
|
|
|
new Position(
|
|
|
|
|
Identifier.parse(c.get("dimension").getAsString()).toString(),
|
|
|
|
|
new BlockPos(
|
|
|
|
|
c.get("x").getAsInt(),
|
|
|
|
|
c.get("y").getAsInt(),
|
|
|
|
|
c.get("z").getAsInt()));
|
|
|
|
|
CauldronApi.Potion potion =
|
|
|
|
|
c.has("potion")
|
|
|
|
|
? api.potion(
|
|
|
|
|
SoupFiles.decode(
|
|
|
|
|
c.get("potion"), server.registryAccess()))
|
|
|
|
|
.orElseThrow()
|
|
|
|
|
: null;
|
|
|
|
|
var liquid =
|
|
|
|
|
new Liquid(c.get("levels").getAsInt(), c.get("rgb").getAsInt(), potion);
|
|
|
|
|
if (liquids.putIfAbsent(pos, liquid) != null)
|
|
|
|
|
throw new IllegalArgumentException("Duplicate liquid cauldron");
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-09-13 20:05:38 +03:00
|
|
|
|
|
|
|
|
public Liquid get(ServerLevel level, BlockPos pos) {
|
|
|
|
|
return liquids.get(Position.at(level, pos));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean contains(ServerLevel level, BlockPos pos) {
|
|
|
|
|
return get(level, pos) != null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean applyRecipe(ServerLevel level, BlockPos blockPos, int remaining, Integer color) {
|
|
|
|
|
var pos = Position.at(level, blockPos);
|
|
|
|
|
var previous = liquids.get(pos);
|
|
|
|
|
if (remaining < 0 || remaining > 3)
|
|
|
|
|
throw new IllegalArgumentException("Invalid remaining liquid");
|
|
|
|
|
Liquid next = null;
|
|
|
|
|
if (remaining > 0) {
|
|
|
|
|
int rgb = color == null ? Objects.requireNonNull(previous).rgb : color;
|
|
|
|
|
next = new Liquid(remaining, rgb, previous == null ? null : previous.potion);
|
|
|
|
|
}
|
|
|
|
|
if (!change(pos, next)) return false;
|
|
|
|
|
level.setBlock(blockPos, Blocks.CAULDRON.defaultBlockState(), 3);
|
|
|
|
|
if (next != null) setVisual(level, pos, next);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-08 19:44:45 +03:00
|
|
|
private boolean change(Position pos, Liquid next) {
|
|
|
|
|
var old = liquids.get(pos);
|
2026-09-13 20:05:38 +03:00
|
|
|
if (next == null) liquids.remove(pos);
|
|
|
|
|
else liquids.put(pos, next);
|
2026-09-08 19:44:45 +03:00
|
|
|
try {
|
2026-09-13 20:05:38 +03:00
|
|
|
var root = new JsonObject();
|
|
|
|
|
root.addProperty("version", 1);
|
|
|
|
|
var array = new JsonArray();
|
|
|
|
|
root.add("cauldrons", array);
|
2026-09-08 19:44:45 +03:00
|
|
|
for (var entry : liquids.entrySet()) {
|
2026-09-13 20:05:38 +03:00
|
|
|
var p = entry.getKey();
|
|
|
|
|
var liquid = entry.getValue();
|
|
|
|
|
var c = new JsonObject();
|
|
|
|
|
c.addProperty("dimension", p.dimension);
|
|
|
|
|
c.addProperty("x", p.pos.getX());
|
|
|
|
|
c.addProperty("y", p.pos.getY());
|
|
|
|
|
c.addProperty("z", p.pos.getZ());
|
|
|
|
|
c.addProperty("levels", liquid.levels);
|
|
|
|
|
c.addProperty("rgb", liquid.rgb);
|
|
|
|
|
if (liquid.potion != null)
|
|
|
|
|
c.add(
|
|
|
|
|
"potion",
|
|
|
|
|
SoupFiles.encode(api.bottle(liquid.potion), server.registryAccess()));
|
2026-09-08 19:44:45 +03:00
|
|
|
array.add(c);
|
|
|
|
|
}
|
|
|
|
|
SoupFiles.write(file, root);
|
|
|
|
|
if (next == null) removeSurface(pos);
|
|
|
|
|
return true;
|
|
|
|
|
} catch (Exception e) {
|
2026-09-13 20:05:38 +03:00
|
|
|
if (old == null) liquids.remove(pos);
|
|
|
|
|
else liquids.put(pos, old);
|
|
|
|
|
AstraCauldron.LOG.error("Не удалось сохранить жидкость; действие отменено", e);
|
|
|
|
|
return false;
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
|
|
|
|
}
|
2026-09-13 20:05:38 +03:00
|
|
|
|
2026-09-08 19:44:45 +03:00
|
|
|
public boolean interact(ServerPlayer player, BlockPos blockPos, InteractionHand hand) {
|
|
|
|
|
if (player.isSpectator()) return false;
|
2026-09-13 20:05:38 +03:00
|
|
|
var level = player.level();
|
|
|
|
|
var pos = Position.at(level, blockPos);
|
|
|
|
|
var liquid = liquids.get(pos);
|
2026-09-08 19:44:45 +03:00
|
|
|
if (hand != InteractionHand.MAIN_HAND) return liquid != null;
|
2026-09-13 20:05:38 +03:00
|
|
|
var state = level.getBlockState(blockPos);
|
|
|
|
|
var held = player.getMainHandItem();
|
2026-09-08 19:44:45 +03:00
|
|
|
if (!state.is(Blocks.CAULDRON) && !state.is(Blocks.WATER_CAULDRON)) return false;
|
|
|
|
|
var potion = api.potion(held);
|
|
|
|
|
if (liquid == null) {
|
|
|
|
|
if (potion.isPresent() && plainWater(potion.get())) {
|
2026-09-13 20:05:38 +03:00
|
|
|
int current =
|
|
|
|
|
state.is(Blocks.WATER_CAULDRON)
|
|
|
|
|
? state.getValue(LayeredCauldronBlock.LEVEL)
|
|
|
|
|
: 0;
|
2026-09-08 19:44:45 +03:00
|
|
|
if (current < 3) {
|
2026-09-13 20:05:38 +03:00
|
|
|
level.setBlock(
|
|
|
|
|
blockPos,
|
|
|
|
|
Blocks.WATER_CAULDRON
|
|
|
|
|
.defaultBlockState()
|
|
|
|
|
.setValue(LayeredCauldronBlock.LEVEL, current + 1),
|
|
|
|
|
3);
|
|
|
|
|
consumeAndGive(player, 1, new ItemStack(Items.GLASS_BOTTLE));
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
var dye = api.mixDye(OptionalInt.empty(), held);
|
2026-09-13 20:05:38 +03:00
|
|
|
if (AstraCauldron.config().dyeWater
|
|
|
|
|
&& state.is(Blocks.WATER_CAULDRON)
|
|
|
|
|
&& dye.isPresent()) {
|
|
|
|
|
var next =
|
|
|
|
|
new Liquid(
|
|
|
|
|
state.getValue(LayeredCauldronBlock.LEVEL), dye.getAsInt(), null);
|
|
|
|
|
if (!change(pos, next)) {
|
|
|
|
|
error(player);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
held.consume(1, player);
|
|
|
|
|
setVisual(level, pos, next);
|
|
|
|
|
say(
|
|
|
|
|
player,
|
|
|
|
|
"Вода окрашена. Окуните кожаную броню, шерсть или ковры; красители можно"
|
|
|
|
|
+ " смешивать.");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (AstraCauldron.config().storePotions
|
|
|
|
|
&& state.is(Blocks.CAULDRON)
|
|
|
|
|
&& potion.isPresent()) {
|
|
|
|
|
var next =
|
|
|
|
|
new Liquid(1, potion.get().contents().getColor() & 0xFFFFFF, potion.get());
|
|
|
|
|
if (!change(pos, next)) {
|
|
|
|
|
error(player);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
consumeAndGive(player, 1, new ItemStack(Items.GLASS_BOTTLE));
|
|
|
|
|
setVisual(level, pos, next);
|
|
|
|
|
say(player, "Зелье налито: 1/3. Бутылочка — забрать, стрелы — обработать.");
|
|
|
|
|
return true;
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (liquid.potion == null) {
|
|
|
|
|
var dye = api.mixDye(OptionalInt.of(liquid.rgb), held);
|
2026-09-12 14:19:03 +03:00
|
|
|
if (AstraCauldron.config().dyeWater && dye.isPresent()) {
|
2026-09-08 19:44:45 +03:00
|
|
|
var next = new Liquid(liquid.levels, dye.getAsInt(), null);
|
2026-09-13 20:05:38 +03:00
|
|
|
if (!change(pos, next)) {
|
|
|
|
|
error(player);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
held.consume(1, player);
|
|
|
|
|
setVisual(level, pos, next);
|
|
|
|
|
return true;
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
2026-09-12 13:47:11 +03:00
|
|
|
var blocks = api.dyeBlocks(held, liquid.rgb, liquid.levels);
|
2026-09-12 14:19:03 +03:00
|
|
|
if (AstraCauldron.config().dyeBlocks && blocks.isPresent()) {
|
2026-09-13 20:05:38 +03:00
|
|
|
var batch = blocks.get();
|
|
|
|
|
var result = batch.result();
|
|
|
|
|
if (!decrease(level, pos, liquid, batch.levelsUsed())) {
|
|
|
|
|
error(player);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2026-09-12 13:47:11 +03:00
|
|
|
int count = result.getCount();
|
2026-09-13 20:05:38 +03:00
|
|
|
consumeAndGive(player, count, result);
|
|
|
|
|
sound(level, blockPos);
|
|
|
|
|
say(player, "Окрашено предметов: " + count + ".");
|
|
|
|
|
return true;
|
2026-09-12 13:47:11 +03:00
|
|
|
}
|
2026-09-08 19:44:45 +03:00
|
|
|
var armor = api.dyeArmor(held, liquid.rgb);
|
2026-09-12 14:19:03 +03:00
|
|
|
if (AstraCauldron.config().dyeArmor && armor.isPresent()) {
|
2026-09-13 20:05:38 +03:00
|
|
|
if (!decrease(level, pos, liquid, 1)) {
|
|
|
|
|
error(player);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
// Transform the equipped item, including Creative, preserving
|
|
|
|
|
// enchantments/damage/name.
|
|
|
|
|
if (held.getCount() == 1) player.setItemInHand(hand, armor.get());
|
|
|
|
|
else consumeAndGive(player, 1, armor.get());
|
|
|
|
|
sound(level, blockPos);
|
|
|
|
|
say(player, "Броня окрашена. Израсходован один уровень воды.");
|
|
|
|
|
return true;
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
|
|
|
|
if (held.is(Items.WATER_BUCKET)) {
|
2026-09-13 20:05:38 +03:00
|
|
|
if (!change(pos, null)) {
|
|
|
|
|
error(player);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
level.setBlock(
|
|
|
|
|
blockPos,
|
|
|
|
|
Blocks.WATER_CAULDRON
|
|
|
|
|
.defaultBlockState()
|
|
|
|
|
.setValue(LayeredCauldronBlock.LEVEL, 3),
|
|
|
|
|
3);
|
|
|
|
|
consumeAndGive(player, 1, new ItemStack(Items.BUCKET));
|
|
|
|
|
return true;
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
|
|
|
|
if (held.is(Items.BUCKET) && liquid.levels == 3) {
|
2026-09-13 20:05:38 +03:00
|
|
|
if (!decrease(level, pos, liquid, 3)) {
|
|
|
|
|
error(player);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
consumeAndGive(player, 1, new ItemStack(Items.WATER_BUCKET));
|
|
|
|
|
return true;
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
|
|
|
|
if (held.is(Items.GLASS_BOTTLE)) {
|
2026-09-13 20:05:38 +03:00
|
|
|
if (!decrease(level, pos, liquid, 1)) {
|
|
|
|
|
error(player);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
consumeAndGive(
|
|
|
|
|
player,
|
|
|
|
|
1,
|
|
|
|
|
api.bottle(
|
|
|
|
|
new CauldronApi.Potion(
|
|
|
|
|
new net.minecraft.world.item.alchemy.PotionContents(
|
|
|
|
|
Potions.WATER),
|
|
|
|
|
1)));
|
|
|
|
|
return true;
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
2026-09-13 20:05:38 +03:00
|
|
|
say(player, "Цветная вода: " + liquid.levels + "/3. Для варки супа нужна чистая вода.");
|
|
|
|
|
return true;
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
|
|
|
|
if (potion.isPresent()) {
|
2026-09-12 14:19:03 +03:00
|
|
|
if (!AstraCauldron.config().storePotions) return true;
|
2026-09-13 20:05:38 +03:00
|
|
|
if (!potion.get().equals(liquid.potion)) {
|
|
|
|
|
say(player, "В котле другое зелье. Сначала заберите его бутылочками.");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (liquid.levels == 3) {
|
|
|
|
|
say(player, "Котёл уже полон.");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2026-09-08 19:44:45 +03:00
|
|
|
var next = liquid.withLevels(liquid.levels + 1);
|
2026-09-13 20:05:38 +03:00
|
|
|
if (!change(pos, next)) {
|
|
|
|
|
error(player);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
consumeAndGive(player, 1, new ItemStack(Items.GLASS_BOTTLE));
|
|
|
|
|
setVisual(level, pos, next);
|
|
|
|
|
return true;
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
|
|
|
|
if (held.is(Items.GLASS_BOTTLE)) {
|
|
|
|
|
var bottle = api.bottle(liquid.potion);
|
2026-09-13 20:05:38 +03:00
|
|
|
if (!decrease(level, pos, liquid, 1)) {
|
|
|
|
|
error(player);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
consumeAndGive(player, 1, bottle);
|
|
|
|
|
sound(level, blockPos);
|
|
|
|
|
return true;
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
2026-09-13 20:05:38 +03:00
|
|
|
var arrows = api.tipArrows(held, liquid.potion, liquid.levels);
|
2026-09-12 14:19:03 +03:00
|
|
|
if (AstraCauldron.config().tipArrows && arrows.isPresent()) {
|
2026-09-13 20:05:38 +03:00
|
|
|
var batch = arrows.get();
|
|
|
|
|
var result = batch.result();
|
|
|
|
|
if (!decrease(level, pos, liquid, batch.levelsUsed())) {
|
|
|
|
|
error(player);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2026-09-08 19:44:45 +03:00
|
|
|
int count = result.getCount();
|
2026-09-13 20:05:38 +03:00
|
|
|
consumeAndGive(player, count, result);
|
|
|
|
|
sound(level, blockPos);
|
|
|
|
|
say(player, "Обработано стрел: " + count + ".");
|
|
|
|
|
return true;
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
2026-09-13 20:05:38 +03:00
|
|
|
say(
|
|
|
|
|
player,
|
|
|
|
|
"Зелье: " + liquid.levels + "/3. Окуните обычные стрелы или наберите бутылочку.");
|
|
|
|
|
return true;
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
2026-09-13 20:05:38 +03:00
|
|
|
|
2026-09-08 19:44:45 +03:00
|
|
|
private boolean decrease(ServerLevel level, Position pos, Liquid old, int used) {
|
2026-09-13 20:05:38 +03:00
|
|
|
int remaining = old.levels - used;
|
|
|
|
|
var next = remaining == 0 ? null : old.withLevels(remaining);
|
|
|
|
|
if (!change(pos, next)) return false;
|
|
|
|
|
level.setBlock(pos.pos, Blocks.CAULDRON.defaultBlockState(), 3);
|
|
|
|
|
if (next != null) setVisual(level, pos, next);
|
|
|
|
|
return true;
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
2026-09-13 20:05:38 +03:00
|
|
|
|
2026-09-08 19:44:45 +03:00
|
|
|
private static boolean plainWater(CauldronApi.Potion potion) {
|
|
|
|
|
var contents = potion.contents();
|
2026-09-13 20:05:38 +03:00
|
|
|
return contents.is(Potions.WATER)
|
|
|
|
|
&& contents.customColor().isEmpty()
|
|
|
|
|
&& contents.customName().isEmpty()
|
|
|
|
|
&& potion.durationScale() == 1f;
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
2026-09-13 20:05:38 +03:00
|
|
|
|
|
|
|
|
public boolean breakPot(ServerLevel level, BlockPos pos) {
|
|
|
|
|
var position = Position.at(level, pos);
|
|
|
|
|
return !liquids.containsKey(position) || change(position, null);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-08 19:44:45 +03:00
|
|
|
public void tick() {
|
|
|
|
|
for (var entry : new ArrayList<>(liquids.entrySet())) {
|
2026-09-13 20:05:38 +03:00
|
|
|
var pos = entry.getKey();
|
|
|
|
|
var level = level(pos);
|
|
|
|
|
if (level == null || !level.hasChunkAt(pos.pos)) continue;
|
|
|
|
|
if (!level.getBlockState(pos.pos).is(Blocks.CAULDRON)) {
|
|
|
|
|
change(pos, null);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
surface(level, pos, entry.getValue());
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
|
|
|
|
}
|
2026-09-13 20:05:38 +03:00
|
|
|
|
|
|
|
|
private void setVisual(ServerLevel level, Position pos, Liquid liquid) {
|
|
|
|
|
level.setBlock(pos.pos, Blocks.CAULDRON.defaultBlockState(), 3);
|
|
|
|
|
surface(level, pos, liquid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void surface(ServerLevel level, Position pos, Liquid liquid) {
|
|
|
|
|
api.water()
|
|
|
|
|
.show(
|
|
|
|
|
level,
|
|
|
|
|
pos.pos,
|
|
|
|
|
new ColoredWaterApi.Surface(
|
|
|
|
|
OWNER, liquid.rgb, .375f + .1875f * liquid.levels));
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
2026-09-13 20:05:38 +03:00
|
|
|
|
|
|
|
|
private ServerLevel level(Position pos) {
|
|
|
|
|
return server.getLevel(
|
|
|
|
|
ResourceKey.create(Registries.DIMENSION, Identifier.parse(pos.dimension)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void removeSurface(Position pos) {
|
|
|
|
|
var level = level(pos);
|
|
|
|
|
if (level != null) api.water().remove(level, pos.pos, OWNER);
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|
2026-09-13 20:05:38 +03:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void close() {
|
|
|
|
|
api.water().removeAll(OWNER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void consumeAndGive(ServerPlayer player, int count, ItemStack result) {
|
|
|
|
|
player.getMainHandItem().consume(count, player);
|
|
|
|
|
player.getInventory().add(result);
|
|
|
|
|
if (!result.isEmpty()) player.drop(result, false);
|
2026-09-08 19:44:45 +03:00
|
|
|
player.containerMenu.broadcastChanges();
|
|
|
|
|
}
|
2026-09-13 20:05:38 +03:00
|
|
|
|
|
|
|
|
private static void sound(ServerLevel level, BlockPos pos) {
|
|
|
|
|
var config = AstraCauldron.config();
|
|
|
|
|
if (config.sounds)
|
|
|
|
|
level.playSound(
|
|
|
|
|
null, pos, SoundEvents.BOTTLE_FILL, SoundSource.BLOCKS, config.soundVolume, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void say(ServerPlayer player, String text) {
|
|
|
|
|
var config = AstraCauldron.config();
|
|
|
|
|
if (config.messages)
|
|
|
|
|
player.sendSystemMessage(
|
|
|
|
|
Component.literal(config.messageOverrides.getOrDefault(text, text))
|
|
|
|
|
.withStyle(ChatFormatting.GOLD),
|
|
|
|
|
true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void error(ServerPlayer player) {
|
|
|
|
|
say(player, "Не удалось сохранить котёл. Действие отменено.");
|
|
|
|
|
}
|
2026-09-08 19:44:45 +03:00
|
|
|
}
|