BlockEvents.rightClicked(event => {
let player = event.player;
let block = event.block;
if (player.getMainHandItem().id == "minecraft:glass_bottle") {
let blockEntity = block.getEntity();
if (!blockEntity) {
console.log("No block entity found!");
return;
}
console.log(`Block entity found: ${blockEntity}`);
if (typeof blockEntity.getTankInv !== "function") {
console.log("Block entity does not support fluid handling!");
return;
}
let tankInventory = blockEntity.getTankInv();
if (!tankInventory) {
console.log("No tank inventory found!");
return;
}
console.log("Tank inventory found!");
let fluidStack = tankInventory.getFluidInTank(0);
if (!fluidStack || fluidStack.isEmpty()) {
console.log("Tank is empty!");
return;
}
let fluidId = fluidStack.getFluid().toString();
let amount = fluidStack.amount;
console.log(`Fluid found: ${fluidId}, Amount: ${amount}mb`);
if (fluidId.includes("PurifiedWater") && amount >= 1000) {
console.log("Purified water found! Filling the bucket...");
event.item.count--;
event.entity.runCommandSilent('playsound minecraft:item.bucket.fill master @p ~ ~ ~');
event.entity.runCommandSilent('give @p minecraft:potion{Potion:"survive:purified_water"}');
tankInventory.drain(1000, true);
} else {
console.log("Not enough purified water or wrong fluid!");
}
}
});