Search in sources :

Example 31 with IFluidBlock

use of net.minecraftforge.fluids.IFluidBlock in project BuildCraft by BuildCraft.

the class TileQuarry method isQuarriableBlock.

private boolean isQuarriableBlock(BlockPos pos) {
    IBlockState state = worldObj.getBlockState(pos);
    Block block = state.getBlock();
    return BlockUtil.canChangeBlock(state, worldObj, pos) && !BuildCraftAPI.isSoftBlock(worldObj, pos) && !(block instanceof BlockLiquid) && !(block instanceof IFluidBlock);
}
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 32 with IFluidBlock

use of net.minecraftforge.fluids.IFluidBlock in project BuildCraft by BuildCraft.

the class PipeItemsStripes method updateEntity.

@Override
public void updateEntity() {
    super.updateEntity();
    if (container.getWorld().isRemote) {
        return;
    }
    if (battery.getEnergyStored() >= 10) {
        EnumPipePart o = actionDir;
        if (o == EnumPipePart.CENTER) {
            o = EnumPipePart.fromFacing(getOpenOrientation());
        }
        if (o != EnumPipePart.CENTER) {
            Vec3d vec = Utils.convert(container.getPos()).add(Utils.convert(o.face));
            BlockPos veci = Utils.convertFloor(vec);
            if (!BlockUtil.isUnbreakableBlock(getWorld(), Utils.convertFloor(vec))) {
                IBlockState state = getWorld().getBlockState(Utils.convertFloor(vec));
                Block block = state.getBlock();
                if (block instanceof BlockLiquid || block instanceof IFluidBlock) {
                    return;
                }
                ItemStack stack = new ItemStack(block, 1, block.getMetaFromState(state));
                EntityPlayer player = CoreProxy.proxy.getBuildCraftPlayer((WorldServer) getWorld(), veci).get();
                if (battery.useEnergy(10, 10, false) != 10) {
                    return;
                }
                for (IStripesHandler handler : PipeManager.stripesHandlers) {
                    if (handler.getType() == StripesHandlerType.BLOCK_BREAK && handler.shouldHandle(stack)) {
                        if (handler.handle(getWorld(), veci, o.face, stack, player, this)) {
                            return;
                        }
                    }
                }
                List<ItemStack> stacks = block.getDrops(getWorld(), veci, state, 0);
                if (stacks != null) {
                    for (ItemStack s : stacks) {
                        if (s != null) {
                            sendItem(s, o.opposite().face);
                        }
                    }
                }
                getWorld().setBlockToAir(veci);
            }
        }
        return;
    }
}
Also used : IStripesHandler(buildcraft.api.transport.IStripesHandler) IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) EnumPipePart(buildcraft.api.core.EnumPipePart) Block(net.minecraft.block.Block) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) WorldServer(net.minecraft.world.WorldServer) ItemStack(net.minecraft.item.ItemStack) Vec3d(net.minecraft.util.math.Vec3d)

Example 33 with IFluidBlock

use of net.minecraftforge.fluids.IFluidBlock in project BuildCraft by BuildCraft.

the class ItemFacade method isValidFacade.

public static boolean isValidFacade(IBlockState state) {
    if (blacklistedFacades.contains(state)) {
        return false;
    }
    if (whitelistedFacades.contains(state)) {
        return true;
    }
    Block block = state.getBlock();
    if (block instanceof IFluidBlock || block.hasTileEntity(state)) {
        return false;
    }
    block.setBlockBoundsBasedOnState(new FakeBlockAccessSingleBlock(state), BlockPos.ORIGIN);
    if (block.getBlockBoundsMinX() != 0.0D || block.getBlockBoundsMinY() != 0.0D || block.getBlockBoundsMinZ() != 0.0D) {
        return false;
    }
    if (block.getBlockBoundsMaxX() != 1.0D || block.getBlockBoundsMaxY() != 1.0D || block.getBlockBoundsMaxZ() != 1.0D) {
        return false;
    }
    return true;
}
Also used : IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block) FakeBlockAccessSingleBlock(buildcraft.core.lib.world.FakeBlockAccessSingleBlock) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) FakeBlockAccessSingleBlock(buildcraft.core.lib.world.FakeBlockAccessSingleBlock)

Example 34 with IFluidBlock

use of net.minecraftforge.fluids.IFluidBlock in project BloodMagic by WayofTime.

the class RitualPump method performRitual.

@Override
public void performRitual(IMasterRitualStone masterRitualStone) {
    World world = masterRitualStone.getWorldObj();
    int currentEssence = masterRitualStone.getOwnerNetwork().getCurrentEssence();
    TileEntity tileEntity = world.getTileEntity(masterRitualStone.getBlockPos().up());
    if (currentEssence < getRefreshCost()) {
        masterRitualStone.getOwnerNetwork().causeNausea();
        return;
    }
    if (tileEntity != null && tileEntity.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.DOWN)) {
        IFluidHandler fluidHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.DOWN);
        IBlockState tankState = world.getBlockState(masterRitualStone.getBlockPos().up());
        int maxDrain = fluidHandler.getTankProperties()[0].getCapacity();
        if (fluidHandler.getTankProperties()[0].getContents() != null && fluidHandler.getTankProperties()[0].getContents().amount >= maxDrain)
            return;
        for (BlockPos pos : getBlockRange(PUMP_RANGE).getContainedPositions(masterRitualStone.getBlockPos())) {
            IBlockState state = world.getBlockState(pos);
            IFluidHandler blockHandler = null;
            if (state.getBlock() instanceof BlockLiquid)
                blockHandler = new BlockLiquidWrapper((BlockLiquid) state.getBlock(), world, pos);
            else if (state.getBlock() instanceof IFluidHandler)
                blockHandler = new FluidBlockWrapper((IFluidBlock) state.getBlock(), world, pos);
            if (blockHandler != null) {
                FluidStack blockDrain = blockHandler.drain(maxDrain, false);
                if (blockDrain != null && fluidHandler.fill(blockDrain, false) == blockDrain.amount) {
                    Pair<BlockPos, FluidStack> posInfo = Pair.of(pos, blockHandler.drain(maxDrain, false));
                    if (!liquidsCache.contains(posInfo))
                        liquidsCache.add(posInfo);
                }
            }
        }
        blockPosIterator = liquidsCache.iterator();
        if (blockPosIterator.hasNext()) {
            Pair<BlockPos, FluidStack> posInfo = blockPosIterator.next();
            masterRitualStone.getOwnerNetwork().syphon(getRefreshCost());
            fluidHandler.fill(posInfo.getRight(), true);
            world.setBlockState(posInfo.getLeft(), Blocks.STONE.getDefaultState());
            world.notifyBlockUpdate(posInfo.getLeft(), tankState, tankState, 3);
            blockPosIterator.remove();
        }
    }
}
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) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) BlockLiquidWrapper(net.minecraftforge.fluids.capability.wrappers.BlockLiquidWrapper) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 35 with IFluidBlock

use of net.minecraftforge.fluids.IFluidBlock in project GregTech by GregTechCE.

the class MetaTileEntityPump method checkFluidBlockAt.

private void checkFluidBlockAt(BlockPos pumpHeadPos, BlockPos checkPos) {
    IBlockState blockHere = getWorld().getBlockState(checkPos);
    boolean shouldCheckNeighbours = isStraightInPumpRange(checkPos);
    if (blockHere.getBlock() instanceof BlockLiquid || blockHere.getBlock() instanceof IFluidBlock) {
        IFluidHandler fluidHandler = FluidUtil.getFluidHandler(getWorld(), checkPos, null);
        FluidStack drainStack = fluidHandler.drain(Integer.MAX_VALUE, false);
        if (drainStack != null && drainStack.amount > 0) {
            this.fluidSourceBlocks.add(checkPos);
        }
        shouldCheckNeighbours = true;
    }
    if (shouldCheckNeighbours) {
        int maxPumpRange = getMaxPumpRange();
        for (EnumFacing facing : EnumFacing.VALUES) {
            BlockPos offsetPos = checkPos.offset(facing);
            if (offsetPos.distanceSq(pumpHeadPos) > maxPumpRange * maxPumpRange)
                // do not add blocks outside bounds
                continue;
            if (!fluidSourceBlocks.contains(offsetPos) && !blocksToCheck.contains(offsetPos)) {
                this.blocksToCheck.add(offsetPos);
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Aggregations

IFluidBlock (net.minecraftforge.fluids.IFluidBlock)41 Block (net.minecraft.block.Block)28 IBlockState (net.minecraft.block.state.IBlockState)24 BlockLiquid (net.minecraft.block.BlockLiquid)18 BlockPos (net.minecraft.util.math.BlockPos)13 ItemStack (net.minecraft.item.ItemStack)11 FluidStack (net.minecraftforge.fluids.FluidStack)9 EntityPlayer (net.minecraft.entity.player.EntityPlayer)5 TileEntity (net.minecraft.tileentity.TileEntity)5 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)5 Fluid (net.minecraftforge.fluids.Fluid)5 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)5 Entity (net.minecraft.entity.Entity)4 World (net.minecraft.world.World)4 EntityFlyingBlock (icbm.classic.content.entity.EntityFlyingBlock)3 BlockStaticLiquid (net.minecraft.block.BlockStaticLiquid)3 Item (net.minecraft.item.Item)3 ItemBlock (net.minecraft.item.ItemBlock)3 EnumFacing (net.minecraft.util.EnumFacing)3 RayTraceResult (net.minecraft.util.math.RayTraceResult)3