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;
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations