Search in sources :

Example 1 with IPartialSealableBlock

use of micdoodle8.mods.galacticraft.api.block.IPartialSealableBlock in project Galacticraft by micdoodle8.

the class OxygenPressureProtocol method canBlockPassAir.

public static boolean canBlockPassAir(World world, Block block, BlockPos pos, EnumFacing side) {
    if (block == null) {
        return true;
    }
    if (block instanceof IPartialSealableBlock) {
        return !((IPartialSealableBlock) block).isSealed(world, pos, side);
    }
    // (See net.minecraft.block.BlockLeaves.isOpaqueCube()!)
    if (block instanceof BlockLeavesBase) {
        return true;
    }
    if (block.isOpaqueCube()) {
        return block instanceof BlockGravel || block.getMaterial() == Material.cloth || block instanceof BlockSponge;
    }
    if (block instanceof BlockGlass || block instanceof BlockStainedGlass) {
        return false;
    }
    // Solid but non-opaque blocks, for example special glass
    if (OxygenPressureProtocol.nonPermeableBlocks.containsKey(block)) {
        ArrayList<Integer> metaList = OxygenPressureProtocol.nonPermeableBlocks.get(block);
        IBlockState state = world.getBlockState(pos);
        if (metaList.contains(Integer.valueOf(-1)) || metaList.contains(state.getBlock().getMetaFromState(state))) {
            return false;
        }
    }
    // Half slab seals on the top side or the bottom side according to its metadata
    if (block instanceof BlockSlab) {
        IBlockState state = world.getBlockState(pos);
        int meta = state.getBlock().getMetaFromState(state);
        return !(side == EnumFacing.DOWN && (meta & 8) == 8 || side == EnumFacing.UP && (meta & 8) == 0);
    }
    // Farmland etc only seals on the solid underside
    if (block instanceof BlockFarmland || block instanceof BlockEnchantmentTable || block instanceof BlockLiquid) {
        return side != EnumFacing.UP;
    }
    if (block instanceof BlockPistonBase) {
        BlockPistonBase piston = (BlockPistonBase) block;
        IBlockState state = world.getBlockState(pos);
        if (((Boolean) state.getValue(BlockPistonBase.EXTENDED)).booleanValue()) {
            EnumFacing facing = (EnumFacing) state.getValue(BlockPistonBase.FACING);
            return side != facing;
        }
        return false;
    }
    // ### Any exceptions in mods should implement the IPartialSealableBlock interface ###
    return !block.isSideSolid(world, pos, EnumFacing.getFront(side.getIndex() ^ 1));
}
Also used : IPartialSealableBlock(micdoodle8.mods.galacticraft.api.block.IPartialSealableBlock) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing)

Example 2 with IPartialSealableBlock

use of micdoodle8.mods.galacticraft.api.block.IPartialSealableBlock in project Galacticraft by micdoodle8.

the class ThreadFindSeal method canBlockPassAirCheck.

