Allow transfer between same rate cables. Closes #2965

This commit is contained in:
drcrazy 2022-06-13 03:04:14 +03:00
parent e4d398e600
commit a8b7fb36b9

View file

@ -35,10 +35,14 @@ import java.util.*;
@SuppressWarnings("UnstableApiUsage") @SuppressWarnings("UnstableApiUsage")
class CableTickManager { class CableTickManager {
private static long tickCounter = 0;
private static final List<CableBlockEntity> cableList = new ArrayList<>(); private static final List<CableBlockEntity> cableList = new ArrayList<>();
private static final List<OfferedEnergyStorage> targetStorages = new ArrayList<>(); private static final List<OfferedEnergyStorage> targetStorages = new ArrayList<>();
private static final Deque<CableBlockEntity> bfsQueue = new ArrayDeque<>(); private static final Deque<CableBlockEntity> bfsQueue = new ArrayDeque<>();
private static long tickCounter = 0;
static {
ServerTickEvents.START_SERVER_TICK.register(server -> tickCounter++);
}
static void handleCableTick(CableBlockEntity startingCable) { static void handleCableTick(CableBlockEntity startingCable) {
if (!(startingCable.getWorld() instanceof ServerWorld)) throw new IllegalStateException(); if (!(startingCable.getWorld() instanceof ServerWorld)) throw new IllegalStateException();
@ -93,9 +97,7 @@ class CableTickManager {
// Make sure we only gather and tick each cable once per tick. // Make sure we only gather and tick each cable once per tick.
if (current.lastTick == tickCounter) return false; if (current.lastTick == tickCounter) return false;
// Make sure we ignore cables in non-ticking chunks. // Make sure we ignore cables in non-ticking chunks.
if (!(current.getWorld() instanceof ServerWorld sw) || !sw.isChunkLoaded(current.getPos())) return false; return current.getWorld() instanceof ServerWorld sw && sw.isChunkLoaded(current.getPos());
return true;
} }
/** /**
@ -112,7 +114,7 @@ class CableTickManager {
CableBlockEntity current = bfsQueue.removeFirst(); CableBlockEntity current = bfsQueue.removeFirst();
for (Direction direction : Direction.values()) { for (Direction direction : Direction.values()) {
if (current.getAdjacentBlockEntity(direction) instanceof CableBlockEntity adjCable && current.getCableType() == adjCable.getCableType()) { if (current.getAdjacentBlockEntity(direction) instanceof CableBlockEntity adjCable && current.getCableType().transferRate == adjCable.getCableType().transferRate) {
if (shouldTickCable(adjCable)) { if (shouldTickCable(adjCable)) {
bfsQueue.add(adjCable); bfsQueue.add(adjCable);
adjCable.lastTick = tickCounter; adjCable.lastTick = tickCounter;
@ -173,8 +175,4 @@ class CableTickManager {
} }
} }
} }
static {
ServerTickEvents.START_SERVER_TICK.register(server -> tickCounter++);
}
} }