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 receivers = Collections.newSetFromMap(new ConcurrentHashMap<>()); @Override diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/handles/ByteBufferChannel.java b/projects/core/src/main/java/dan200/computercraft/core/apis/handles/ByteBufferChannel.java index d0ac16bef..bffb70fc7 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/handles/ByteBufferChannel.java +++ b/projects/core/src/main/java/dan200/computercraft/core/apis/handles/ByteBufferChannel.java @@ -33,11 +33,7 @@ public class ByteBufferChannel implements SeekableByteChannel { var remaining = Math.min(backing.limit() - position, destination.remaining()); - // TODO: Switch to Java 17 methods on 1.18.x - var slice = backing.slice(); - slice.position(position); - slice.limit(position + remaining); - destination.put(slice); + destination.put(position, backing, position, remaining); position += remaining; return remaining; } diff --git a/projects/core/src/main/java/dan200/computercraft/core/computer/ComputerThread.java b/projects/core/src/main/java/dan200/computercraft/core/computer/ComputerThread.java index b22ab503a..951d6f004 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/computer/ComputerThread.java +++ b/projects/core/src/main/java/dan200/computercraft/core/computer/ComputerThread.java @@ -391,7 +391,7 @@ public final class ComputerThread { */ long scaledPeriod() { // FIXME: We access this on other threads (in TimeoutState), so their reads won't be consistent. This isn't - // "criticial" behaviour, so not clear if it matters too much. + // "critical" behaviour, so not clear if it matters too much. // +1 to include the current task var count = 1 + computerQueue.size(); diff --git a/projects/fabric/build.gradle.kts b/projects/fabric/build.gradle.kts index 58191acbc..f1ca00f89 100644 --- a/projects/fabric/build.gradle.kts +++ b/projects/fabric/build.gradle.kts @@ -35,7 +35,9 @@ addRemappedConfiguration("testWithSodium") addRemappedConfiguration("testWithIris") dependencies { - modImplementation(libs.bundles.externalMods.fabric) + modImplementation(libs.bundles.externalMods.fabric) { + exclude("curse.maven", "configured-fabric-667378") // Added by Forge Config API + } modCompileOnly(libs.bundles.externalMods.fabric.compile) { exclude("net.fabricmc", "fabric-loader") exclude("net.fabricmc.fabric-api") diff --git a/projects/forge-api/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java b/projects/forge-api/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java index f5ccd52e3..d715bdc1f 100644 --- a/projects/forge-api/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java +++ b/projects/forge-api/src/main/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java @@ -5,26 +5,24 @@ */ package dan200.computercraft.api.peripheral; +import dan200.computercraft.api.ForgeComputerCraftAPI; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.common.util.LazyOptional; - /** * This interface is used to create peripheral implementations for blocks. *

* 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. *