1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-07 16:00:31 +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
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
10 changed files with 26 additions and 41 deletions

View File

@ -27,7 +27,7 @@ nightConfig = "3.6.5"
slf4j = "1.7.36" slf4j = "1.7.36"
# Minecraft mods # Minecraft mods
forgeConfig = "4.2.6" forgeConfig = "4.2.7"
iris = "1.19.x-v1.4.0" iris = "1.19.x-v1.4.0"
jei = "11.3.0.262" jei = "11.3.0.262"
modmenu = "4.1.0" modmenu = "4.1.0"

View File

@ -24,7 +24,6 @@ import dan200.computercraft.impl.network.wired.WiredNodeImpl;
import dan200.computercraft.shared.computer.core.ServerContext; import dan200.computercraft.shared.computer.core.ServerContext;
import dan200.computercraft.shared.details.BlockDetails; import dan200.computercraft.shared.details.BlockDetails;
import dan200.computercraft.shared.details.ItemDetails; import dan200.computercraft.shared.details.ItemDetails;
import dan200.computercraft.shared.peripheral.modem.wireless.WirelessNetwork;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@ -89,7 +88,7 @@ public abstract class AbstractComputerCraftAPI implements ComputerCraftAPIServic
@Override @Override
public final PacketNetwork getWirelessNetwork(MinecraftServer server) { public final PacketNetwork getWirelessNetwork(MinecraftServer server) {
return WirelessNetwork.getUniversal(); return ServerContext.get(server).wirelessNetwork();
} }
@Override @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.ResourceMount;
import dan200.computercraft.shared.computer.core.ServerContext; import dan200.computercraft.shared.computer.core.ServerContext;
import dan200.computercraft.shared.computer.metrics.ComputerMBean; 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.peripheral.monitor.MonitorWatcher;
import dan200.computercraft.shared.util.DropConsumer; import dan200.computercraft.shared.util.DropConsumer;
import dan200.computercraft.shared.util.TickScheduler; import dan200.computercraft.shared.util.TickScheduler;
@ -70,7 +69,6 @@ public final class CommonHooks {
private static void resetState() { private static void resetState() {
ServerContext.close(); ServerContext.close();
WirelessNetwork.resetNetworks();
NetworkUtils.reset(); NetworkUtils.reset();
} }

View File

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

View File

@ -408,17 +408,8 @@ public final class ConfigSpec {
public static void sync(ModConfig config) { public static void sync(ModConfig config) {
if (!config.getModId().equals(ComputerCraftAPI.MOD_ID)) return; if (!config.getModId().equals(ComputerCraftAPI.MOD_ID)) return;
try { if (config.getType() == ModConfig.Type.SERVER) syncServer();
if (config.getType() == ModConfig.Type.SERVER) syncServer(); if (config.getType() == ModConfig.Type.CLIENT) syncClient();
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;
}
} }
/** /**

View File

@ -9,25 +9,12 @@ import dan200.computercraft.api.network.Packet;
import dan200.computercraft.api.network.PacketNetwork; import dan200.computercraft.api.network.PacketNetwork;
import dan200.computercraft.api.network.PacketReceiver; import dan200.computercraft.api.network.PacketReceiver;
import javax.annotation.Nullable;
import java.util.Collections; import java.util.Collections;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public class WirelessNetwork implements PacketNetwork { 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<>()); private final Set<PacketReceiver> receivers = Collections.newSetFromMap(new ConcurrentHashMap<>());
@Override @Override

View File

@ -33,11 +33,7 @@ public class ByteBufferChannel implements SeekableByteChannel {
var remaining = Math.min(backing.limit() - position, destination.remaining()); var remaining = Math.min(backing.limit() - position, destination.remaining());
// TODO: Switch to Java 17 methods on 1.18.x destination.put(position, backing, position, remaining);
var slice = backing.slice();
slice.position(position);
slice.limit(position + remaining);
destination.put(slice);
position += remaining; position += remaining;
return remaining; return remaining;
} }

View File

@ -391,7 +391,7 @@ public final class ComputerThread {
*/ */
long scaledPeriod() { long scaledPeriod() {
// FIXME: We access this on other threads (in TimeoutState), so their reads won't be consistent. This isn't // 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 // +1 to include the current task
var count = 1 + computerQueue.size(); var count = 1 + computerQueue.size();

View File

@ -35,7 +35,9 @@ addRemappedConfiguration("testWithSodium")
addRemappedConfiguration("testWithIris") addRemappedConfiguration("testWithIris")
dependencies { 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) { modCompileOnly(libs.bundles.externalMods.fabric.compile) {
exclude("net.fabricmc", "fabric-loader") exclude("net.fabricmc", "fabric-loader")
exclude("net.fabricmc.fabric-api") exclude("net.fabricmc.fabric-api")

View File

@ -5,26 +5,24 @@
*/ */
package dan200.computercraft.api.peripheral; package dan200.computercraft.api.peripheral;
import dan200.computercraft.api.ForgeComputerCraftAPI;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.common.util.LazyOptional;
/** /**
* This interface is used to create peripheral implementations for blocks. * This interface is used to create peripheral implementations for blocks.
* <p> * <p>
* If you have a {@link BlockEntity} which acts as a peripheral, you may alternatively expose the {@link IPeripheral} * If you have a {@link BlockEntity} which acts as a peripheral, you may alternatively expose the {@link IPeripheral}
* capability. * capability.
* <p> * <p>
* {@code dan200.computercraft.api.ForgeComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)} should be used * {@link ForgeComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider)} should be used to register a peripheral
* to register a peripheral provider. * provider.
*/ */
@FunctionalInterface @FunctionalInterface
public interface IPeripheralProvider { public interface IPeripheralProvider {
// TODO(1.19.3): Move to Forge and fix link above.
/** /**
* Produce an peripheral implementation from a block location. * Produce an peripheral implementation from a block location.
* *