Search in sources :

Example 16 with IFluidBlock

use of net.minecraftforge.fluids.IFluidBlock in project MorePlanets by SteveKunG.

the class LiquidUtils method isInsideLiquid.

@Deprecated
private static boolean isInsideLiquid(EntityPlayer player, BlockPos pos) {
    IBlockState state = player.world.getBlockState(pos);
    Block block = state.getBlock();
    double eyes = player.posY + player.getEyeHeight();
    double filled = 1.0F;
    if (block instanceof IFluidBlock) {
        filled = ((IFluidBlock) block).getFilledPercentage(player.world, pos);
    } else if (block instanceof BlockLiquid) {
        filled = 1.0F - (BlockLiquid.getLiquidHeightPercent(block.getMetaFromState(state)) - 1.0F / 9.0F);
    }
    if (filled < 0.0F) {
        return eyes > pos.getY() + (filled + 1.0F);
    } else {
        return eyes < pos.getY() + filled;
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.block.Block)

Example 17 with IFluidBlock

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

the class SurfaceRockPopulator method findUndergroundMaterials.

private Set<Material> findUndergroundMaterials(Collection<IBlockState> generatedBlocks) {
    HashSet<Material> result = new HashSet<>();
    for (IBlockState blockState : generatedBlocks) {
        Material resultMaterial;
        if (blockState.getBlock() instanceof IFluidBlock || blockState.getBlock() instanceof BlockLiquid) {
            Fluid fluid = FluidRegistry.lookupFluidForBlock(blockState.getBlock());
            resultMaterial = fluid == null ? null : MetaFluids.getMaterialFromFluid(fluid);
        } else {
            ItemStack itemStack = new ItemStack(blockState.getBlock(), 1, blockState.getBlock().damageDropped(blockState));
            UnificationEntry entry = OreDictUnifier.getUnificationEntry(itemStack);
            resultMaterial = entry == null ? null : entry.material;
        }
        if (resultMaterial != null) {
            result.add(resultMaterial);
        }
    }
    return result;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Fluid(net.minecraftforge.fluids.Fluid) UnificationEntry(gregtech.api.unification.stack.UnificationEntry) Material(gregtech.api.unification.material.type.Material) ItemStack(net.minecraft.item.ItemStack)

Example 18 with IFluidBlock

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

the class MetaTileEntityPump method updateQueueState.

private void updateQueueState(int blocksToCheckAmount) {
    BlockPos selfPos = getPos().down(pumpHeadY);
    for (int i = 0; i < blocksToCheckAmount; i++) {
        BlockPos checkPos = null;
        int amountIterated = 0;
        do {
            if (checkPos != null) {
                blocksToCheck.push(checkPos);
                amountIterated++;
            }
            checkPos = blocksToCheck.poll();
        } while (checkPos != null && !getWorld().isBlockLoaded(checkPos) && amountIterated < blocksToCheck.size());
        if (checkPos != null) {
            checkFluidBlockAt(selfPos, checkPos);
        } else
            break;
    }
    if (fluidSourceBlocks.isEmpty()) {
        if (getOffsetTimer() % 20 == 0) {
            BlockPos downPos = selfPos.down(1);
            if (downPos != null && downPos.getY() >= 0) {
                IBlockState downBlock = getWorld().getBlockState(downPos);
                if (downBlock.getBlock() instanceof BlockLiquid || downBlock.getBlock() instanceof IFluidBlock || !downBlock.isTopSolid()) {
                    this.pumpHeadY++;
                }
            }
            // Always recheck next time
            writeCustomData(200, b -> b.writeVarInt(pumpHeadY));
            markDirty();
            // schedule queue rebuild because we changed our position and no fluid is available
            this.initializedQueue = false;
        }
        if (!initializedQueue || getOffsetTimer() % 6000 == 0 || getTimer() == 0) {
            this.initializedQueue = true;
            // just add ourselves to check list and see how this will go
            this.blocksToCheck.add(selfPos);
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) BlockPos(net.minecraft.util.math.BlockPos)

Example 19 with IFluidBlock

use of net.minecraftforge.fluids.IFluidBlock in project Galacticraft by micdoodle8.

the class EntityAstroMiner method tryBlockClient.

private boolean tryBlockClient(BlockPos pos) {
    BlockVec3 bv = new BlockVec3(pos.getX(), pos.getY(), pos.getZ());
    if (this.laserBlocks.contains(bv)) {
        return false;
    }
    // Add minable blocks to the laser fx list
    IBlockState state = this.world.getBlockState(pos);
    Block b = state.getBlock();
    if (b.getMaterial(state) == Material.AIR) {
        return false;
    }
    if (noMineList.contains(b)) {
        return true;
    }
    if (b instanceof BlockLiquid) {
        return false;
    }
    if (b instanceof IFluidBlock) {
        return false;
    }
    if (b instanceof IPlantable) {
        return true;
    }
    if (b.hasTileEntity(state) || b.getBlockHardness(state, this.world, pos) < 0) {
        return true;
    }
    if (this.tryBlockLimit == 0) {
        return false;
    }
    this.tryBlockLimit--;
    this.laserBlocks.add(bv);
    this.laserTimes.add(this.ticksExisted);
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 20 with IFluidBlock

use of net.minecraftforge.fluids.IFluidBlock in project Galacticraft by micdoodle8.

the class EntityAstroMiner method tryMineBlock.

private boolean tryMineBlock(BlockPos pos) {
    // Check things to avoid in front of it (see static list for list) including base type things
    // Can move through liquids including flowing lava
    IBlockState state = this.world.getBlockState(pos);
    Block b = state.getBlock();
    if (b.getMaterial(state) == Material.AIR) {
        return false;
    }
    if (noMineList.contains(b)) {
        blockingBlock.block = b;
        blockingBlock.meta = b.getMetaFromState(state);
        return true;
    }
    if (b instanceof BlockLiquid) {
        if ((b == Blocks.LAVA || b == Blocks.FLOWING_LAVA) && state.getValue(BlockLiquid.LEVEL) == 0 && this.AIstate != AISTATE_RETURNING) {
            blockingBlock.block = Blocks.LAVA;
            blockingBlock.meta = 0;
            return true;
        }
        return false;
    }
    if (b instanceof IFluidBlock) {
        return false;
    }
    boolean gtFlag = false;
    if (b != GCBlocks.fallenMeteor) {
        if (b instanceof IPlantable && b != Blocks.TALLGRASS && b != Blocks.DEADBUSH && b != Blocks.DOUBLE_PLANT && b != Blocks.WATERLILY && !(b instanceof BlockFlower) && b != Blocks.REEDS) {
            blockingBlock.block = b;
            blockingBlock.meta = b.getMetaFromState(state);
            return true;
        }
        int meta = b.getMetaFromState(state);
        if (b.getBlockHardness(state, this.world, pos) < 0) {
            blockingBlock.block = b;
            blockingBlock.meta = meta;
            return true;
        }
        if (b.hasTileEntity(state)) {
            if (CompatibilityManager.isGTLoaded() && gregTechCheck(b)) {
                gtFlag = true;
            } else {
                blockingBlock.block = b;
                blockingBlock.meta = meta;
                return true;
            }
        }
    }
    if (this.tryBlockLimit == 0) {
        return false;
    }
    int result = ForgeHooks.onBlockBreakEvent(this.world, this.playerMP.interactionManager.getGameType(), this.playerMP, pos);
    if (result < 0) {
        blockingBlock.block = Blocks.STONE;
        blockingBlock.meta = 0;
        return true;
    }
    this.tryBlockLimit--;
    // Collect the mined block - unless it's a plant or leaves in which case just break it
    if (!((b instanceof IPlantable && !(b instanceof BlockReed)) || b instanceof BlockLeaves)) {
        ItemStack drops = gtFlag ? getGTDrops(this.world, pos, b) : getPickBlock(this.world, pos, b);
        if (drops != null && !this.addToInventory(drops)) {
            // drop itemstack if AstroMiner can't hold it
            dropStack(pos, drops);
        }
    }
    this.world.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockLiquid(net.minecraft.block.BlockLiquid) BlockLeaves(net.minecraft.block.BlockLeaves) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) IPlantable(net.minecraftforge.common.IPlantable) Block(net.minecraft.block.Block) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) ItemStack(net.minecraft.item.ItemStack) BlockFlower(net.minecraft.block.BlockFlower) BlockReed(net.minecraft.block.BlockReed)

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