Search in sources :

Example 1 with IMultipartContainer

use of mcmultipart.multipart.IMultipartContainer in project Charset by CharsetMC.

the class CharsetHelperImpl method getInterfaceList.

@Override
public <T> List<T> getInterfaceList(Class<T> clazz, World world, BlockPos pos) {
    IMultipartContainer container = MultipartHelper.getPartContainer(world, pos);
    List<T> list = new ArrayList<T>();
    if (container == null) {
        TileEntity tile = world.getTileEntity(pos);
        if (tile != null && clazz.isAssignableFrom(tile.getClass())) {
            list.add((T) tile);
        }
    } else {
        for (IMultipart part : container.getParts()) {
            if (clazz.isAssignableFrom(part.getClass())) {
                list.add((T) part);
            }
        }
    }
    return list;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IMultipartContainer(mcmultipart.multipart.IMultipartContainer) ArrayList(java.util.ArrayList) IMultipart(mcmultipart.multipart.IMultipart)

Example 2 with IMultipartContainer

use of mcmultipart.multipart.IMultipartContainer in project Charset by CharsetMC.

the class ItemPartSlab method createPart.

@Override
public IMultipart createPart(World world, BlockPos blockPos, EnumFacing facing, Vec3 vec3, ItemStack stack, EntityPlayer player) {
    PartSlab slab = createPartSlab(world, blockPos, facing, vec3, stack, player);
    slab.isTop = facing == EnumFacing.UP || (vec3.yCoord >= 0.5 && facing != EnumFacing.DOWN);
    IMultipartContainer container = MultipartHelper.getPartContainer(world, blockPos);
    if (container != null) {
        boolean occupiedDown = false;
        if (container.getPartInSlot(PartSlot.DOWN) != null || !OcclusionHelper.occlusionTest(container.getParts(), PartSlab.BOXES[0])) {
            slab.isTop = true;
            occupiedDown = true;
        }
        if (slab.isTop && (container.getPartInSlot(PartSlot.UP) != null || !OcclusionHelper.occlusionTest(container.getParts(), PartSlab.BOXES[1]))) {
            if (occupiedDown) {
                return null;
            } else {
                slab.isTop = false;
            }
        }
    }
    return slab;
}
Also used : IMultipartContainer(mcmultipart.multipart.IMultipartContainer)

Example 3 with IMultipartContainer

use of mcmultipart.multipart.IMultipartContainer in project Charset by CharsetMC.

the class WireUtils method getRedstoneLevel.

public static int getRedstoneLevel(World world, BlockPos pos, IBlockState state, EnumFacing facing, WireFace face, boolean weak) {
    int power = 0;
    IMultipartContainer container = MultipartHelper.getPartContainer(world, pos);
    if (container != null) {
        if (getWire(container, face) != null || getWire(container, WireFace.get(facing.getOpposite())) != null) {
            return 0;
        }
        for (IMultipart part : container.getParts()) {
            if (!(part instanceof PartWireBase)) {
                if (part instanceof IRedstonePart) {
                    power = Math.max(power, ((IRedstonePart) part).getWeakSignal(facing.getOpposite()));
                }
            }
        }
    }
    if (MultipartUtils.hasCapability(Capabilities.REDSTONE_EMITTER, world, pos, WireUtils.getSlotForFace(face), facing)) {
        power = Math.max(power, MultipartUtils.getCapability(Capabilities.REDSTONE_EMITTER, world, pos, WireUtils.getSlotForFace(face), facing).getRedstoneSignal());
    }
    Block block = state.getBlock();
    if (power == 0) {
        if (weak) {
            if (block instanceof BlockRedstoneWire && face == WireFace.DOWN) {
                return state.getValue(BlockRedstoneWire.POWER);
            }
            return block.shouldCheckWeakPower(world, pos, facing) ? block.getStrongPower(world, pos, state, facing) : block.getWeakPower(world, pos, state, facing);
        } else {
            return block.getStrongPower(world, pos, state, facing);
        }
    } else {
        return power;
    }
}
Also used : IRedstonePart(mcmultipart.multipart.IRedstonePart) PartWireBase(pl.asie.charset.wires.logic.PartWireBase) IMultipartContainer(mcmultipart.multipart.IMultipartContainer) Block(net.minecraft.block.Block) IMultipart(mcmultipart.multipart.IMultipart) BlockRedstoneWire(net.minecraft.block.BlockRedstoneWire)

Example 4 with IMultipartContainer

use of mcmultipart.multipart.IMultipartContainer in project Charset by CharsetMC.

the class WireUtils method canConnectCorner.

public static boolean canConnectCorner(PartWireBase wire, EnumFacing direction) {
    if (wire.location == WireFace.CENTER || wire.isCornerOccluded(direction)) {
        return false;
    }
    EnumFacing side = wire.location.facing;
    IMultipartContainer container = wire.getContainer();
    if (isBlockingPart(container, PartSlot.getFaceSlot(direction)) || isBlockingPart(container, PartSlot.getEdgeSlot(direction, wire.location.facing))) {
        return false;
    }
    BlockPos middlePos = wire.getPos().offset(direction);
    if (wire.getWorld().isSideSolid(middlePos, direction.getOpposite()) || wire.getWorld().isSideSolid(middlePos, side.getOpposite())) {
        return false;
    }
    BlockPos cornerPos = middlePos.offset(side);
    container = MultipartHelper.getPartContainer(wire.getWorld(), cornerPos);
    if (container == null) {
        return false;
    }
    if (isBlockingPart(container, PartSlot.getFaceSlot(side.getOpposite())) || isBlockingPart(container, PartSlot.getEdgeSlot(side.getOpposite(), direction.getOpposite()))) {
        return false;
    }
    PartWireBase wire2 = getWire(container, WireFace.get(direction.getOpposite()));
    if (wire2 == null || wire2.isCornerOccluded(side.getOpposite()) || !wire2.type.connects(wire.type)) {
        return false;
    }
    container = MultipartHelper.getPartContainer(wire.getWorld(), middlePos);
    if (container != null) {
        if (isBlockingPart(container, PartSlot.getFaceSlot(direction.getOpposite())) || isBlockingPart(container, PartSlot.getFaceSlot(side)) || isBlockingPart(container, PartSlot.getEdgeSlot(direction.getOpposite(), side))) {
            return false;
        }
    }
    return true;
}
Also used : PartWireBase(pl.asie.charset.wires.logic.PartWireBase) IMultipartContainer(mcmultipart.multipart.IMultipartContainer) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.BlockPos)

