Search in sources :

Example 1 with PartWireBase

use of pl.asie.charset.wires.logic.PartWireBase 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 2 with PartWireBase

use of pl.asie.charset.wires.logic.PartWireBase 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 3 with PartWireBase

use of pl.asie.charset.wires.logic.PartWireBase 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)

Example 4 with PartWireBase

use of pl.asie.charset.wires.logic.PartWireBase in project Charset by CharsetMC.

the class RendererWire method getGeneralQuads.

@Override
public List<BakedQuad> getGeneralQuads() {
    List<BakedQuad> quads = new ArrayList<BakedQuad>();
    PartWireBase wire = null;
    if (state instanceof IExtendedBlockState) {
        wire = ((IExtendedBlockState) state).getValue(PartWireBase.PROPERTY);
    }
    if (wire != null) {
        renderers.get(getRendererId()).handlePartState(state);
        renderers.get(getRendererId()).addWire(wire, wire.location, wire.getRedstoneLevel() > 0, quads);
    } else if (stack != null) {
        if (ItemWire.isFreestanding(stack)) {
            renderers.get(getRendererId()).handleItemState(stack);
            renderers.get(getRendererId()).addWireFreestanding(null, false, quads);
        } else {
            renderers.get(getRendererId()).handleItemState(stack);
            renderers.get(getRendererId()).addWire(null, WireFace.DOWN, false, quads);
        }
    }
    return quads;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) PartWireBase(pl.asie.charset.wires.logic.PartWireBase) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) ArrayList(java.util.ArrayList)

Example 5 with PartWireBase

use of pl.asie.charset.wires.logic.PartWireBase in project Charset by CharsetMC.

the class ItemWire method createPart.

@Override
public IMultipart createPart(World world, BlockPos blockPos, EnumFacing facing, Vec3 vec3, ItemStack stack, EntityPlayer player) {
    PartWireBase part = PartWireProvider.createPart(stack.getItemDamage() >> 1);
    part.location = isFreestanding(stack) ? WireFace.CENTER : WireFace.get(facing);
    return part;
}
Also used : PartWireBase(pl.asie.charset.wires.logic.PartWireBase)

Aggregations

PartWireBase (pl.asie.charset.wires.logic.PartWireBase)6 IMultipartContainer (mcmultipart.multipart.IMultipartContainer)4 Block (net.minecraft.block.Block)2 BlockPos (net.minecraft.util.BlockPos)2 ArrayList (java.util.ArrayList)1 IMultipart (mcmultipart.multipart.IMultipart)1 IRedstonePart (mcmultipart.multipart.IRedstonePart)1 BlockRedstoneWire (net.minecraft.block.BlockRedstoneWire)1 IBlockState (net.minecraft.block.state.IBlockState)1 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)1 EnumFacing (net.minecraft.util.EnumFacing)1 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)1 WireFace (pl.asie.charset.api.wires.WireFace)1