private boolean canBlockPassAirCheck(Block block, BlockVec3 vec, int side) {
    if (block instanceof IPartialSealableBlock) {
        EnumFacing testSide = EnumFacing.getFront(side);
        IPartialSealableBlock blockPartial = (IPartialSealableBlock) block;
        BlockPos vecPos = new BlockPos(vec.x, vec.y, vec.z);
        if (blockPartial.isSealed(this.world, vecPos, testSide)) {
            // If a partial block checks as solid, allow it to be tested
            // again from other directions
            // This won't cause an endless loop, because the block won't
            // be included in nextLayer if it checks as solid
            this.checkCount--;
            return false;
        }
        // Find the solid sides so they don't get iterated into, when doing the next layer
        for (EnumFacing face : EnumFacing.VALUES) {
            if (face == testSide) {
                continue;
            }
            if (blockPartial.isSealed(this.world, vecPos, face)) {
                vec.setSideDone(face.getIndex() ^ 1);
            }
        }
        checkedAdd(vec);
        return true;
    }
    // (See net.minecraft.block.BlockLeaves.isOpaqueCube()!)
    if (block instanceof BlockLeavesBase) {
        checkedAdd(vec);
        return true;
    }
    if (block.isOpaqueCube()) {
        checkedAdd(vec);
        // Gravel, wool and sponge are porous
        return block instanceof BlockGravel || block.getMaterial() == Material.cloth || block instanceof BlockSponge;
    }
    if (block instanceof BlockGlass || block instanceof BlockStainedGlass) {
        checkedAdd(vec);
        return false;
    }
    // Solid but non-opaque blocks, for example special glass
    if (OxygenPressureProtocol.nonPermeableBlocks.containsKey(block)) {
        ArrayList<Integer> metaList = OxygenPressureProtocol.nonPermeableBlocks.get(block);
        if (metaList.contains(Integer.valueOf(-1)) || metaList.contains(vec.getBlockMetadata(this.world))) {
            checkedAdd(vec);
            return false;
        }
    }
    if (block instanceof BlockUnlitTorch) {
        this.torchesToUpdate.add(vec);
        checkedAdd(vec);
        return true;
    }
    // Half slab seals on the top side or the bottom side according to its metadata
    if (block instanceof BlockSlab) {
        boolean isTopSlab = (vec.getBlockMetadata(this.world) & 8) == 8;
        // Looking down onto a top slab or looking up onto a bottom slab
        if (side == 0 && isTopSlab || side == 1 && !isTopSlab) {
            // Sealed from that solid side but allow other sides still to be checked
            this.checkCount--;
            return false;
        }
        // Not sealed
        vec.setSideDone(isTopSlab ? 1 : 0);
        checkedAdd(vec);
        return true;
    }
    // Farmland etc only seals on the solid underside
    if (block instanceof BlockFarmland || block instanceof BlockEnchantmentTable || block instanceof BlockLiquid) {
        if (side == 1) {
            // Sealed from the underside but allow other sides still to be checked
            this.checkCount--;
            return false;
        }
        // Not sealed
        vec.setSideDone(0);
        checkedAdd(vec);
        return true;
    }
    if (block instanceof BlockPistonBase) {
        BlockPistonBase piston = (BlockPistonBase) block;
        IBlockState state = this.world.getBlockState(new BlockPos(vec.x, vec.y, vec.z));
        if (((Boolean) state.getValue(BlockPistonBase.EXTENDED)).booleanValue()) {
            int facing = ((EnumFacing) state.getValue(BlockPistonBase.FACING)).getIndex();
            if (side == facing) {
                this.checkCount--;
                return false;
            }
            vec.setSideDone(facing ^ 1);
            checkedAdd(vec);
            return true;
        }
        checkedAdd(vec);
        return false;
    }
    // ### Any exceptions in mods should implement the IPartialSealableBlock interface ###
    if (block.isSideSolid(this.world, new BlockPos(vec.x, vec.y, vec.z), EnumFacing.getFront(side ^ 1))) {
        // Solid on all sides
        if (block.getMaterial().blocksMovement() && block.isFullCube()) {
            checkedAdd(vec);
            return false;
        }
        // Sealed from this side but allow other sides still to be checked
        this.checkCount--;
        return false;
    }
    // Easy case: airblock, return without checking other sides
    if (block.getMaterial() == Material.air) {
        checkedAdd(vec);
        return true;
    }
    // Look to see if there is any other side which is solid in which case a check will not be needed next time
    for (int i = 0; i < 6; i++) {
        if (i == (side ^ 1)) {
            continue;
        }
        if (block.isSideSolid(this.world, new BlockPos(vec.x, vec.y, vec.z), EnumFacing.getFront(i))) {
            vec.setSideDone(i);
        }
    }
    // Not solid from this side, so this is not sealed
    checkedAdd(vec);
    return true;
}
Also used : IPartialSealableBlock(micdoodle8.mods.galacticraft.api.block.IPartialSealableBlock) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BlockUnlitTorch(micdoodle8.mods.galacticraft.core.blocks.BlockUnlitTorch) BlockPos(net.minecraft.util.BlockPos) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 3 with IPartialSealableBlock

use of micdoodle8.mods.galacticraft.api.block.IPartialSealableBlock in project Galacticraft by micdoodle8.

the class OxygenUtil method canBlockPassAirOnSide.

// TODO - performance, could add a 'safe' version of this code (inside world borders)
// TODO - add more performance increase, these sided checks could be done once only
private static boolean canBlockPassAirOnSide(World world, Block block, BlockPos vec, EnumFacing side) {
    if (block instanceof IPartialSealableBlock) {
        return !((IPartialSealableBlock) block).isSealed(world, vec, side);
    }
    // Half slab seals on the top side or the bottom side according to its metadata
    if (block instanceof BlockSlab) {
        IBlockState state = world.getBlockState(vec);
        int meta = state.getBlock().getMetaFromState(state);
        return !(side == EnumFacing.DOWN && (meta & 8) == 8 || side == EnumFacing.UP && (meta & 8) == 0);
    }
    // Farmland etc only seals on the solid underside
    if (block instanceof BlockFarmland || block instanceof BlockEnchantmentTable || block instanceof BlockLiquid) {
        return side != EnumFacing.UP;
    }
    if (block instanceof BlockPistonBase) {
        IBlockState state = world.getBlockState(vec);
        if (((Boolean) state.getValue(BlockPistonBase.EXTENDED)).booleanValue()) {
            int meta0 = state.getBlock().getMetaFromState(state);
            EnumFacing facing = BlockPistonBase.getFacing(meta0);
            return side != facing;
        }
        return false;
    }
    return !block.isSideSolid(world, vec, EnumFacing.getFront(side.getIndex() ^ 1));
}
Also used : IPartialSealableBlock(micdoodle8.mods.galacticraft.api.block.IPartialSealableBlock) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing)

Aggregations

IPartialSealableBlock (micdoodle8.mods.galacticraft.api.block.IPartialSealableBlock)3 IBlockState (net.minecraft.block.state.IBlockState)3 EnumFacing (net.minecraft.util.EnumFacing)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 BlockUnlitTorch (micdoodle8.mods.galacticraft.core.blocks.BlockUnlitTorch)1 BlockPos (net.minecraft.util.BlockPos)1