Example 5 with IMultipartContainer

use of mcmultipart.multipart.IMultipartContainer in project Charset by CharsetMC.

the class WireUtils method canConnectExternal.

public static boolean canConnectExternal(PartWireBase wire, EnumFacing facing) {
    IMultipartContainer container = wire.getContainer();
    if (isBlockingPart(container, PartSlot.getFaceSlot(facing))) {
        return false;
    }
    if (wire.location != WireFace.CENTER && isBlockingPart(container, PartSlot.getEdgeSlot(facing, wire.location.facing))) {
        return false;
    }
    BlockPos pos2 = wire.getPos().offset(facing);
    IMultipartContainer container2 = MultipartHelper.getPartContainer(wire.getWorld(), pos2);
    if (container2 != null) {
        PartWireBase wire2 = getWire(container2, wire.location);
        if (wire2 != null) {
            if (isBlockingPart(container2, PartSlot.getFaceSlot(facing.getOpposite()))) {
                return false;
            }
            if (wire2.isOccluded(facing.getOpposite())) {
                return false;
            }
            if (wire.location != WireFace.CENTER && isBlockingPart(container2, PartSlot.getEdgeSlot(facing.getOpposite(), wire.location.facing))) {
                return false;
            }
            return wire2.type.connects(wire.type);
        }
    }
    if (wire.type.type() == WireType.BUNDLED) {
        if (MultipartUtils.hasCapability(Capabilities.BUNDLED_EMITTER, wire.getWorld(), pos2, WireUtils.getSlotForFace(wire.location), facing.getOpposite())) {
            return true;
        }
        if (MultipartUtils.hasCapability(Capabilities.BUNDLED_RECEIVER, wire.getWorld(), pos2, WireUtils.getSlotForFace(wire.location), facing.getOpposite())) {
            return true;
        }
    } else {
        if (MultipartUtils.hasCapability(Capabilities.REDSTONE_EMITTER, wire.getWorld(), pos2, WireUtils.getSlotForFace(wire.location), facing.getOpposite())) {
            return true;
        }
        if (MultipartUtils.hasCapability(Capabilities.REDSTONE_RECEIVER, wire.getWorld(), pos2, WireUtils.getSlotForFace(wire.location), facing.getOpposite())) {
            return true;
        }
        IBlockState connectingState = wire.getWorld().getBlockState(pos2);
        Block connectingBlock = connectingState.getBlock();
        if (wire.location == WireFace.CENTER && !connectingBlock.isSideSolid(wire.getWorld(), pos2, facing.getOpposite())) {
            return false;
        }
        WIRES_CONNECT = false;
        if (RedstoneUtils.canConnectFace(wire.getWorld(), pos2, connectingState, facing, wire.location.facing)) {
            WIRES_CONNECT = true;
            return true;
        }
        WIRES_CONNECT = true;
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) PartWireBase(pl.asie.charset.wires.logic.PartWireBase) IMultipartContainer(mcmultipart.multipart.IMultipartContainer) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.BlockPos)

Aggregations

IMultipartContainer (mcmultipart.multipart.IMultipartContainer)14 BlockPos (net.minecraft.util.BlockPos)7 EnumFacing (net.minecraft.util.EnumFacing)6 Block (net.minecraft.block.Block)4 BlockRedstoneWire (net.minecraft.block.BlockRedstoneWire)4 IBlockState (net.minecraft.block.state.IBlockState)4 TileEntity (net.minecraft.tileentity.TileEntity)4 WireFace (pl.asie.charset.api.wires.WireFace)4 PartWireBase (pl.asie.charset.wires.logic.PartWireBase)4 IMultipart (mcmultipart.multipart.IMultipart)3 ArrayList (java.util.ArrayList)2 World (net.minecraft.world.World)2 UUID (java.util.UUID)1 IMicroblock (mcmultipart.microblock.IMicroblock)1 IOccludingPart (mcmultipart.multipart.IOccludingPart)1 IRedstonePart (mcmultipart.multipart.IRedstonePart)1 ISlottedPart (mcmultipart.multipart.ISlottedPart)1 BlockBasePressurePlate (net.minecraft.block.BlockBasePressurePlate)1 BlockButton (net.minecraft.block.BlockButton)1 BlockDaylightDetector (net.minecraft.block.BlockDaylightDetector)1