Search in sources :

Example 1 with BlockLiquid

use of net.minecraft.block.BlockLiquid in project MinecraftForge by MinecraftForge.

the class FluidUtil method tryPlaceFluid.

/**
     * Tries to place a fluid in the world in block form and drains the container.
     * Makes a fluid emptying sound when successful.
     * Honors the amount of fluid contained by the used container.
     * Checks if water-like fluids should vaporize like in the nether.
     *
     * Modeled after {@link net.minecraft.item.ItemBucket#tryPlaceContainedLiquid(EntityPlayer, World, BlockPos)}
     *
     * @param player    Player who places the fluid. May be null for blocks like dispensers.
     * @param world     World to place the fluid in
     * @param pos       The position in the world to place the fluid block
     * @param container The fluid container holding the fluidStack to place
     * @param resource  The fluidStack to place
     * @return the container's ItemStack with the remaining amount of fluid if the placement was successful, null otherwise
     */
@Nonnull
public static FluidActionResult tryPlaceFluid(@Nullable EntityPlayer player, World world, BlockPos pos, @Nonnull ItemStack container, FluidStack resource) {
    if (world == null || resource == null || pos == null) {
        return FluidActionResult.FAILURE;
    }
    Fluid fluid = resource.getFluid();
    if (fluid == null || !fluid.canBePlacedInWorld()) {
        return FluidActionResult.FAILURE;
    }
    // check that we can place the fluid at the destination
    IBlockState destBlockState = world.getBlockState(pos);
    Material destMaterial = destBlockState.getMaterial();
    boolean isDestNonSolid = !destMaterial.isSolid();
    boolean isDestReplaceable = destBlockState.getBlock().isReplaceable(world, pos);
    if (!world.isAirBlock(pos) && !isDestNonSolid && !isDestReplaceable) {
        // Non-air, solid, unreplacable block. We can't put fluid here.
        return FluidActionResult.FAILURE;
    }
    if (world.provider.doesWaterVaporize() && fluid.doesVaporize(resource)) {
        fluid.vaporize(player, world, pos, resource);
        return tryEmptyContainer(container, new VoidFluidHandler(), Integer.MAX_VALUE, player, true);
    } else {
        if (!world.isRemote && (isDestNonSolid || isDestReplaceable) && !destMaterial.isLiquid()) {
            world.destroyBlock(pos, true);
        }
        // Defer the placement to the fluid block
        // Instead of actually "filling", the fluid handler method replaces the block
        Block block = fluid.getBlock();
        IFluidHandler handler;
        if (block instanceof IFluidBlock) {
            handler = new FluidBlockWrapper((IFluidBlock) block, world, pos);
        } else if (block instanceof BlockLiquid) {
            handler = new BlockLiquidWrapper((BlockLiquid) block, world, pos);
        } else {
            handler = new BlockWrapper(block, world, pos);
        }
        FluidActionResult result = tryEmptyContainer(container, handler, Integer.MAX_VALUE, player, true);
        if (result.isSuccess()) {
            SoundEvent soundevent = fluid.getEmptySound(resource);
            world.playSound(player, pos, soundevent, SoundCategory.BLOCKS, 1.0F, 1.0F);
        }
        return result;
    }
}
Also used : VoidFluidHandler(net.minecraftforge.fluids.capability.templates.VoidFluidHandler) FluidBlockWrapper(net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper) FluidBlockWrapper(net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper) BlockWrapper(net.minecraftforge.fluids.capability.wrappers.BlockWrapper) IBlockState(net.minecraft.block.state.IBlockState) Material(net.minecraft.block.material.Material) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) SoundEvent(net.minecraft.util.SoundEvent) BlockLiquid(net.minecraft.block.BlockLiquid) BlockLiquidWrapper(net.minecraftforge.fluids.capability.wrappers.BlockLiquidWrapper) Block(net.minecraft.block.Block) Nonnull(javax.annotation.Nonnull)

Example 2 with BlockLiquid

use of net.minecraft.block.BlockLiquid in project MinecraftForge by MinecraftForge.

the class FluidUtil method getFluidHandler.

/**
     * Helper method to get an IFluidHandler for at a block position.
     *
     * Returns null if there is no valid fluid handler.
     */
