diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 093dbd9df..1e47b94c2 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -27,7 +27,7 @@ nightConfig = "3.6.5" slf4j = "1.7.36" # Minecraft mods -forgeConfig = "4.2.6" +forgeConfig = "4.2.7" iris = "1.19.x-v1.4.0" jei = "11.3.0.262" modmenu = "4.1.0" diff --git a/projects/common/src/main/java/dan200/computercraft/impl/AbstractComputerCraftAPI.java b/projects/common/src/main/java/dan200/computercraft/impl/AbstractComputerCraftAPI.java index 83b441547..d02b2ca89 100644 --- a/projects/common/src/main/java/dan200/computercraft/impl/AbstractComputerCraftAPI.java +++ b/projects/common/src/main/java/dan200/computercraft/impl/AbstractComputerCraftAPI.java @@ -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 diff --git a/projects/common/src/main/java/dan200/computercraft/shared/CommonHooks.java b/projects/common/src/main/java/dan200/computercraft/shared/CommonHooks.java index 978f80039..a1d12c9da 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/CommonHooks.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/CommonHooks.java @@ -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(); } diff --git a/projects/common/src/main/java/dan200/computercraft/shared/computer/core/ServerContext.java b/projects/common/src/main/java/dan200/computercraft/shared/computer/core/ServerContext.java index 80e246a19..f3fb3fc2a 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/computer/core/ServerContext.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/computer/core/ServerContext.java @@ -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. + *
+ * 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) {
diff --git a/projects/common/src/main/java/dan200/computercraft/shared/config/ConfigSpec.java b/projects/common/src/main/java/dan200/computercraft/shared/config/ConfigSpec.java
index a6b897549..202121190 100644
--- a/projects/common/src/main/java/dan200/computercraft/shared/config/ConfigSpec.java
+++ b/projects/common/src/main/java/dan200/computercraft/shared/config/ConfigSpec.java
@@ -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();
}
/**
diff --git a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/WirelessNetwork.java b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/WirelessNetwork.java
index 65808e6dc..6d92a9b95 100644
--- a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/WirelessNetwork.java
+++ b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/modem/wireless/WirelessNetwork.java
@@ -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
* If you have a {@link BlockEntity} which acts as a peripheral, you may alternatively expose the {@link IPeripheral}
* capability.
*
- * {@code dan200.computercraft.api.ForgeComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)} should be used
- * to register a peripheral provider.
+ * {@link ForgeComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)} should be used to register a peripheral
+ * provider.
*/
@FunctionalInterface
public interface IPeripheralProvider {
- // TODO(1.19.3): Move to Forge and fix link above.
-
/**
* Produce an peripheral implementation from a block location.
*