Search in sources :

Example 1 with IOccludingPart

use of mcmultipart.multipart.IOccludingPart 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();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.AxisAlignedBB) IBlockState(net.minecraft.block.state.IBlockState) IMultipartContainer(mcmultipart.multipart.IMultipartContainer) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) WireFace(pl.asie.charset.api.wires.WireFace) BlockPos(net.minecraft.util.BlockPos) IMultipart(mcmultipart.multipart.IMultipart) IOccludingPart(mcmultipart.multipart.IOccludingPart)

Aggregations

ArrayList (java.util.ArrayList)1 IMultipart (mcmultipart.multipart.IMultipart)1 IMultipartContainer (mcmultipart.multipart.IMultipartContainer)1 IOccludingPart (mcmultipart.multipart.IOccludingPart)1 IBlockState (net.minecraft.block.state.IBlockState)1 AxisAlignedBB (net.minecraft.util.AxisAlignedBB)1 BlockPos (net.minecraft.util.BlockPos)1 EnumFacing (net.minecraft.util.EnumFacing)1 WireFace (pl.asie.charset.api.wires.WireFace)1