Skip to content

Commit fd6e6e9

Browse files
committed
Add a couple helper methods to ConnectionType to make it slightly clearer in places what is going on logically
1 parent bacc188 commit fd6e6e9

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

src/main/java/mekanism/common/content/network/transmitter/LogisticalTransporterBase.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public boolean handlesRedstone() {
7272
}
7373

7474
public boolean exposesInsertCap(@NotNull Direction side) {
75-
ConnectionType connectionType = getConnectionTypeRaw(side);
76-
return connectionType == ConnectionType.NORMAL || connectionType == ConnectionType.PULL;
75+
return getConnectionTypeRaw(side).canAccept();
7776
}
7877

7978
@Nullable
@@ -82,19 +81,11 @@ public EnumColor getColor() {
8281
}
8382

8483
public boolean canEmitTo(Direction side) {
85-
if (canConnect(side)) {
86-
ConnectionType connectionType = getConnectionType(side);
87-
return connectionType == ConnectionType.NORMAL || connectionType == ConnectionType.PUSH;
88-
}
89-
return false;
84+
return canConnect(side) && getConnectionType(side).canSendTo();
9085
}
9186

9287
public boolean canReceiveFrom(Direction side) {
93-
if (canConnect(side)) {
94-
ConnectionType connectionType = getConnectionType(side);
95-
return connectionType == ConnectionType.NORMAL || connectionType == ConnectionType.PULL;
96-
}
97-
return false;
88+
return canConnect(side) && getConnectionType(side).canAccept();
9889
}
9990

10091
@Override
@@ -221,7 +212,7 @@ public void onUpdateServer() {
221212
if (pathType == Path.DEST || pathType == Path.HOME) {
222213
Direction side = stack.getSide(this);
223214
ConnectionType connectionType = getConnectionType(side);
224-
tryRecalculate = connectionType != ConnectionType.NORMAL && connectionType != ConnectionType.PUSH ||
215+
tryRecalculate = !connectionType.canSendTo() ||
225216
!TransporterUtils.canInsert(getLevel(), stack.getDest(), stack.color, stack.itemStack, side, pathType == Path.HOME);
226217
} else {
227218
tryRecalculate = pathType == Path.NONE;
@@ -233,7 +224,7 @@ public void onUpdateServer() {
233224
// in a single length transmitter, in which case we only recalculate it at 50 if it won't
234225
// be able to go into that connection type
235226
ConnectionType connectionType = getConnectionType(stack.getSide(this));
236-
tryRecalculate = connectionType != ConnectionType.NORMAL && connectionType != ConnectionType.PUSH;
227+
tryRecalculate = !connectionType.canSendTo();
237228
} else {
238229
tryRecalculate = !stack.canInsertToTransporter(nextTransmitter, stack.getSide(this), this);
239230
}

src/main/java/mekanism/common/content/network/transmitter/Transmitter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,7 @@ public boolean isValidTransmitterBasic(TileEntityTransmitter transmitter, Direct
350350
}
351351

352352
public boolean canConnectToAcceptor(Direction side) {
353-
ConnectionType type = getConnectionTypeRaw(side);
354-
return type == ConnectionType.NORMAL || type == ConnectionType.PUSH;
353+
return getConnectionTypeRaw(side).canSendTo();
355354
}
356355

357356
/**

src/main/java/mekanism/common/lib/transmitter/ConnectionType.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,18 @@ public ConnectionType byIndex(int index) {
5151
public static ConnectionType byIndexStatic(int index) {
5252
return MathUtils.getByIndexMod(TYPES, index);
5353
}
54+
55+
/**
56+
* @return {@code true} If this connection type allows other things to insert into it.
57+
*/
58+
public boolean canAccept() {
59+
return this == NORMAL || this == PULL;
60+
}
61+
62+
/**
63+
* @return {@code true} If this connection type can send to other things or allow them to extract from it.
64+
*/
65+
public boolean canSendTo() {
66+
return this == NORMAL || this == PUSH;
67+
}
5468
}

src/main/java/mekanism/common/tile/transmitter/TileEntityTransmitter.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,7 @@ public void redstoneChanged(boolean powered) {
418418
return true;
419419
}
420420
//If we have a side only allow extracting if our connection allows it
421-
ConnectionType connectionType = getTransmitter().getConnectionType(side);
422-
return connectionType == ConnectionType.NORMAL || connectionType == ConnectionType.PUSH;
421+
return getTransmitter().getConnectionType(side).canSendTo();
423422
};
424423
}
425424

@@ -430,8 +429,7 @@ public void redstoneChanged(boolean powered) {
430429
return true;
431430
}
432431
//If we have a side only allow inserting if our connection allows it
433-
ConnectionType connectionType = getTransmitter().getConnectionType(side);
434-
return connectionType == ConnectionType.NORMAL || connectionType == ConnectionType.PULL;
432+
return getTransmitter().getConnectionType(side).canAccept();
435433
};
436434
}
437435
}

0 commit comments

Comments
 (0)