Search in sources :

Example 1 with IRedstonePart

use of mcmultipart.multipart.IRedstonePart 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)

Aggregations

IMultipart (mcmultipart.multipart.IMultipart)1 IMultipartContainer (mcmultipart.multipart.IMultipartContainer)1 IRedstonePart (mcmultipart.multipart.IRedstonePart)1 Block (net.minecraft.block.Block)1 BlockRedstoneWire (net.minecraft.block.BlockRedstoneWire)1 PartWireBase (pl.asie.charset.wires.logic.PartWireBase)1