Search in sources :

Example 6 with TileCapBank

use of crazypants.enderio.powertools.machine.capbank.TileCapBank in project EnderIO by SleepyTrousers.

the class NetworkUtil method ensureValidNetwork.

public static void ensureValidNetwork(TileCapBank cap) {
    World world = cap.getWorld();
    Collection<TileCapBank> neighbours = getNeigbours(cap);
    if (reuseNetwork(cap, neighbours, world)) {
        return;
    }
    CapBankNetwork network = new CapBankNetwork(nextID.getAndIncrement());
    network.init(cap, neighbours, world);
    return;
}
Also used : TileCapBank(crazypants.enderio.powertools.machine.capbank.TileCapBank) World(net.minecraft.world.World)

Example 7 with TileCapBank

use of crazypants.enderio.powertools.machine.capbank.TileCapBank in project EnderIO by SleepyTrousers.

the class CapBankClientNetwork method computeIODisplayInfo.

@Nonnull
private IOInfo computeIODisplayInfo(int xOrg, int yOrg, int zOrg, @Nonnull EnumFacing dir) {
    if (dir.getFrontOffsetY() != 0) {
        return IOInfo.SINGLE;
    }
    TileCapBank cb = getCapBankAt(xOrg, yOrg, zOrg);
    if (cb == null) {
        return IOInfo.SINGLE;
    }
    CapBankType type = cb.getType();
    EnumFacing left = dir.rotateYCCW();
    EnumFacing right = left.getOpposite();
    int hOff = 0;
    int vOff = 0;
    // step 1: find top left
    while (isIOType(xOrg + left.getFrontOffsetX(), yOrg, zOrg + left.getFrontOffsetZ(), dir, type)) {
        xOrg += left.getFrontOffsetX();
        zOrg += left.getFrontOffsetZ();
        hOff++;
    }
    while (isIOType(xOrg, yOrg + 1, zOrg, dir, type)) {
        yOrg++;
        vOff++;
    }
    if (isIOType(xOrg + left.getFrontOffsetX(), yOrg, zOrg + left.getFrontOffsetZ(), dir, type)) {
        // not a rectangle
        return IOInfo.SINGLE;
    }
    // step 2: find width
    int width = 1;
    int height = 1;
    int xTmp = xOrg;
    int yTmp = yOrg;
    int zTmp = zOrg;
    while (isIOType(xTmp + right.getFrontOffsetX(), yTmp, zTmp + right.getFrontOffsetZ(), dir, type)) {
        if (isIOType(xTmp + right.getFrontOffsetX(), yTmp + 1, zTmp + right.getFrontOffsetZ(), dir, type)) {
            // not a rectangle
            return IOInfo.SINGLE;
        }
        xTmp += right.getFrontOffsetX();
        zTmp += right.getFrontOffsetZ();
        width++;
    }
    // step 3: find height
    while (isIOType(xOrg, yTmp - 1, zOrg, dir, type)) {
        xTmp = xOrg;
        yTmp--;
        zTmp = zOrg;
        if (isIOType(xTmp + left.getFrontOffsetX(), yTmp, zTmp + left.getFrontOffsetZ(), dir, type)) {
            // not a rectangle
            return IOInfo.SINGLE;
        }
        for (int i = 1; i < width; i++) {
            xTmp += right.getFrontOffsetX();
            zTmp += right.getFrontOffsetZ();
            if (!isIOType(xTmp, yTmp, zTmp, dir, type)) {
                // not a rectangle
                return IOInfo.SINGLE;
            }
        }
        if (isIOType(xTmp + right.getFrontOffsetX(), yTmp, zTmp + right.getFrontOffsetZ(), dir, type)) {
            // not a rectangle
            return IOInfo.SINGLE;
        }
        height++;
    }
    xTmp = xOrg;
    yTmp--;
    zTmp = zOrg;
    for (int i = 0; i < width; i++) {
        if (isIOType(xTmp, yTmp, zTmp, dir, type)) {
            // not a rectangle
            return IOInfo.SINGLE;
        }
        xTmp += right.getFrontOffsetX();
        zTmp += right.getFrontOffsetZ();
    }
    if (width == 1 && height == 1) {
        return IOInfo.SINGLE;
    }
    if (hOff > 0 || vOff > 0) {
        return IOInfo.INSIDE;
    }
    return new IOInfo(width, height);
}
Also used : TileCapBank(crazypants.enderio.powertools.machine.capbank.TileCapBank) CapBankType(crazypants.enderio.powertools.machine.capbank.CapBankType) EnumFacing(net.minecraft.util.EnumFacing) Nonnull(javax.annotation.Nonnull)

