1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-10-30 21:23:00 +00:00

Resolve a few TODOs

- Update ForgeConfigAPI to the latest version, to fix the race
   condition.
 - Move WirelessNetwork lifecycle management to ServerContext.
 - Some doc fixes.
This commit is contained in:
Jonathan Coates
2022-12-03 15:55:48 +00:00
parent 87c6d3aef6
commit fa122a56cf
10 changed files with 26 additions and 41 deletions

View File

@@ -24,7 +24,6 @@ import dan200.computercraft.impl.network.wired.WiredNodeImpl;
import dan200.computercraft.shared.computer.core.ServerContext;
import dan200.computercraft.shared.details.BlockDetails;
import dan200.computercraft.shared.details.ItemDetails;
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
@@ -89,7 +88,7 @@ public abstract class AbstractComputerCraftAPI implements ComputerCraftAPIServic
@Override
public final PacketNetwork getWirelessNetwork(MinecraftServer server) {
return WirelessNetwork.getUniversal();
return ServerContext.get(server).wirelessNetwork();
}
@Override

View File

@@ -12,7 +12,6 @@ import dan200.computercraft.impl.TurtleUpgrades;
import dan200.computercraft.shared.computer.core.ResourceMount;
import dan200.computercraft.shared.computer.core.ServerContext;
import dan200.computercraft.shared.computer.metrics.ComputerMBean;
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
import dan200.computercraft.shared.peripheral.monitor.MonitorWatcher;
import dan200.computercraft.shared.util.DropConsumer;
import dan200.computercraft.shared.util.TickScheduler;
@@ -70,7 +69,6 @@ public final class CommonHooks {
private static void resetState() {
ServerContext.close();
WirelessNetwork.resetNetworks();
NetworkUtils.reset();
}

View File

@@ -8,6 +8,7 @@ package dan200.computercraft.shared.computer.core;
import com.google.common.annotations.VisibleForTesting;
import dan200.computercraft.api.ComputerCraftAPI;
import dan200.computercraft.api.filesystem.Mount;
import dan200.computercraft.api.network.PacketNetwork;
import dan200.computercraft.core.ComputerContext;
import dan200.computercraft.core.computer.ComputerThread;
import dan200.computercraft.core.computer.GlobalEnvironment;
@@ -18,6 +19,7 @@ import dan200.computercraft.impl.AbstractComputerCraftAPI;
import dan200.computercraft.shared.CommonHooks;
import dan200.computercraft.shared.computer.metrics.GlobalMetrics;
import dan200.computercraft.shared.config.Config;
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
import dan200.computercraft.shared.util.IDAssigner;
import net.minecraft.SharedConstants;
import net.minecraft.server.MinecraftServer;
@@ -58,6 +60,7 @@ public final class ServerContext {
private final ComputerContext context;
private final MainThread mainThread;
private final IDAssigner idAssigner;
private final WirelessNetwork wirelessNetwork = new WirelessNetwork();
private final Path storageDir;
private ServerContext(MinecraftServer server) {
@@ -180,6 +183,17 @@ public final class ServerContext {
return metrics;
}
/**
* Get the global wireless network.
* <p>
* Use {@link ComputerCraftAPI#getWirelessNetwork(MinecraftServer)} instead of this method.
*
* @return The wireless network.
*/
public PacketNetwork wirelessNetwork() {
return wirelessNetwork;
}
private record Environment(MinecraftServer server) implements GlobalEnvironment {
@Override
public @Nullable Mount createResourceMount(String domain, String subPath) {

View File

@@ -408,17 +408,8 @@ public final class ConfigSpec {
public static void sync(ModConfig config) {
if (!config.getModId().equals(ComputerCraftAPI.MOD_ID)) return;
try {
if (config.getType() == ModConfig.Type.SERVER) syncServer();
if (config.getType() == ModConfig.Type.CLIENT) syncClient();
} catch (IllegalStateException e) {
// TODO: Remove when https://github.com/Fuzss/forgeconfigapiport-fabric/issues/26 is fixed.
if (e.getMessage() != null && e.getMessage().startsWith("Cannot get config value before config is loaded.")) {
return;
}
throw e;
}
if (config.getType() == ModConfig.Type.SERVER) syncServer();
if (config.getType() == ModConfig.Type.CLIENT) syncClient();
}
/**

View File

@@ -9,25 +9,12 @@ import dan200.computercraft.api.network.Packet;
import dan200.computercraft.api.network.PacketNetwork;
import dan200.computercraft.api.network.PacketReceiver;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
public class WirelessNetwork implements PacketNetwork {
// TODO: Move this to ServerContext.
private static @Nullable WirelessNetwork universalNetwork = null;
public static WirelessNetwork getUniversal() {
if (universalNetwork == null) universalNetwork = new WirelessNetwork();
return universalNetwork;
}
public static void resetNetworks() {
universalNetwork = null;
}
private final Set<PacketReceiver> receivers = Collections.newSetFromMap(new ConcurrentHashMap<>());
@Override