Search in sources :

Example 21 with BlockFenceGate

use of net.minecraft.block.BlockFenceGate in project Railcraft by Railcraft.

the class PostConnectionHelper method connect.

public static ConnectStyle connect(IBlockAccess world, BlockPos pos, IBlockState state, EnumFacing side) {
    try {
        Block block = state.getBlock();
        if (block instanceof IPostConnection && ((IPostConnection) block).connectsToPost(world, pos, state, side) == ConnectStyle.NONE)
            return ConnectStyle.NONE;
    } catch (Error error) {
        Game.log().api(Railcraft.NAME, error, IPostConnection.class);
        return ConnectStyle.NONE;
    }
    BlockPos otherPos = pos.offset(side);
    if (world.isAirBlock(otherPos))
        return ConnectStyle.NONE;
    IBlockState otherState = WorldPlugin.getBlockState(world, otherPos);
    Block otherBlock = otherState.getBlock();
    EnumFacing oppositeSide = side.getOpposite();
    try {
        if (otherBlock instanceof IPostConnection)
            return ((IPostConnection) otherBlock).connectsToPost(world, otherPos, otherState, oppositeSide);
    } catch (Error error) {
        Game.log().api(Railcraft.NAME, error, IPostConnection.class);
    }
    if (otherBlock instanceof BlockPostBase)
        return ConnectStyle.TWO_THIN;
    if (noConnect.contains(otherBlock))
        return ConnectStyle.NONE;
    if (canConnect.contains(otherBlock))
        return ConnectStyle.TWO_THIN;
    if (otherBlock instanceof BlockFenceGate) {
        return otherState.getValue(BlockFenceGate.FACING).getAxis() != side.getAxis() ? ConnectStyle.TWO_THIN : ConnectStyle.NONE;
    }
    if (otherBlock instanceof BlockWallSign) {
        return otherState.getValue(BlockWallSign.FACING) == side ? ConnectStyle.SINGLE_THICK : ConnectStyle.NONE;
    }
    if (otherBlock instanceof BlockLantern)
        return ConnectStyle.SINGLE_THICK;
    if (world.isSideSolid(pos, oppositeSide, false))
        return ConnectStyle.TWO_THIN;
    return ConnectStyle.NONE;
}
Also used : BlockLantern(mods.railcraft.common.blocks.aesthetics.materials.BlockLantern) IPostConnection(mods.railcraft.api.core.IPostConnection) IBlockState(net.minecraft.block.state.IBlockState) BlockFenceGate(net.minecraft.block.BlockFenceGate) EnumFacing(net.minecraft.util.EnumFacing) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) BlockWallSign(net.minecraft.block.BlockWallSign)

Example 22 with BlockFenceGate

use of net.minecraft.block.BlockFenceGate in project Galacticraft by micdoodle8.

the class BlockWallGC method canConnectTo.

// @Override
// public void setBlockBoundsBasedOnState(IBlockAccess world, BlockPos pos)
// {
// boolean flag = this.canConnectTo(world, pos.north());
// boolean flag1 = this.canConnectTo(world, pos.south());
// boolean flag2 = this.canConnectTo(world, pos.west());
// boolean flag3 = this.canConnectTo(world, pos.east());
// float f = 0.25F;
// float f1 = 0.75F;
// float f2 = 0.25F;
// float f3 = 0.75F;
// float f4 = 1.0F;
// 
// if (flag)
// {
// f2 = 0.0F;
// }
// if (flag1)
// {
// f3 = 1.0F;
// }
// if (flag2)
// {
// f = 0.0F;
// }
// if (flag3)
// {
// f1 = 1.0F;
// }
// 
// if (flag && flag1 && !flag2 && !flag3)
// {
// f4 = 0.8125F;
// f = 0.3125F;
// f1 = 0.6875F;
// }
// else if (!flag && !flag1 && flag2 && flag3)
// {
// f4 = 0.8125F;
// f2 = 0.3125F;
// f3 = 0.6875F;
// }
// this.setBlockBounds(f, 0.0F, f2, f1, f4, f3);
// }
// @Override
// public AxisAlignedBB getCollisionBoundingBox(World world, BlockPos pos, IBlockState state)
// {
// this.setBlockBoundsBasedOnState(world, pos);
// this.maxY = 1.5D;
// return super.getCollisionBoundingBox(world, pos, state);
// }
private boolean canConnectTo(IBlockAccess world, BlockPos pos) {
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    return block == Blocks.BARRIER ? false : block != this && !(block instanceof BlockFenceGate) ? block.getMaterial(state).isOpaque() && block.isFullCube(state) ? block.getMaterial(state) != Material.GOURD : false : true;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) BlockFenceGate(net.minecraft.block.BlockFenceGate) EnumSortCategoryBlock(micdoodle8.mods.galacticraft.core.util.EnumSortCategoryBlock) Block(net.minecraft.block.Block)

Aggregations

BlockFenceGate (net.minecraft.block.BlockFenceGate)22 Block (net.minecraft.block.Block)20 IBlockState (net.minecraft.block.state.IBlockState)18 BlockFence (net.minecraft.block.BlockFence)7 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)5 BlockWall (net.minecraft.block.BlockWall)3 Entity (net.minecraft.entity.Entity)3 EnumFacing (net.minecraft.util.EnumFacing)3 BlockPos (net.minecraft.util.math.BlockPos)3 IELadderBlock (blusunrize.immersiveengineering.common.blocks.BlockIEBase.IELadderBlock)2 BlockDoor (net.minecraft.block.BlockDoor)2 BlockTrapDoor (net.minecraft.block.BlockTrapDoor)2 BlockFaceShape (net.minecraft.block.state.BlockFaceShape)2 CrashReport (net.minecraft.crash.CrashReport)2 CrashReportCategory (net.minecraft.crash.CrashReportCategory)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 MoverType (net.minecraft.entity.MoverType)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ItemStack (net.minecraft.item.ItemStack)2 ReportedException (net.minecraft.util.ReportedException)2