Example 8 with TileCapBank

use of crazypants.enderio.powertools.machine.capbank.TileCapBank in project EnderIO by SleepyTrousers.

the class CapBankClientNetwork method destroyNetwork.

@Override
public void destroyNetwork() {
    for (TileCapBank cb : members.values()) {
        cb.setNetworkId(-1);
        cb.setNetwork(null);
    }
    invalidateDisplayInfoCache();
}
Also used : TileCapBank(crazypants.enderio.powertools.machine.capbank.TileCapBank)

Example 9 with TileCapBank

use of crazypants.enderio.powertools.machine.capbank.TileCapBank in project EnderIO by SleepyTrousers.

the class CapBankNetwork method destroyNetwork.

@Override
public void destroyNetwork() {
    ServerTickHandler.removeListener(this);
    distributeEnergyToBanks();
    TileCapBank cap = null;
    for (TileCapBank cb : capBanks) {
        cb.setNetwork(null);
        if (cap == null) {
            cap = cb;
        }
    }
    capBanks.clear();
    if (cap != null) {
        PacketHandler.INSTANCE.sendToAll(new PacketNetworkStateResponse(this, true));
    }
}
Also used : TileCapBank(crazypants.enderio.powertools.machine.capbank.TileCapBank) PacketNetworkStateResponse(crazypants.enderio.powertools.machine.capbank.packet.PacketNetworkStateResponse)

Example 10 with TileCapBank

use of crazypants.enderio.powertools.machine.capbank.TileCapBank in project EnderIO by SleepyTrousers.

the class CapBankNetwork method setMaxInput.

@Override
public void setMaxInput(int max) {
    if (DiagnosticsConfig.debugTraceCapLimitsExtremelyDetailed.get()) {
        StringBuilder sb = new StringBuilder("CapBankNetwork ").append(this).append(" intput changed from ").append(this.maxInput).append(" to ").append(max);
        for (StackTraceElement elem : new Exception("Stackstrace").getStackTrace()) {
            sb.append(" at ").append(elem);
        }
        Log.warn(sb);
    }
    if (max >= maxIO) {
        maxInput = -1;
    } else if (max < 0) {
        maxInput = 0;
    } else {
        maxInput = max;
    }
    for (TileCapBank cb : capBanks) {
        cb.setMaxInput(maxInput);
    }
}
Also used : TileCapBank(crazypants.enderio.powertools.machine.capbank.TileCapBank)

Aggregations

TileCapBank (crazypants.enderio.powertools.machine.capbank.TileCapBank)13 TileEntity (net.minecraft.tileentity.TileEntity)3 BlockCapBank (crazypants.enderio.powertools.machine.capbank.BlockCapBank)2 IBlockState (net.minecraft.block.state.IBlockState)2 EnumFacing (net.minecraft.util.EnumFacing)2 IoMode (crazypants.enderio.base.machine.modes.IoMode)1 EnumIOMode (crazypants.enderio.base.render.property.IOMode.EnumIOMode)1 CapBankType (crazypants.enderio.powertools.machine.capbank.CapBankType)1 InfoDisplayType (crazypants.enderio.powertools.machine.capbank.InfoDisplayType)1 CapBankClientNetwork (crazypants.enderio.powertools.machine.capbank.network.CapBankClientNetwork)1 ICapBankNetwork (crazypants.enderio.powertools.machine.capbank.network.ICapBankNetwork)1 PacketNetworkStateResponse (crazypants.enderio.powertools.machine.capbank.packet.PacketNetworkStateResponse)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1