Search in sources :

Example 1 with FlowingFluid

use of net.minecraft.fluid.FlowingFluid in project Ceramics by KnightMiner.

the class ClayBucketItem method tryPlaceContainedLiquid.

// TODO: possibly migrate to the Forge method
@SuppressWarnings("deprecation")
private boolean tryPlaceContainedLiquid(@Nullable PlayerEntity player, World world, BlockPos pos, ItemStack stack, @Nullable BlockRayTraceResult trace) {
    Fluid fluidStack = this.getFluid(stack);
    Fluid fluid = fluidStack.getFluid();
    if (!(fluid instanceof FlowingFluid)) {
        return false;
    }
    BlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    boolean replaceable = state.isReplaceable(fluid);
    if (state.isAir(world, pos) || replaceable || block instanceof ILiquidContainer && ((ILiquidContainer) block).canContainFluid(world, pos, state, fluid)) {
        if (world.getDimensionType().isUltrawarm() && fluid.isIn(FluidTags.WATER)) {
            world.playSound(player, pos, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
            for (int l = 0; l < 8; ++l) {
                world.addParticle(ParticleTypes.LARGE_SMOKE, pos.getX() + Math.random(), pos.getY() + Math.random(), pos.getZ() + Math.random(), 0.0D, 0.0D, 0.0D);
            }
        } else if (block instanceof ILiquidContainer && fluid == Fluids.WATER) {
            if (((ILiquidContainer) block).receiveFluid(world, pos, state, ((FlowingFluid) fluid).getStillFluidState(false))) {
                this.playEmptySound(fluid, player, world, pos);
            }
        } else {
            if (!world.isRemote() && replaceable && !state.getMaterial().isLiquid()) {
                world.destroyBlock(pos, true);
            }
            this.playEmptySound(fluid, player, world, pos);
            world.setBlockState(pos, fluid.getDefaultState().getBlockState(), 11);
        }
        return true;
    }
    if (trace == null) {
        return false;
    }
    return this.tryPlaceContainedLiquid(player, world, trace.getPos().offset(trace.getFace()), stack, null);
}
Also used : BlockState(net.minecraft.block.BlockState) ILiquidContainer(net.minecraft.block.ILiquidContainer) FlowingFluid(net.minecraft.fluid.FlowingFluid) Fluid(net.minecraft.fluid.Fluid) FlowingFluid(net.minecraft.fluid.FlowingFluid) Block(net.minecraft.block.Block) CauldronBlock(net.minecraft.block.CauldronBlock)

Example 2 with FlowingFluid

use of net.minecraft.fluid.FlowingFluid in project Mekanism by mekanism.

the class MekanismUtils method getFluidsIn.

/**
 * Similar in concept to {@link net.minecraft.entity.Entity#updateFluidHeightAndDoFluidPushing(ITag, double)} except calculates if a given portion of the player is in
 * the fluids.
 */
public static Map<Fluid, FluidInDetails> getFluidsIn(PlayerEntity player, UnaryOperator<AxisAlignedBB> modifyBoundingBox) {
    AxisAlignedBB bb = modifyBoundingBox.apply(player.getBoundingBox().deflate(0.001));
    int xMin = MathHelper.floor(bb.minX);
    int xMax = MathHelper.ceil(bb.maxX);
    int yMin = MathHelper.floor(bb.minY);
    int yMax = MathHelper.ceil(bb.maxY);
    int zMin = MathHelper.floor(bb.minZ);
    int zMax = MathHelper.ceil(bb.maxZ);
    if (!player.level.hasChunksAt(xMin, yMin, zMin, xMax, yMax, zMax)) {
        // If the position isn't actually loaded, just return there isn't any fluids
        return Collections.emptyMap();
    }
    Map<Fluid, FluidInDetails> fluidsIn = new HashMap<>();
    BlockPos.Mutable mutablePos = new BlockPos.Mutable();
    for (int x = xMin; x < xMax; ++x) {
        for (int y = yMin; y < yMax; ++y) {
            for (int z = zMin; z < zMax; ++z) {
                mutablePos.set(x, y, z);
                FluidState fluidState = player.level.getFluidState(mutablePos);
                if (!fluidState.isEmpty()) {
                    double fluidY = y + fluidState.getHeight(player.level, mutablePos);
                    if (bb.minY <= fluidY) {
                        // The fluid intersects the bounding box
                        Fluid fluid = fluidState.getType();
                        if (fluid instanceof FlowingFluid) {
                            // Almost always will be flowing fluid but check just in case
                            // and if it is grab the source state to not have duplicates
                            fluid = ((FlowingFluid) fluid).getSource();
                        }
                        FluidInDetails details = fluidsIn.computeIfAbsent(fluid, f -> new FluidInDetails());
                        details.positions.add(mutablePos.immutable());
                        double actualFluidHeight;
                        if (fluidY > bb.maxY) {
                            // Fluid goes past the top of the bounding box, limit it to the top
                            // We do the max of the bottom of the bounding box and our current block so that
                            // if we are floating above the bottom we don't take the area below us into account
                            actualFluidHeight = bb.maxY - Math.max(bb.minY, y);
                        } else {
                            // We do the max of the bottom of the bounding box and our current block so that
                            // if we are floating above the bottom we don't take the area below us into account
                            actualFluidHeight = fluidY - Math.max(bb.minY, y);
                        }
                        details.heights.merge(ChunkPos.asLong(x, z), actualFluidHeight, Double::sum);
                    }
                }
            }
        }
    }
    return fluidsIn;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) HashMap(java.util.HashMap) FlowingFluid(net.minecraft.fluid.FlowingFluid) Fluid(net.minecraft.fluid.Fluid) FlowingFluid(net.minecraft.fluid.FlowingFluid) BlockPos(net.minecraft.util.math.BlockPos) FluidState(net.minecraft.fluid.FluidState)

Example 3 with FlowingFluid

use of net.minecraft.fluid.FlowingFluid in project MCMOD-Industria by M-Marvin.

the class ItemFluidBucket method emptyBucket.

@SuppressWarnings("deprecation")
public boolean emptyBucket(@Nullable PlayerEntity player, World worldIn, BlockPos posIn, @Nullable BlockRayTraceResult rayTrace) {
    if (!(getFluid() instanceof FlowingFluid)) {
        return false;
    } else {
        BlockState blockstate = worldIn.getBlockState(posIn);
        Block block = blockstate.getBlock();
        Material material = blockstate.getMaterial();
        boolean flag = blockstate.canBeReplaced(getFluid());
        boolean flag1 = blockstate.isAir() || flag || block instanceof ILiquidContainer && ((ILiquidContainer) block).canPlaceLiquid(worldIn, posIn, blockstate, getFluid());
        if (!flag1) {
            return rayTrace != null && this.emptyBucket(player, worldIn, rayTrace.getBlockPos().relative(rayTrace.getDirection()), (BlockRayTraceResult) null);
        } else if (!canPlaceInNether && worldIn.dimensionType().ultraWarm()) {
            int i = posIn.getX();
            int j = posIn.getY();
            int k = posIn.getZ();
            worldIn.playSound(player, posIn, SoundEvents.FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (worldIn.random.nextFloat() - worldIn.random.nextFloat()) * 0.8F);
            for (int l = 0; l < 8; ++l) {
                worldIn.addParticle(ParticleTypes.LARGE_SMOKE, (double) i + Math.random(), (double) j + Math.random(), (double) k + Math.random(), 0.0D, 0.0D, 0.0D);
            }
            return true;
        } else if (block instanceof ILiquidContainer && ((ILiquidContainer) block).canPlaceLiquid(worldIn, posIn, blockstate, getFluid())) {
            ((ILiquidContainer) block).placeLiquid(worldIn, posIn, blockstate, ((FlowingFluid) getFluid()).getSource(false));
            this.playEmptySound(player, worldIn, posIn);
            return true;
        } else {
            if (!worldIn.isClientSide && flag && !material.isLiquid()) {
                worldIn.destroyBlock(posIn, true);
            }
            if (!worldIn.setBlock(posIn, getFluid().defaultFluidState().createLegacyBlock(), 11) && !blockstate.getFluidState().isSource()) {
                return false;
            } else {
                this.playEmptySound(player, worldIn, posIn);
                return true;
            }
        }
    }
}
Also used : BlockState(net.minecraft.block.BlockState) ILiquidContainer(net.minecraft.block.ILiquidContainer) FlowingFluid(net.minecraft.fluid.FlowingFluid) Block(net.minecraft.block.Block) Material(net.minecraft.block.material.Material) BlockRayTraceResult(net.minecraft.util.math.BlockRayTraceResult)

Aggregations

FlowingFluid (net.minecraft.fluid.FlowingFluid)3 Block (net.minecraft.block.Block)2 BlockState (net.minecraft.block.BlockState)2 ILiquidContainer (net.minecraft.block.ILiquidContainer)2 Fluid (net.minecraft.fluid.Fluid)2 HashMap (java.util.HashMap)1 CauldronBlock (net.minecraft.block.CauldronBlock)1 Material (net.minecraft.block.material.Material)1 FluidState (net.minecraft.fluid.FluidState)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 BlockRayTraceResult (net.minecraft.util.math.BlockRayTraceResult)1