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