@Nullable
public static IFluidHandler getFluidHandler(World world, BlockPos blockPos, @Nullable EnumFacing side) {
    IBlockState state = world.getBlockState(blockPos);
    Block block = state.getBlock();
    if (block.hasTileEntity(state)) {
        TileEntity tileEntity = world.getTileEntity(blockPos);
        if (tileEntity != null && tileEntity.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) {
            return tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side);
        }
    } else if (block instanceof IFluidBlock) {
        return new FluidBlockWrapper((IFluidBlock) block, world, blockPos);
    } else if (block instanceof BlockLiquid) {
        return new BlockLiquidWrapper((BlockLiquid) block, world, blockPos);
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidBlockWrapper(net.minecraftforge.fluids.capability.wrappers.FluidBlockWrapper) IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) BlockLiquidWrapper(net.minecraftforge.fluids.capability.wrappers.BlockLiquidWrapper) Block(net.minecraft.block.Block) Nullable(javax.annotation.Nullable)

Example 3 with BlockLiquid

use of net.minecraft.block.BlockLiquid in project MinecraftForge by MinecraftForge.

the class ForgeHooks method isInsideOfMaterial.

public static boolean isInsideOfMaterial(Material material, Entity entity, BlockPos pos) {
    IBlockState state = entity.world.getBlockState(pos);
    Block block = state.getBlock();
    double eyes = entity.posY + (double) entity.getEyeHeight();
    //If it's not a liquid assume it's a solid block
    double filled = 1.0f;
    if (block instanceof IFluidBlock) {
        filled = ((IFluidBlock) block).getFilledPercentage(entity.world, pos);
    } else if (block instanceof BlockLiquid) {
        filled = BlockLiquid.getLiquidHeightPercent(block.getMetaFromState(state));
    }
    if (filled < 0) {
        filled *= -1;
        //filled -= 0.11111111F; //Why this is needed.. not sure...
        return eyes > pos.getY() + 1 + (1 - filled);
    } else {
        return eyes < pos.getY() + 1 + filled;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block) IFluidBlock(net.minecraftforge.fluids.IFluidBlock)

Example 4 with BlockLiquid

use of net.minecraft.block.BlockLiquid in project MinecraftForge by MinecraftForge.

the class BlockFluidBase method getFluidHeightForRender.

public float getFluidHeightForRender(IBlockAccess world, BlockPos pos) {
    IBlockState here = world.getBlockState(pos);
    IBlockState up = world.getBlockState(pos.down(densityDir));
    if (here.getBlock() == this) {
        if (up.getMaterial().isLiquid() || up.getBlock() instanceof IFluidBlock) {
            return 1;
        }
        if (getMetaFromState(here) == getMaxRenderHeightMeta()) {
            return 0.875F;
        }
    }
    if (here.getBlock() instanceof BlockLiquid) {
        return Math.min(1 - BlockLiquid.getLiquidHeightPercent(here.getValue(BlockLiquid.LEVEL)), 14f / 16);
    }
    return !here.getMaterial().isSolid() && up.getBlock() == this ? 1 : this.getQuantaPercentage(world, pos) * 0.875F;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid)

Example 5 with BlockLiquid

use of net.minecraft.block.BlockLiquid in project MinecraftForge by MinecraftForge.

the class BlockLiquidWrapper method fill.

@Override
public int fill(FluidStack resource, boolean doFill) {
    // NOTE: "Filling" means placement in this context!
    if (resource.amount < Fluid.BUCKET_VOLUME) {
        return 0;
    }
    if (doFill) {
        Material material = blockLiquid.getDefaultState().getMaterial();
        BlockLiquid block = BlockLiquid.getStaticBlock(material);
        world.setBlockState(blockPos, block.getDefaultState().withProperty(BlockLiquid.LEVEL, 0), 11);
    }
    return Fluid.BUCKET_VOLUME;
}
Also used : BlockLiquid(net.minecraft.block.BlockLiquid) Material(net.minecraft.block.material.Material)

Aggregations

BlockLiquid (net.minecraft.block.BlockLiquid)57 IBlockState (net.minecraft.block.state.IBlockState)44 Block (net.minecraft.block.Block)27 BlockPos (net.minecraft.util.math.BlockPos)22 IFluidBlock (net.minecraftforge.fluids.IFluidBlock)20 Material (net.minecraft.block.material.Material)11 ItemStack (net.minecraft.item.ItemStack)8 EnumFacing (net.minecraft.util.EnumFacing)5 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)5 BlockPos (net.minecraft.util.BlockPos)4 BlockFluidBase (net.minecraftforge.fluids.BlockFluidBase)4 FluidStack (net.minecraftforge.fluids.FluidStack)4 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)4 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)3 Entity (net.minecraft.entity.Entity)3 World (net.minecraft.world.World)3 IPlantable (net.minecraftforge.common.IPlantable)3 Location (com.builtbroken.mc.imp.transform.vector.Location)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ArrayList (java.util.ArrayList)2