Skip to content

Commit e9bc382

Browse files
committed
修复乱七八糟的问题
1 parent 70082a3 commit e9bc382

8 files changed

Lines changed: 53 additions & 106 deletions

File tree

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
#Wed May 13 22:29:01 CST 2026
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip
4-
networkTimeout=10000
5-
validateDistributionUrl=true
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.0-bin.zip
65
zipStoreBase=GRADLE_USER_HOME
76
zipStorePath=wrapper/dists

src/main/java/com/circulation/circulation_networks/manager/ChannelActivityIndex.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@ void add(T entry, UUID channelId) {
2929
}
3030
entries.add(entry);
3131
}
32+
33+
ReferenceSet<T> get(UUID channelId) {
34+
return entriesByChannel.get(channelId);
35+
}
3236
}

src/main/java/com/circulation/circulation_networks/manager/ChannelRuntime.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/main/java/com/circulation/circulation_networks/manager/ChargingManager.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ private static void transferEnergyForGrid(IGrid grid,
264264
return;
265265
}
266266

267+
EnergyMachineManager.prepareInteractionsForTransfer(channelGrids);
267268
long startNanos = System.nanoTime();
268269
transferEnergy(merged.send, merged.targets, EnergyMachineManager.Status.EXTRACT);
269270
transferEnergy(merged.storage, merged.targets, EnergyMachineManager.Status.EXTRACT);
@@ -281,6 +282,7 @@ private static void transferEnergyForGrid(IGrid grid,
281282

282283
var handlers = machineMap.get(grid);
283284
if (handlers != null && handlers.activeThisTick) {
285+
EnergyMachineManager.prepareInteractionForTransfer(grid);
284286
long startNanos = System.nanoTime();
285287
transferEnergy(handlers.send, chargingTargets, EnergyMachineManager.Status.EXTRACT);
286288
transferEnergy(handlers.storage, chargingTargets, EnergyMachineManager.Status.EXTRACT);
@@ -289,15 +291,19 @@ private static void transferEnergyForGrid(IGrid grid,
289291
}
290292

291293
private ReferenceSet<IGrid> collectActiveChannelTransferGrids(UUID channelId,
292-
IGrid rootGrid,
293-
EnergyMachineRuntimeIndex runtimeIndex,
294-
ReferenceSet<IGrid> processedGrids) {
294+
IGrid rootGrid,
295+
EnergyMachineRuntimeIndex runtimeIndex,
296+
ReferenceSet<IGrid> processedGrids) {
295297
channelTransferGridsScratch.clear();
296-
var channelRuntime = runtimeIndex.getChannelRuntime(channelId);
297-
if (channelRuntime == null) {
298+
var channelGrids = HubChannelManager.INSTANCE.getChannelGrids(channelId);
299+
var activeGrids = runtimeIndex.getActiveChannelGrids(channelId);
300+
if (channelGrids.isEmpty() || activeGrids == null || activeGrids.isEmpty()) {
298301
return channelTransferGridsScratch;
299302
}
300-
for (var candidate : channelRuntime.activeGrids()) {
303+
for (var candidate : channelGrids) {
304+
if (!activeGrids.contains(candidate)) {
305+
continue;
306+
}
301307
collectActiveChannelTransferGrid(channelId, rootGrid, candidate, processedGrids);
302308
}
303309
return channelTransferGridsScratch;

src/main/java/com/circulation/circulation_networks/manager/EnergyMachineManager.java

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,11 @@ public void onServerTick() {
238238
if (hubNode != null && hubNode.isActive()) {
239239
var channelId = hubNode.getChannelId();
240240
if (!channelId.equals(HubNode.EMPTY)) {
241-
var channelRuntime = runtimeIndex.getChannelRuntime(channelId);
242-
ReferenceSet<IGrid> channelGrids = channelRuntime == null ? ReferenceSets.emptySet() : collectActiveChannelTickGrids(channelRuntime);
241+
ReferenceSet<IGrid> channelGrids = collectActiveChannelTickGrids(channelId);
243242
if (channelGrids.size() > 1) {
244243
var merged = channelTransferView.prepare(channelGrids);
245244
processedTickGrids.addAll(channelGrids);
245+
prepareInteractionsForTransfer(channelGrids);
246246
long startNanos = System.nanoTime();
247247
transferEnergy(merged.sendView, merged.receiveView, Status.INTERACTION);
248248
transferEnergy(merged.storageView, merged.receiveView, Status.EXTRACT, true, false);
@@ -260,6 +260,7 @@ public void onServerTick() {
260260
continue;
261261
}
262262

263+
prepareInteractionForTransfer(grid);
263264
long startNanos = System.nanoTime();
264265
transferEnergy(handlers.send, handlers.receive, Status.INTERACTION);
265266
transferEnergy(handlers.storage, handlers.receive, Status.EXTRACT, true, false);
@@ -281,9 +282,17 @@ public void onServerTick() {
281282
canAddManchine = true;
282283
}
283284

284-
private ReferenceSet<IGrid> collectActiveChannelTickGrids(ChannelRuntime channelRuntime) {
285+
private ReferenceSet<IGrid> collectActiveChannelTickGrids(UUID channelId) {
285286
channelTickGridsScratch.clear();
286-
for (var candidate : channelRuntime.activeGrids()) {
287+
var channelGrids = HubChannelManager.INSTANCE.getChannelGrids(channelId);
288+
var activeGrids = runtimeIndex.getActiveChannelGrids(channelId);
289+
if (channelGrids.isEmpty() || activeGrids == null || activeGrids.isEmpty()) {
290+
return channelTickGridsScratch;
291+
}
292+
for (var candidate : channelGrids) {
293+
if (!activeGrids.contains(candidate)) {
294+
continue;
295+
}
287296
if (processedTickGrids.contains(candidate)) {
288297
continue;
289298
}
@@ -862,10 +871,22 @@ static Interaction getOrCreateInteraction(@Nullable IGrid grid) {
862871
interaction = new Interaction();
863872
INSTANCE.interaction.put(grid, interaction);
864873
}
865-
interaction.prepareForTick(INSTANCE.interactionEpoch);
866874
return interaction;
867875
}
868876

877+
static void prepareInteractionForTransfer(@Nullable IGrid grid) {
878+
Interaction interaction = getOrCreateInteraction(grid);
879+
if (interaction != null) {
880+
interaction.prepareForTick(INSTANCE.interactionEpoch);
881+
}
882+
}
883+
884+
static void prepareInteractionsForTransfer(Collection<? extends IGrid> grids) {
885+
for (IGrid grid : grids) {
886+
prepareInteractionForTransfer(grid);
887+
}
888+
}
889+
869890
private GridTickData getTickGridData(IGrid grid) {
870891
GridTickData data = tickGridData.get(grid);
871892
if (data == null) {
@@ -1552,22 +1573,18 @@ public static class Interaction {
15521573
private long preparedEpoch = Long.MIN_VALUE;
15531574

15541575
public EnergyAmount getInput() {
1555-
ensureCurrent();
15561576
return input;
15571577
}
15581578

15591579
public EnergyAmount getOutput() {
1560-
ensureCurrent();
15611580
return output;
15621581
}
15631582

15641583
public String getInteractionTimeMicrosString() {
1565-
ensureCurrent();
15661584
return Long.toString(interactionTimeNanos / 1_000L);
15671585
}
15681586

15691587
void recordGridTickTimeNanos(long durationNanos) {
1570-
ensureCurrent();
15711588
if (durationNanos > 0L) {
15721589
interactionTimeNanos += durationNanos;
15731590
}
@@ -1581,10 +1598,6 @@ private void prepareForTick(long epoch) {
15811598
preparedEpoch = epoch;
15821599
}
15831600

1584-
private void ensureCurrent() {
1585-
prepareForTick(INSTANCE.interactionEpoch);
1586-
}
1587-
15881601
private void reset() {
15891602
input.setZero();
15901603
output.setZero();

src/main/java/com/circulation/circulation_networks/manager/EnergyMachineRuntimeIndex.java

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.circulation.circulation_networks.api.IGrid;
44
import com.circulation.circulation_networks.network.nodes.HubNode;
5-
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
65
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
76
//~ mc_imports
87
import net.minecraft.tileentity.TileEntity;
@@ -18,8 +17,7 @@ final class EnergyMachineRuntimeIndex {
1817
private final Reference2ObjectOpenHashMap<TileEntity, MachineRuntime> machineRuntimes = new Reference2ObjectOpenHashMap<>();
1918
//~}
2019
private final Reference2ObjectOpenHashMap<IGrid, GridRuntime> gridRuntimes = new Reference2ObjectOpenHashMap<>();
21-
private final Object2ObjectOpenHashMap<UUID, ChannelRuntime> channelRuntimes = new Object2ObjectOpenHashMap<>();
22-
private final ChannelActivityIndex<IGrid> activeChannels = new ChannelActivityIndex<>();
20+
private final ChannelActivityIndex<IGrid> activeChannelGrids = new ChannelActivityIndex<>();
2321

2422
//~ if >=1.20 'TileEntity' -> 'BlockEntity' {
2523
MachineRuntime getOrCreateMachineRuntime(TileEntity tileEntity, boolean machineNode) {
@@ -40,8 +38,8 @@ MachineRuntime getMachineRuntime(TileEntity tileEntity) {
4038
//~}
4139

4240
@Nullable
43-
ChannelRuntime getChannelRuntime(UUID channelId) {
44-
return channelRuntimes.get(channelId);
41+
it.unimi.dsi.fastutil.objects.ReferenceSet<IGrid> getActiveChannelGrids(UUID channelId) {
42+
return activeChannelGrids.get(channelId);
4543
}
4644

4745
Collection<MachineRuntime> machineRuntimes() {
@@ -58,44 +56,30 @@ void rebuildMachineEndpoints(MachineRuntime runtime, Collection<MachineEndpointS
5856
runtime.transferSlots().add(new MachineTransferSlot(
5957
endpoint,
6058
endpointSpec.grid(),
61-
EnergyMachineManager.INSTANCE.getOrCreateWarningTarget(runtime.tileEntity()),
62-
EnergyMachineManager.getOrCreateInteraction(endpointSpec.grid())
59+
EnergyMachineManager.INSTANCE.getOrCreateWarningTarget(runtime.tileEntity())
6360
));
64-
65-
UUID channelId = endpointSpec.channelId();
66-
if (channelId != null) {
67-
channelRuntimes.computeIfAbsent(channelId, ignored -> new ChannelRuntime()).addGrid(endpointSpec.grid());
68-
}
6961
}
7062
runtime.clearDirty();
7163
}
7264

7365
void activateEndpoint(MachineEndpoint endpoint) {
7466
UUID channelId = resolveChannelId(endpoint.grid());
7567
if (channelId != null) {
76-
activeChannels.add(endpoint.grid(), channelId);
77-
ChannelRuntime channelRuntime = channelRuntimes.get(channelId);
78-
if (channelRuntime != null) {
79-
channelRuntime.activateGrid(endpoint.grid());
80-
}
68+
activeChannelGrids.add(endpoint.grid(), channelId);
8169
}
8270
}
8371

8472
void clearTickActivity() {
85-
activeChannels.clear();
8673
for (GridRuntime gridRuntime : gridRuntimes.values()) {
8774
gridRuntime.clearActive();
8875
}
89-
for (ChannelRuntime channelRuntime : channelRuntimes.values()) {
90-
channelRuntime.clearActive();
91-
}
76+
activeChannelGrids.clear();
9277
}
9378

9479
void clear() {
9580
machineRuntimes.clear();
9681
gridRuntimes.clear();
97-
channelRuntimes.clear();
98-
activeChannels.clear();
82+
activeChannelGrids.clear();
9983
}
10084

10185
//~ if >=1.20 'TileEntity' -> 'BlockEntity' {
@@ -119,18 +103,6 @@ private void detachMachineEndpoints(MachineRuntime runtime) {
119103
for (MachineEndpoint endpoint : endpoints) {
120104
GridRuntime gridRuntime = endpoint.gridRuntime();
121105
gridRuntime.removeEndpoint(endpoint);
122-
UUID channelId = resolveChannelId(endpoint.grid());
123-
if (channelId != null) {
124-
ChannelRuntime channelRuntime = channelRuntimes.get(channelId);
125-
if (channelRuntime != null) {
126-
if (gridRuntime.isEmpty() || !channelId.equals(resolveChannelId(endpoint.grid()))) {
127-
channelRuntime.removeGrid(endpoint.grid());
128-
}
129-
if (channelRuntime.isEmpty()) {
130-
channelRuntimes.remove(channelId);
131-
}
132-
}
133-
}
134106
if (gridRuntime.isEmpty()) {
135107
gridRuntimes.remove(endpoint.grid());
136108
}

src/main/java/com/circulation/circulation_networks/manager/HubChannelManager.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ private HubChannelManager() {
6868
hubChannels.defaultReturnValue(EMPTY);
6969
}
7070

71-
//~ if >=1.20 'net.minecraft.world.World' -> 'net.minecraft.world.level.Level' {
7271
public void bindHub(IHubNode hub) {
7372
if (hub == null || !NetworkManager.isServerAvailable()) {
7473
return;
@@ -922,5 +921,4 @@ private record ChannelDataSnapshot(UUID channelId, String name, PermissionMode p
922921
Map<UUID, HubPermissionLevel> explicitPermissions,
923922
Map<UUID, ChargingPreference> chargingPreferences) {
924923
}
925-
//~}
926924
}

src/main/java/com/circulation/circulation_networks/manager/MachineTransferSlot.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ final class MachineTransferSlot {
1010
private final MachineEndpoint endpoint;
1111
private final IGrid grid;
1212
private EnergyMachineManager.WarningTarget warningTarget;
13-
@Nullable
14-
private final EnergyMachineManager.Interaction interaction;
1513

1614
@Nullable
1715
private IEnergyHandler handler;
@@ -20,12 +18,10 @@ final class MachineTransferSlot {
2018

2119
MachineTransferSlot(MachineEndpoint endpoint,
2220
IGrid grid,
23-
EnergyMachineManager.WarningTarget warningTarget,
24-
@Nullable EnergyMachineManager.Interaction interaction) {
21+
EnergyMachineManager.WarningTarget warningTarget) {
2522
this.endpoint = endpoint;
2623
this.grid = grid;
2724
this.warningTarget = warningTarget;
28-
this.interaction = interaction;
2925
}
3026

3127
MachineEndpoint endpoint() {
@@ -42,7 +38,7 @@ EnergyMachineManager.WarningTarget warningTarget() {
4238

4339
@Nullable
4440
EnergyMachineManager.Interaction interaction() {
45-
return interaction;
41+
return EnergyMachineManager.getOrCreateInteraction(grid);
4642
}
4743

4844
@Nullable

0 commit comments

Comments
 (0)