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