Search in sources :

Example 46 with BlockLiquid

use of net.minecraft.block.BlockLiquid 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 47 with BlockLiquid

use of net.minecraft.block.BlockLiquid 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)

Example 48 with BlockLiquid

use of net.minecraft.block.BlockLiquid in project GregTech by GregTechCE.

the class MetaTileEntityPump method tryPumpFirstBlock.

private void tryPumpFirstBlock() {
    BlockPos fluidBlockPos = fluidSourceBlocks.poll();
    if (fluidBlockPos == null)
        return;
    IBlockState blockHere = getWorld().getBlockState(fluidBlockPos);
    if (blockHere.getBlock() instanceof BlockLiquid || blockHere.getBlock() instanceof IFluidBlock) {
        IFluidHandler fluidHandler = FluidUtil.getFluidHandler(getWorld(), fluidBlockPos, null);
        FluidStack drainStack = fluidHandler.drain(Integer.MAX_VALUE, false);
        if (drainStack != null && exportFluids.fill(drainStack, false) == drainStack.amount) {
            exportFluids.fill(drainStack, true);
            fluidHandler.drain(drainStack.amount, true);
            this.fluidSourceBlocks.remove(fluidBlockPos);
            energyContainer.changeEnergy(-GTValues.V[getTier()]);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) BlockPos(net.minecraft.util.math.BlockPos) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Example 49 with BlockLiquid

use of net.minecraft.block.BlockLiquid in project Tale-of-Kingdoms by Ivasik78.

the class ItemSpawnEgg method onItemRightClick.

@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
    if (world.isRemote) {
        return stack;
    } else {
        MovingObjectPosition movingobjectposition = getMovingObjectPositionFromPlayer(world, player, true);
        if (movingobjectposition == null) {
            return stack;
        } else {
            if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
                int x = movingobjectposition.blockX;
                int y = movingobjectposition.blockY;
                int z = movingobjectposition.blockZ;
                if (!world.canMineBlock(player, x, y, z))
                    return stack;
                if (!player.canPlayerEdit(x, y, z, movingobjectposition.sideHit, stack))
                    return stack;
                if (world.getBlock(x, y, z) instanceof BlockLiquid) {
                    Entity entity = spawnEntity(stack, world, x, y, z);
                    if (entity != null) {
                        if (entity instanceof EntityLivingBase && stack.hasDisplayName())
                            ((EntityLiving) entity).setCustomNameTag(stack.getDisplayName());
                        if (!player.capabilities.isCreativeMode)
                            --stack.stackSize;
                    }
                }
            }
            return stack;
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) BlockLiquid(net.minecraft.block.BlockLiquid) EntityLivingBase(net.minecraft.entity.EntityLivingBase)

Example 50 with BlockLiquid

use of net.minecraft.block.BlockLiquid in project harvestcraft by MatrexsVigil.

the class TileEntityWaterTrap method getRunTime.

private int getRunTime() {
    final int radius = 2;
    // final World world = world;
    final int varX = pos.getX();
    final int varY = pos.getY();
    final int varZ = pos.getZ();
    int speed = 3500;
    for (int offsetX = -radius; offsetX <= radius; ++offsetX) {
        for (int offsetZ = -radius; offsetZ <= radius; ++offsetZ) {
            if (offsetX * offsetX + offsetZ * offsetZ > radius * radius || offsetX == -radius - 1 && offsetZ == -radius - 1 || offsetX == radius - 1 && offsetZ == radius - 1 || offsetX == radius - 1 && offsetZ == -radius - 1 || offsetX == -radius - 1 && offsetZ == radius - 1)
                continue;
            final BlockPos pos = new BlockPos(varX + offsetX, varY, varZ + offsetZ);
            if (!world.isBlockLoaded(pos))
                continue;
            final Block blockAtCoords = world.getBlockState(pos).getBlock();
            if (blockAtCoords instanceof BlockLiquid) {
                speed = (int) (speed * 0.95);
            }
            if (blockAtCoords != BlockRegistry.watertrap)
                continue;
            speed = (int) (speed / 0.85);
        }
    }
    return speed;
}
Also used : BlockLiquid(net.minecraft.block.BlockLiquid) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

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