Search in sources :

Example 11 with WireFace

use of pl.asie.charset.api.wires.WireFace in project Charset by CharsetMC.

the class PartWireBundled method propagate.

private void propagate(int color, byte[][] nValues) {
    int maxSignal = 0;
    int[] neighborLevel = new int[7];
    boolean[] isWire = new boolean[7];
    PartWireBase.PROPAGATING = true;
    if (internalConnections > 0) {
        for (WireFace location : WireFace.VALUES) {
            if (connectsInternal(location)) {
                isWire[location.ordinal()] = true;
                neighborLevel[location.ordinal()] = WireUtils.getBundledWireLevel(getContainer(), location, color);
            }
        }
    }
    for (EnumFacing facing : EnumFacing.VALUES) {
        if (connectsExternal(facing)) {
            if (nValues[facing.ordinal()] != null) {
                int v = nValues[facing.ordinal()][color] << 8;
                if (v != 0) {
                    neighborLevel[facing.ordinal()] = v | 0xFF;
                }
            } else {
                IMultipartContainer container = MultipartHelper.getPartContainer(getWorld(), getPos().offset(facing));
                if (container != null) {
                    isWire[facing.ordinal()] = true;
                    neighborLevel[facing.ordinal()] = WireUtils.getBundledWireLevel(container, location, color);
                }
            }
        } else if (connectsCorner(facing)) {
            BlockPos cornerPos = getPos().offset(facing).offset(location.facing);
            IMultipartContainer container = MultipartHelper.getPartContainer(getWorld(), cornerPos);
            if (container != null) {
                isWire[facing.ordinal()] = true;
                neighborLevel[facing.ordinal()] = WireUtils.getBundledWireLevel(container, WireFace.get(facing.getOpposite()), color);
            }
        }
    }
    PartWireBase.PROPAGATING = false;
    int newSignal = 0;
    for (int j = 0; j < 7; j++) {
        if (neighborLevel[j] > maxSignal) {
            maxSignal = neighborLevel[j];
        }
        if (!isWire[j] && neighborLevel[j] > newSignal) {
            newSignal = neighborLevel[j];
        }
    }
    if (DEBUG) {
        System.out.println("[" + color + "] Levels: " + Arrays.toString(neighborLevel));
    }
    if (maxSignal > signalLevel[color] && maxSignal > 1) {
        newSignal = maxSignal - 1;
        if ((newSignal & 0xFF) == 0 || (newSignal & 0xFF) == 0xFF) {
            newSignal = 0;
        }
    }
    if (newSignal == signalLevel[color]) {
        return;
    }
    signalLevel[color] = newSignal;
    signalValue[color] = (byte) (newSignal >> 8);
    if (newSignal == 0) {
        for (WireFace nLoc : WireFace.VALUES) {
            if (connectsInternal(nLoc)) {
                if (neighborLevel[nLoc.ordinal()] > 0) {
                    WireUtils.getWire(getContainer(), nLoc).onSignalChanged(color);
                }
            } else if (nLoc != WireFace.CENTER) {
                EnumFacing facing = nLoc.facing;
                if (connectsExternal(facing)) {
                    IMultipartContainer container = MultipartHelper.getPartContainer(getWorld(), getPos().offset(facing));
                    if (container == null || WireUtils.getWire(container, location) == null || neighborLevel[facing.ordinal()] > 0) {
                        propagateNotify(facing, color);
                    }
                } else if (connectsCorner(facing)) {
                    if (neighborLevel[facing.ordinal()] > 0) {
                        propagateNotifyCorner(location.facing, facing, color);
                    }
                }
            }
        }
    } else {
        for (WireFace nLoc : WireFace.VALUES) {
            if (neighborLevel[nLoc.ordinal()] < newSignal - 1 || neighborLevel[nLoc.ordinal()] > (newSignal + 1)) {
                if (connectsInternal(nLoc)) {
                    WireUtils.getWire(getContainer(), nLoc).onSignalChanged(color);
                } else if (nLoc != WireFace.CENTER) {
                    EnumFacing facing = nLoc.facing;
                    if (connectsExternal(facing)) {
                        propagateNotify(facing, color);
                    } else if (connectsCorner(facing)) {
                        propagateNotifyCorner(location.facing, facing, color);
                    }
                }
            }
        }
    }
    finishPropagation();
}
Also used : IMultipartContainer(mcmultipart.multipart.IMultipartContainer) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.BlockPos) WireFace(pl.asie.charset.api.wires.WireFace)

Aggregations

WireFace (pl.asie.charset.api.wires.WireFace)11 EnumFacing (net.minecraft.util.EnumFacing)6 IMultipartContainer (mcmultipart.multipart.IMultipartContainer)4 IBlockState (net.minecraft.block.state.IBlockState)3 TileEntity (net.minecraft.tileentity.TileEntity)3 BlockPos (net.minecraft.util.BlockPos)3 Block (net.minecraft.block.Block)2 ItemStack (net.minecraft.item.ItemStack)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Nullable (javax.annotation.Nullable)1 IPartInfo (mcmultipart.api.container.IPartInfo)1 IMultipart (mcmultipart.api.multipart.IMultipart)1 EnumCenterSlot (mcmultipart.api.slot.EnumCenterSlot)1 EnumFaceSlot (mcmultipart.api.slot.EnumFaceSlot)1 IPartSlot (mcmultipart.api.slot.IPartSlot)1 IMultipartWorld (mcmultipart.api.world.IMultipartWorld)1 IMultipart (mcmultipart.multipart.IMultipart)1