#Trying to make this script drain the fluid in the block tank

2 messages · Page 1 of 1 (latest)

olive olive
#
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(); // Convert fluid to string
        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"}');

            // Drena 1000mb do tanque corretamente
            tankInventory.drain(1000, true);
            
        } else {
            console.log("Not enough purified water or wrong fluid!");
        }
    }
});
terse ermineBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!