Search in sources :

Example 1 with FlowingFluid

use of net.minecraft.world.level.material.FlowingFluid in project pollen by MoonflowerTeam.

the class BucketItemBase method emptyBucket.

@Override
public boolean emptyBucket(@Nullable Player player, Level level, BlockPos blockPos, @Nullable BlockHitResult blockHitResult) {
    Fluid content = this.getFluid();
    if (!(content instanceof FlowingFluid))
        return false;
    BlockState blockState = level.getBlockState(blockPos);
    Block block = blockState.getBlock();
    Material material = blockState.getMaterial();
    boolean bl = blockState.canBeReplaced(content);
    boolean bl2 = blockState.isAir() || bl || block instanceof LiquidBlockContainer && ((LiquidBlockContainer) block).canPlaceLiquid(level, blockPos, blockState, content);
    if (!bl2) {
        return blockHitResult != null && this.emptyBucket(player, level, blockHitResult.getBlockPos().relative(blockHitResult.getDirection()), null);
    } else if (level.dimensionType().ultraWarm() && content.is(FluidTags.WATER)) {
        int i = blockPos.getX();
        int j = blockPos.getY();
        int k = blockPos.getZ();
        level.playSound(player, blockPos, SoundEvents.FIRE_EXTINGUISH, SoundSource.BLOCKS, 0.5F, 2.6F + (level.random.nextFloat() - level.random.nextFloat()) * 0.8F);
        for (int l = 0; l < 8; ++l) {
            level.addParticle(ParticleTypes.LARGE_SMOKE, (double) i + Math.random(), (double) j + Math.random(), (double) k + Math.random(), 0.0, 0.0, 0.0);
        }
        return true;
    } else if (block instanceof LiquidBlockContainer && content == Fluids.WATER) {
        ((LiquidBlockContainer) block).placeLiquid(level, blockPos, blockState, ((FlowingFluid) content).getSource(false));
        this.playEmptySound(player, level, blockPos);
        return true;
    } else {
        if (!level.isClientSide() && bl && !material.isLiquid()) {
            level.destroyBlock(blockPos, true);
        }
        if (!level.setBlock(blockPos, content.defaultFluidState().createLegacyBlock(), 11) && !blockState.getFluidState().isSource()) {
            return false;
        } else {
            this.playEmptySound(player, level, blockPos);
            return true;
        }
    }
}
Also used : LiquidBlockContainer(net.minecraft.world.level.block.LiquidBlockContainer) BlockState(net.minecraft.world.level.block.state.BlockState) Fluid(net.minecraft.world.level.material.Fluid) PollinatedFluid(gg.moonflower.pollen.api.fluid.PollinatedFluid) FlowingFluid(net.minecraft.world.level.material.FlowingFluid) FlowingFluid(net.minecraft.world.level.material.FlowingFluid) Block(net.minecraft.world.level.block.Block) Material(net.minecraft.world.level.material.Material)

Example 2 with FlowingFluid

use of net.minecraft.world.level.material.FlowingFluid in project MoreBoots by North-West-Wind.

the class Utils method isSurroundedByInvalidBlocks.

public static boolean isSurroundedByInvalidBlocks(LivingEntity player) {
    BlockPos pos = new BlockPos(player.position());
    BlockPos pos1 = pos.offset(1, 0, 1);
    BlockPos pos2 = pos.offset(-1, 0, -1);
    Iterator<BlockPos> iterator = BlockPos.betweenClosedStream(pos1, pos2).iterator();
    while (iterator.hasNext()) {
        BlockPos blockPos = iterator.next();
        Block block = player.level.getBlockState(blockPos).getBlock();
        Fluid fluid = player.level.getFluidState(blockPos).getType();
        if (!player.level.isEmptyBlock(blockPos) && !(fluid instanceof FlowingFluid) && !block.getCollisionShape(player.level.getBlockState(blockPos), player.level, blockPos, CollisionContext.empty()).equals(Shapes.empty()))
            return false;
    }
    return true;
}
Also used : Fluid(net.minecraft.world.level.material.Fluid) FlowingFluid(net.minecraft.world.level.material.FlowingFluid) LiquidBlock(net.minecraft.world.level.block.LiquidBlock) Block(net.minecraft.world.level.block.Block) FlowingFluid(net.minecraft.world.level.material.FlowingFluid) BlockPos(net.minecraft.core.BlockPos)

Aggregations

Block (net.minecraft.world.level.block.Block)2 FlowingFluid (net.minecraft.world.level.material.FlowingFluid)2 Fluid (net.minecraft.world.level.material.Fluid)2 PollinatedFluid (gg.moonflower.pollen.api.fluid.PollinatedFluid)1 BlockPos (net.minecraft.core.BlockPos)1 LiquidBlock (net.minecraft.world.level.block.LiquidBlock)1 LiquidBlockContainer (net.minecraft.world.level.block.LiquidBlockContainer)1 BlockState (net.minecraft.world.level.block.state.BlockState)1 Material (net.minecraft.world.level.material.Material)1