Skip to content

Commit

Permalink
Ld pipe crash fix (#2028)
Browse files Browse the repository at this point in the history
  • Loading branch information
brachy84 authored Aug 7, 2023
1 parent 8773e34 commit 09bfcad
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gregtech.api.pipenet.longdist;

import gregtech.api.pipenet.WorldPipeNet;
import gregtech.api.util.GTLog;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
Expand Down Expand Up @@ -69,6 +68,7 @@ protected void recalculateNetwork(Collection<BlockPos> starts) {
* Called from the {@link NetworkBuilder} to set the gathered data
*/
protected void setData(Collection<BlockPos> pipes, List<ILDEndpoint> endpoints) {
invalidateEndpoints();
boolean wasEmpty = this.longDistancePipeBlocks.isEmpty();
this.longDistancePipeBlocks.clear();
this.longDistancePipeBlocks.addAll(pipes);
Expand Down Expand Up @@ -202,7 +202,9 @@ public ILDEndpoint getOtherEndpoint(ILDEndpoint endpoint) {
// return null for invalid network configurations
if (!isValid() || (!endpoint.isInput() && !endpoint.isOutput())) return null;

if (this.activeInputIndex >= 0 && this.activeOutputIndex >= 0) {
if (isIOIndexInvalid()) {
invalidateEndpoints();
} else if (this.activeInputIndex >= 0) {
// there is an active input and output endpoint
ILDEndpoint in = this.endpoints.get(this.activeInputIndex);
ILDEndpoint out = this.endpoints.get(this.activeOutputIndex);
Expand All @@ -221,10 +223,6 @@ public ILDEndpoint getOtherEndpoint(ILDEndpoint endpoint) {
return in;
}
return null;
} else if (this.activeInputIndex < 0 != this.activeOutputIndex < 0) {
// only input or output is active
GTLog.logger.warn("Long Distance Network has an {}. This should not happen!", this.activeInputIndex < 0 ? "active input, but not an active output" : "active output, but not an active input");
invalidateEndpoints(); // shouldn't happen
}

// find a valid endpoint in this net
Expand Down Expand Up @@ -257,6 +255,12 @@ private int find(ILDEndpoint endpoint) {
return -1;
}

public boolean isIOIndexInvalid() {
return (this.activeInputIndex >= 0 && this.activeInputIndex >= this.endpoints.size())
|| (this.activeOutputIndex >= 0 && this.activeOutputIndex >= this.endpoints.size())
|| this.activeInputIndex < 0 != this.activeOutputIndex < 0;
}

public ILDEndpoint getActiveInputIndex() {
return this.activeInputIndex >= 0 ? this.endpoints.get(this.activeInputIndex) : null;
}
Expand Down

0 comments on commit 09bfcad

Please sign in to comment.