use of mcmultipart.multipart.IMultipart 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.IMultipart 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.IMultipart in project Charset by CharsetMC.
the class MultipartUtils method getInterfaceCenter.
public static <T> T getInterfaceCenter(Class<T> clazz, IMultipartContainer container) {
ISlottedPart part = container.getPartInSlot(PartSlot.CENTER);
if (part != null && clazz.isAssignableFrom(part.getClass())) {
return (T) part;
} else {
Iterator var4 = container.getParts().iterator();
IMultipart p;
do {
do {
if (!var4.hasNext()) {
return null;
}
p = (IMultipart) var4.next();
} while (p instanceof ISlottedPart && !((ISlottedPart) p).getSlotMask().isEmpty());
} while (p == null || !clazz.isAssignableFrom(p.getClass()));
return (T) p;
}
}
use of mcmultipart.multipart.IMultipart in project Charset by CharsetMC.
the class PartWireBase method updateConnections.
public void updateConnections() {
Set<WireFace> validSides = EnumSet.noneOf(WireFace.class);
Set<WireFace> invalidCornerSides = EnumSet.noneOf(WireFace.class);
for (WireFace facing : WireFace.VALUES) {
if (facing == location) {
continue;
}
if (facing != WireFace.CENTER && location != WireFace.CENTER && location.facing.getAxis() == facing.facing.getAxis()) {
continue;
}
validSides.add(facing);
}
int oldConnectionCache = internalConnections << 12 | externalConnections << 6 | cornerConnections;
internalConnections = externalConnections = cornerConnections = occludedSides = cornerOccludedSides = 0;
// Occlusion test
EnumFacing[] connFaces = WireUtils.getConnectionsForRender(location);
List<IMultipart> parts = new ArrayList<IMultipart>();
for (IMultipart p : getContainer().getParts()) {
if (p != this && p instanceof IOccludingPart && !(p instanceof PartWireBase)) {
parts.add(p);
}
}
if (parts.size() > 0) {
for (int i = 0; i < connFaces.length; i++) {
WireFace face = WireFace.get(connFaces[i]);
if (validSides.contains(face)) {
boolean found = false;
AxisAlignedBB mask = getBox(i + 1);
if (mask != null) {
if (!OcclusionHelper.occlusionTest(parts, this, mask)) {
occludedSides |= 1 << connFaces[i].ordinal();
validSides.remove(face);
found = true;
}
}
if (!found && location != WireFace.CENTER) {
BlockPos cPos = getPos().offset(connFaces[i]);
AxisAlignedBB cornerMask = getCornerBox(i ^ 1);
if (cornerMask != null) {
IMultipartContainer cornerContainer = MultipartHelper.getPartContainer(getWorld(), cPos);
if (cornerContainer != null) {
if (!OcclusionHelper.occlusionTest(cornerContainer.getParts(), cornerMask)) {
cornerOccludedSides |= 1 << connFaces[i].ordinal();
invalidCornerSides.add(face);
}
} else {
List<AxisAlignedBB> boxes = new ArrayList<AxisAlignedBB>();
IBlockState cState = getWorld().getBlockState(cPos);
cState.getBlock().addCollisionBoxesToList(getWorld(), cPos, cState, cornerMask.offset(cPos.getX(), cPos.getY(), cPos.getZ()), boxes, null);
if (boxes.size() > 0) {
cornerOccludedSides |= 1 << connFaces[i].ordinal();
invalidCornerSides.add(face);
}
}
}
}
}
}
}
if (validSides.contains(WireFace.CENTER)) {
AxisAlignedBB mask = getCenterBox(1 + location.ordinal());
if (mask != null) {
if (!OcclusionHelper.occlusionTest(parts, this, mask)) {
occludedSides |= 1 << 6;
validSides.remove(WireFace.CENTER);
}
}
}
for (WireFace facing : validSides) {
if (WireUtils.canConnectInternal(this, facing)) {
internalConnections |= 1 << facing.ordinal();
} else if (facing != WireFace.CENTER) {
if (WireUtils.canConnectExternal(this, facing.facing)) {
externalConnections |= 1 << facing.ordinal();
} else if (location != WireFace.CENTER && !invalidCornerSides.contains(facing) && WireUtils.canConnectCorner(this, facing.facing)) {
cornerConnections |= 1 << facing.ordinal();
}
}
}
int newConnectionCache = internalConnections << 12 | externalConnections << 6 | cornerConnections;
if (oldConnectionCache != newConnectionCache) {
scheduleNeighborUpdate((oldConnectionCache ^ newConnectionCache) >> 6);
schedulePropagationUpdate();
scheduleRenderUpdate();
}
}
use of mcmultipart.multipart.IMultipart in project Charset by CharsetMC.
the class PartWireBase method pokeExtendedNeighbors.
private void pokeExtendedNeighbors() {
if (getContainer() != null) {
for (IMultipart multipart : getContainer().getParts()) {
if (multipart instanceof PartWireBase) {
multipart.onNeighborBlockChange(MCMultiPartMod.multipart);
}
}
}
World world = this.getWorld();
BlockPos pos = this.getPos();
if (world != null) {
world.notifyNeighborsRespectDebug(pos, MCMultiPartMod.multipart);
for (EnumFacing facing : EnumFacing.VALUES) {
world.notifyNeighborsOfStateExcept(pos.offset(facing), MCMultiPartMod.multipart, facing.getOpposite());
}
}
}
Aggregations