Apply editor cauldron recipes with native liquid consumption

This commit is contained in:
2026-09-08 22:43:03 +03:00
parent a82c2aa0f9
commit 43c3222fcb
5 changed files with 50 additions and 4 deletions
@@ -63,6 +63,9 @@ public final class AstraCauldron {
}
private void interact(PlayerInteractEvent.RightClickBlock event) {
if (pots == null || event.isCanceled() || event.getUseBlock() == TriState.FALSE || event.getUseItem() == TriState.FALSE) return;
if (event.getEntity() instanceof ServerPlayer player && EditorCauldronRecipes.interact(player, event.getPos(), event.getHand())) {
event.setCanceled(true); event.setCancellationResult(InteractionResult.SUCCESS); return;
}
if (event.getEntity() instanceof ServerPlayer player && ((!pots.contains(player.level(),event.getPos()) && liquids != null
&& liquids.interact(player,event.getPos(),event.getHand())) || pots.interact(player, event.getPos(), event.getHand()))) {
event.setCanceled(true); event.setCancellationResult(InteractionResult.SUCCESS);
@@ -0,0 +1,39 @@
package online.astradev.cauldron;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.LayeredCauldronBlock;
import net.neoforged.neoforge.common.NeoForge;
import online.astradev.plus.api.CauldronRecipeEvent;
/** Applies editor recipes only to ordinary cauldrons; saved soups and special liquids retain ownership. */
public final class EditorCauldronRecipes {
private EditorCauldronRecipes() {}
public static boolean interact(ServerPlayer player, BlockPos pos, InteractionHand hand) {
var level = player.level();
if (AstraCauldron.occupied(level, pos) || player.isSpectator() || !player.mayInteract(level, pos)) return false;
var state = level.getBlockState(pos);
String liquid = state.is(Blocks.CAULDRON) ? "empty" : state.is(Blocks.WATER_CAULDRON) ? "water"
: state.is(Blocks.LAVA_CAULDRON) ? "lava" : state.is(Blocks.POWDER_SNOW_CAULDRON) ? "powder_snow" : "";
if (liquid.isEmpty()) return false;
int fill = state.hasProperty(LayeredCauldronBlock.LEVEL) ? state.getValue(LayeredCauldronBlock.LEVEL) : liquid.equals("empty") ? 0 : 3;
var request = NeoForge.EVENT_BUS.post(new CauldronRecipeEvent(player.getItemInHand(hand), liquid, fill));
ItemStack output = request.output();
if (output.isEmpty()) return false;
int remaining = fill - request.liquidCost();
if (request.liquidCost() > 0) {
var next = remaining == 0 ? Blocks.CAULDRON.defaultBlockState() : state.setValue(LayeredCauldronBlock.LEVEL, remaining);
if (!level.setBlock(pos, next, 3)) return true;
}
ItemStack held = player.getItemInHand(hand);
held.consume(1, player);
if (held.isEmpty()) player.setItemInHand(hand, output);
else { player.getInventory().add(output); if (!output.isEmpty()) player.drop(output, false); }
level.playSound(null, pos, net.minecraft.sounds.SoundEvents.BUCKET_EMPTY, net.minecraft.sounds.SoundSource.BLOCKS, 0.5F, 1);
player.containerMenu.broadcastChanges();
return true;
}
}