From fde6cb6d27a63b8a0b113df657f89dff1d8cd4b1 Mon Sep 17 00:00:00 2001
From: Marc Hermans
Date: Fri, 17 Nov 2023 23:20:25 +0100
Subject: [PATCH] Remove the version range support. Implement entire
configuration phase.
---
.../ServerboundCustomPayloadPacket.java.patch | 20 ++
.../ServerCommonPacketListenerImpl.java.patch | 16 +-
...ConfigurationPacketListenerImpl.java.patch | 20 +-
.../neoforge/client/event/RenderArmEvent.java | 2 +-
.../neoforge/client/gui/ModListScreen.java | 2 +-
.../gui/ModMismatchDisconnectedScreen.java | 10 +-
.../model/ExtendedBlockModelDeserializer.java | 2 +-
.../neoforge/common/CommonHooks.java | 18 +-
.../neoforge/common/I18nExtension.java | 2 +-
.../neoforge/common/NeoForgeMod.java | 6 +-
.../capabilities/ICapabilityProvider.java | 4 +-
.../common/data/ExistingFileHelper.java | 2 +-
.../IBlockAndTintGetterExtension.java | 2 +-
.../common/extensions/IBlockExtension.java | 4 +-
.../extensions/IBlockStateExtension.java | 4 +-
.../extensions/IEnchantmentExtension.java | 2 +-
.../extensions/IFriendlyByteBufExtension.java | 2 +-
.../common/extensions/IItemExtension.java | 12 +-
.../extensions/IItemStackExtension.java | 6 +-
.../common/util/MavenVersionStringHelper.java | 18 +-
.../neoforge/event/ModMismatchEvent.java | 10 +-
.../RegisterStructureConversionsEvent.java | 2 +-
.../neoforge/event/entity/EntityEvent.java | 4 +-
.../living/LivingDestroyBlockEvent.java | 2 +-
.../neoforged/neoforge/fluids/FluidUtil.java | 2 +-
.../internal/NeoForgeStatesProvider.java | 7 +-
.../versions/neoforge/NeoForgeVersion.java | 4 +-
.../versions/neoform/NeoFormVersion.java | 8 +-
.../neoforge/items/ItemHandlerHelper.java | 2 +-
.../neoforge/network/ConfigSync.java | 22 +-
.../network/ConfigurationInitialization.java | 17 +
.../neoforge/network/DualStackUtils.java | 2 +-
.../neoforge/network/HandshakeMessages.java | 327 ------------------
.../network/NetworkInitialization.java | 47 +--
.../neoforge/network/ServerStatusPing.java | 6 +-
.../network/configuration/SyncConfig.java | 25 ++
.../network/event/OnGameConfiguration.java | 12 +-
.../filters/VanillaPacketSplitter.java | 3 +-
...Handler.java => ClientPayloadHandler.java} | 26 +-
...Handler.java => ServerPayloadHandler.java} | 8 +-
.../handling/ConfigurationPayloadContext.java | 1 -
.../IConfigurationPayloadHandler.java | 1 -
.../network/handling/IPacketHandler.java | 9 +-
.../network/handling/IPayloadContext.java | 2 -
.../network/handling/PlayPayloadContext.java | 2 +-
.../NegotiableNetworkComponent.java | 51 +--
.../NegotiatedNetworkComponent.java | 3 +-
.../NetworkComponentNegotiator.java | 101 +-----
.../network/payload/ConfigFilePayload.java | 19 +-
.../payload/FrozenRegistryPayload.java | 3 +-
.../FrozenRegistrySyncCompletePayload.java | 3 +-
.../FrozenRegistrySyncStartPayload.java | 3 +-
.../payload/ModdedNetworkComponent.java | 7 +-
.../payload/ModdedNetworkQueryComponent.java | 10 +-
.../network/payload/SplitPacketPayload.java | 3 +-
.../network/reading/IPayloadReader.java | 28 --
.../reading/PayloadReadingContext.java | 11 -
...oddedConfigurationPayloadRegistration.java | 20 --
.../ModdedPlayPayloadRegistration.java | 20 --
.../network/registration/NetworkChannel.java | 3 +-
.../network/registration/NetworkRegistry.java | 57 ++-
.../registrar/ConfigurationRegistration.java | 14 +-
.../INetworkPayloadVersioningBuilder.java | 16 -
.../registrar/IPayloadRegistrar.java | 71 ++--
.../registrar/ModdedPacketRegistrar.java | 60 +---
.../registrar/PlayRegistration.java | 15 +-
.../neoforge/server/ServerLifecycleHooks.java | 32 --
.../server/command/ModListCommand.java | 2 +-
.../server/command/TextComponentHelper.java | 11 +-
src/main/resources/META-INF/mods.toml | 2 +-
70 files changed, 366 insertions(+), 904 deletions(-)
create mode 100644 src/main/java/net/neoforged/neoforge/network/ConfigurationInitialization.java
delete mode 100644 src/main/java/net/neoforged/neoforge/network/HandshakeMessages.java
create mode 100644 src/main/java/net/neoforged/neoforge/network/configuration/SyncConfig.java
rename src/main/java/net/neoforged/neoforge/network/handlers/{ClientForgeRegistryHandler.java => ClientPayloadHandler.java} (65%)
rename src/main/java/net/neoforged/neoforge/network/handlers/{ServerForgeRegistryHandler.java => ServerPayloadHandler.java} (68%)
delete mode 100644 src/main/java/net/neoforged/neoforge/network/reading/IPayloadReader.java
delete mode 100644 src/main/java/net/neoforged/neoforge/network/reading/PayloadReadingContext.java
delete mode 100644 src/main/java/net/neoforged/neoforge/network/registration/ModdedConfigurationPayloadRegistration.java
delete mode 100644 src/main/java/net/neoforged/neoforge/network/registration/ModdedPlayPayloadRegistration.java
delete mode 100644 src/main/java/net/neoforged/neoforge/network/registration/registrar/INetworkPayloadVersioningBuilder.java
diff --git a/patches/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java.patch b/patches/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java.patch
index a7d6144977..a35940a821 100644
--- a/patches/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java.patch
+++ b/patches/net/minecraft/network/protocol/common/ServerboundCustomPayloadPacket.java.patch
@@ -40,3 +40,23 @@
private static DiscardedPayload readUnknownPayload(ResourceLocation p_294973_, FriendlyByteBuf p_296037_) {
int i = p_296037_.readableBytes();
if (i >= 0 && i <= 32767) {
+@@ -35,14 +38,15 @@
+ throw new IllegalArgumentException("Payload may not be larger than 32767 bytes");
+ }
+ }
+-
++
+ @Override
+- public void write(FriendlyByteBuf p_295621_) {
+- p_295621_.writeResourceLocation(this.payload.id());
+- this.payload.write(p_295621_);
++ public void write(FriendlyByteBuf p_295630_) {
++ p_295630_.writeResourceLocation(this.payload.id());
++ this.payload.write(p_295630_);
+ }
+
+ public void handle(ServerCommonPacketListener p_295862_) {
+ p_295862_.handleCustomPayload(this);
+ }
++
+ }
diff --git a/patches/net/minecraft/server/network/ServerCommonPacketListenerImpl.java.patch b/patches/net/minecraft/server/network/ServerCommonPacketListenerImpl.java.patch
index 53f037d00e..c6b74b9b79 100644
--- a/patches/net/minecraft/server/network/ServerCommonPacketListenerImpl.java.patch
+++ b/patches/net/minecraft/server/network/ServerCommonPacketListenerImpl.java.patch
@@ -1,6 +1,6 @@
--- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
-@@ -12,13 +12,8 @@
+@@ -12,16 +12,12 @@
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.PacketUtils;
@@ -16,7 +16,11 @@
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ClientInformation;
import net.minecraft.util.VisibleForDebug;
-@@ -65,7 +60,7 @@
++import net.minecraft.util.thread.ReentrantBlockableEventLoop;
+ import org.slf4j.Logger;
+
+ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPacketListener {
+@@ -65,7 +61,7 @@
@Override
public void handlePong(ServerboundPongPacket p_295142_) {
}
@@ -25,7 +29,7 @@
@Override
public void handleCustomPayload(ServerboundCustomPayloadPacket p_294276_) {
}
-@@ -108,8 +103,17 @@
+@@ -108,8 +104,17 @@
public void send(Packet> p_294278_) {
this.send(p_294278_, null);
}
@@ -44,7 +48,7 @@
boolean flag = !this.suspendFlushingOnServerThread || !this.server.isSameThread();
try {
-@@ -121,7 +125,13 @@
+@@ -121,7 +126,13 @@
throw new ReportedException(crashreport);
}
}
@@ -59,7 +63,7 @@
public void disconnect(Component p_294116_) {
this.connection.send(new ClientboundDisconnectPacket(p_294116_), PacketSendListener.thenRun(() -> this.connection.disconnect(p_294116_)));
this.connection.setReadOnly();
-@@ -143,7 +153,17 @@
+@@ -143,7 +154,17 @@
return this.latency;
}
@@ -75,7 +79,7 @@
+ }
+
+ @Override
-+ public MinecraftServer getServer() {
++ public ReentrantBlockableEventLoop> getMainThreadEventLoop() {
+ return server;
}
}
diff --git a/patches/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java.patch b/patches/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java.patch
index 2fcf4f2768..7b9b792ab8 100644
--- a/patches/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java.patch
+++ b/patches/net/minecraft/server/network/ServerConfigurationPacketListenerImpl.java.patch
@@ -13,16 +13,18 @@
import net.minecraft.network.protocol.common.custom.BrandPayload;
import net.minecraft.network.protocol.configuration.ClientboundRegistryDataPacket;
import net.minecraft.network.protocol.configuration.ClientboundUpdateEnabledFeaturesPacket;
-@@ -31,6 +27,8 @@
+@@ -31,6 +27,10 @@
import net.minecraft.server.players.PlayerList;
import net.minecraft.tags.TagNetworkSerialization;
import net.minecraft.world.flag.FeatureFlags;
++import net.neoforged.fml.ModLoader;
++import net.neoforged.neoforge.network.event.OnGameConfiguration;
+import net.neoforged.neoforge.network.payload.ModdedNetworkQueryPayload;
+import net.neoforged.neoforge.network.registration.NetworkRegistry;
import org.slf4j.Logger;
public class ServerConfigurationPacketListenerImpl extends ServerCommonPacketListenerImpl implements TickablePacketListener, ServerConfigurationPacketListener {
-@@ -41,6 +39,8 @@
+@@ -41,6 +41,8 @@
@Nullable
private ConfigurationTask currentTask;
private ClientInformation clientInformation;
@@ -31,7 +33,7 @@
public ServerConfigurationPacketListenerImpl(MinecraftServer p_294645_, Connection p_295787_, CommonListenerCookie p_302003_) {
super(p_294645_, p_295787_, p_302003_);
-@@ -65,6 +65,11 @@
+@@ -65,6 +67,11 @@
}
public void startConfiguration() {
@@ -43,18 +45,18 @@
this.send(new ClientboundCustomPayloadPacket(new BrandPayload(this.server.getServerModName())));
LayeredRegistryAccess layeredregistryaccess = this.server.registries();
this.send(new ClientboundUpdateEnabledFeaturesPacket(FeatureFlags.REGISTRY.toNames(this.server.getWorldData().enabledFeatures())));
-@@ -86,6 +91,10 @@
+@@ -86,6 +93,10 @@
private void addOptionalTasks() {
this.server.getServerResourcePack().ifPresent(p_296496_ -> this.configurationTasks.add(new ServerResourcePackConfigurationTask(p_296496_)));
+
+ this.configurationTasks.add(new net.neoforged.neoforge.network.configuration.ModdedConfigurationPhaseStarted(this));
-+ this.configurationTasks.addAll(net.neoforged.neoforge.common.NeoForge.EVENT_BUS.post(new net.neoforged.neoforge.network.event.OnGameConfiguration()).getConfigurationTasks());
++ this.configurationTasks.addAll(ModLoader.get().postEventWithReturn(new OnGameConfiguration(this)).getConfigurationTasks());
+ this.configurationTasks.add(new net.neoforged.neoforge.network.configuration.ModdedConfigurationPhaseCompleted(this));
}
@Override
-@@ -100,7 +109,40 @@
+@@ -100,7 +111,40 @@
this.finishCurrentTask(ServerResourcePackConfigurationTask.TYPE);
}
}
@@ -96,7 +98,7 @@
@Override
public void handleConfigurationFinished(ServerboundFinishConfigurationPacket p_294283_) {
this.connection.suspendInboundAfterProtocolChange();
-@@ -121,7 +163,7 @@
+@@ -121,7 +165,7 @@
}
ServerPlayer serverplayer = playerlist.getPlayerForLogin(this.gameProfile, this.clientInformation);
@@ -105,7 +107,7 @@
this.connection.resumeInboundAfterProtocolChange();
} catch (Exception exception) {
LOGGER.error("Couldn't place player in world", (Throwable)exception);
-@@ -147,7 +189,8 @@
+@@ -147,7 +191,8 @@
}
}
@@ -115,7 +117,7 @@
ConfigurationTask.Type configurationtask$type = this.currentTask != null ? this.currentTask.type() : null;
if (!p_294853_.equals(configurationtask$type)) {
throw new IllegalStateException("Unexpected request for task finish, current task: " + configurationtask$type + ", requested: " + p_294853_);
-@@ -155,5 +198,15 @@
+@@ -155,5 +200,15 @@
this.currentTask = null;
this.startNextTask();
}
diff --git a/src/main/java/net/neoforged/neoforge/client/event/RenderArmEvent.java b/src/main/java/net/neoforged/neoforge/client/event/RenderArmEvent.java
index 5b0965d791..398ad90e24 100644
--- a/src/main/java/net/neoforged/neoforge/client/event/RenderArmEvent.java
+++ b/src/main/java/net/neoforged/neoforge/client/event/RenderArmEvent.java
@@ -17,7 +17,7 @@
import org.jetbrains.annotations.ApiStatus;
/**
- * Fired before the player's arm is rendered in first person. This is a more targeted preferredVersion of {@link RenderHandEvent},
+ * Fired before the player's arm is rendered in first person. This is a more targeted version of {@link RenderHandEvent},
* and can be used to replace the rendering of the player's arm, such as for rendering armor on the arm or outright
* replacing the arm with armor.
*
diff --git a/src/main/java/net/neoforged/neoforge/client/gui/ModListScreen.java b/src/main/java/net/neoforged/neoforge/client/gui/ModListScreen.java
index bf832e6c7a..0ef796e9a8 100644
--- a/src/main/java/net/neoforged/neoforge/client/gui/ModListScreen.java
+++ b/src/main/java/net/neoforged/neoforge/client/gui/ModListScreen.java
@@ -404,7 +404,7 @@ public void upload() {
}).orElse(Pair.of(null, new Size2i(0, 0)));
lines.add(selectedMod.getDisplayName());
- lines.add(I18nExtension.parseMessage("fml.menu.mods.info.preferredVersion", MavenVersionStringHelper.artifactVersionToString(selectedMod.getVersion())));
+ lines.add(I18nExtension.parseMessage("fml.menu.mods.info.version", MavenVersionStringHelper.artifactVersionToString(selectedMod.getVersion())));
lines.add(I18nExtension.parseMessage("fml.menu.mods.info.idstate", selectedMod.getModId(), ModList.get().getModContainerById(selectedMod.getModId()).map(ModContainer::getCurrentState).map(Object::toString).orElse("NONE")));
selectedMod.getConfig().getConfigElement("credits").ifPresent(credits -> lines.add(I18nExtension.parseMessage("fml.menu.mods.info.credits", credits)));
diff --git a/src/main/java/net/neoforged/neoforge/client/gui/ModMismatchDisconnectedScreen.java b/src/main/java/net/neoforged/neoforge/client/gui/ModMismatchDisconnectedScreen.java
index 399c09bbf8..0c127103d0 100644
--- a/src/main/java/net/neoforged/neoforge/client/gui/ModMismatchDisconnectedScreen.java
+++ b/src/main/java/net/neoforged/neoforge/client/gui/ModMismatchDisconnectedScreen.java
@@ -98,7 +98,7 @@ record Row(MutableComponent name, MutableComponent reason) {
}
List rows = new ArrayList<>();
if (!mismatchedChannelData.isEmpty()) {
- //This table section contains the mod name and both mod versions of each mod that has a mismatching client and server preferredVersion
+ //This table section contains the mod name and both mod versions of each mod that has a mismatching client and server version
rows.add(new Row(Component.translatable("fml.modmismatchscreen.table.channelname"), Component.translatable("fml.modmismatchscreen.table.reason")));
int i = 0;
for (Map.Entry modData : mismatchedChannelData.entrySet()) {
@@ -117,7 +117,7 @@ record Row(MutableComponent name, MutableComponent reason) {
}
/**
- * Splits the raw name and preferredVersion strings, making them use multiple lines if needed, to fit within the table dimensions.
+ * Splits the raw name and version strings, making them use multiple lines if needed, to fit within the table dimensions.
* The style assigned to the name element is then applied to the entire content row.
*
* @param name The first element of the content row, usually representing a table section header or the name of a mod entry
@@ -127,7 +127,7 @@ record Row(MutableComponent name, MutableComponent reason) {
private List> splitLineToWidth(MutableComponent name, MutableComponent reason) {
Style style = name.getStyle();
int versionColumns = 1;
- int adaptedNameWidth = nameWidth + versionWidth * (2 - versionColumns) - 4; //the name width may be expanded when the preferredVersion column string is missing
+ int adaptedNameWidth = nameWidth + versionWidth * (2 - versionColumns) - 4; //the name width may be expanded when the version column string is missing
List nameLines = font.split(name, adaptedNameWidth);
List reasonLines = font.split(reason.setStyle(style), versionWidth - 4);
List> splitLines = new ArrayList<>();
@@ -184,7 +184,7 @@ protected void drawPanel(GuiGraphics guiGraphics, int entryRight, int relativeY,
FormattedCharSequence reaons = line.getRight();
//Since font#draw does not respect the color of the given component, we have to read it out here and then use it as the last parameter
int color = Optional.ofNullable(font.getSplitter().componentStyleAtWidth(name, 0)).map(Style::getColor).map(TextColor::getValue).orElse(0xFFFFFF);
- //Only indent the given name if a preferredVersion string is present. This makes it easier to distinguish table section headers and mod entries
+ //Only indent the given name if a version string is present. This makes it easier to distinguish table section headers and mod entries
int nameLeft = left + border + (reaons == null ? 0 : nameIndent);
guiGraphics.drawString(font, name, nameLeft, relativeY + i * 12, color, false);
if (reaons != null) {
@@ -209,7 +209,7 @@ public Style getComponentStyleAt(double x, double y) {
double relativeY = y - this.top + this.scrollDistance - border;
int slotIndex = (int) (relativeY + (border / 2)) / 12;
if (slotIndex < contentSize) {
- //The relative x needs to take the potentially missing indent of the row into account. It does that by checking if the line has a preferredVersion associated to it
+ //The relative x needs to take the potentially missing indent of the row into account. It does that by checking if the line has a version associated to it
double relativeX = x - left - border - (lineTable.get(slotIndex).getRight() == null ? 0 : nameIndent);
if (relativeX >= 0)
return font.getSplitter().componentStyleAtWidth(lineTable.get(slotIndex).getLeft(), (int) relativeX);
diff --git a/src/main/java/net/neoforged/neoforge/client/model/ExtendedBlockModelDeserializer.java b/src/main/java/net/neoforged/neoforge/client/model/ExtendedBlockModelDeserializer.java
index 5c5395d6a4..e3b2bd9feb 100644
--- a/src/main/java/net/neoforged/neoforge/client/model/ExtendedBlockModelDeserializer.java
+++ b/src/main/java/net/neoforged/neoforge/client/model/ExtendedBlockModelDeserializer.java
@@ -31,7 +31,7 @@
import org.jetbrains.annotations.Nullable;
/**
- * A preferredVersion of {@link BlockModel.Deserializer} capable of deserializing models with custom loaders, as well as other
+ * A version of {@link BlockModel.Deserializer} capable of deserializing models with custom loaders, as well as other
* changes introduced to the spec by Forge.
*/
public class ExtendedBlockModelDeserializer extends BlockModel.Deserializer {
diff --git a/src/main/java/net/neoforged/neoforge/common/CommonHooks.java b/src/main/java/net/neoforged/neoforge/common/CommonHooks.java
index 4c61abe539..5d72ea2292 100644
--- a/src/main/java/net/neoforged/neoforge/common/CommonHooks.java
+++ b/src/main/java/net/neoforged/neoforge/common/CommonHooks.java
@@ -1151,24 +1151,24 @@ public static void readAdditionalLevelSaveData(CompoundTag rootTag, LevelStorage
final var mismatchEvent = new ModMismatchEvent(levelDirectory, mismatchedVersions, missingVersions);
ModLoader.get().postEvent(mismatchEvent);
- StringBuilder resolved = new StringBuilder("The following mods have preferredVersion differences that were marked resolved:");
- StringBuilder unresolved = new StringBuilder("The following mods have preferredVersion differences that were not resolved:");
+ StringBuilder resolved = new StringBuilder("The following mods have version differences that were marked resolved:");
+ StringBuilder unresolved = new StringBuilder("The following mods have version differences that were not resolved:");
- // For mods that were marked resolved, log the preferredVersion resolution and the mod that resolved the mismatch
+ // For mods that were marked resolved, log the version resolution and the mod that resolved the mismatch
mismatchEvent.getResolved().forEachOrdered((res) -> {
final var modid = res.modid();
final var diff = res.versionDifference();
if (res.wasSelfResolved()) {
resolved.append(System.lineSeparator())
.append(diff.isMissing()
- ? "%s (preferredVersion %s -> MISSING, self-resolved)".formatted(modid, diff.oldVersion())
- : "%s (preferredVersion %s -> %s, self-resolved)".formatted(modid, diff.oldVersion(), diff.newVersion()));
+ ? "%s (version %s -> MISSING, self-resolved)".formatted(modid, diff.oldVersion())
+ : "%s (version %s -> %s, self-resolved)".formatted(modid, diff.oldVersion(), diff.newVersion()));
} else {
final var resolver = res.resolver().getModId();
resolved.append(System.lineSeparator())
.append(diff.isMissing()
- ? "%s (preferredVersion %s -> MISSING, resolved by %s)".formatted(modid, diff.oldVersion(), resolver)
- : "%s (preferredVersion %s -> %s, resolved by %s)".formatted(modid, diff.oldVersion(), diff.newVersion(), resolver));
+ ? "%s (version %s -> MISSING, resolved by %s)".formatted(modid, diff.oldVersion(), resolver)
+ : "%s (version %s -> %s, resolved by %s)".formatted(modid, diff.oldVersion(), diff.newVersion(), resolver));
}
});
@@ -1178,8 +1178,8 @@ public static void readAdditionalLevelSaveData(CompoundTag rootTag, LevelStorage
final var diff = unres.versionDifference();
unresolved.append(System.lineSeparator())
.append(diff.isMissing()
- ? "%s (preferredVersion %s -> MISSING)".formatted(modid, diff.oldVersion())
- : "%s (preferredVersion %s -> %s)".formatted(modid, diff.oldVersion(), diff.newVersion()));
+ ? "%s (version %s -> MISSING)".formatted(modid, diff.oldVersion())
+ : "%s (version %s -> %s)".formatted(modid, diff.oldVersion(), diff.newVersion()));
});
if (mismatchEvent.anyResolved()) {
diff --git a/src/main/java/net/neoforged/neoforge/common/I18nExtension.java b/src/main/java/net/neoforged/neoforge/common/I18nExtension.java
index dd1353330b..3e03e45914 100644
--- a/src/main/java/net/neoforged/neoforge/common/I18nExtension.java
+++ b/src/main/java/net/neoforged/neoforge/common/I18nExtension.java
@@ -44,7 +44,7 @@ public class I18nExtension {
customFactories.put("upper", (name, formatString, locale) -> new CustomReadOnlyFormat((stringBuffer, objectToParse) -> stringBuffer.append(StringUtils.toUpperCase(String.valueOf(objectToParse)))));
// {0,exc,cls} -> class of exception; {0,exc,msg} -> message from exception
customFactories.put("exc", (name, formatString, locale) -> new CustomReadOnlyFormat((stringBuffer, objectToParse) -> parseException(formatString, stringBuffer, objectToParse)));
- // {0,vr} -> transform VersionRange into cleartext string using fml.messages.preferredVersion.restriction.* strings
+ // {0,vr} -> transform VersionRange into cleartext string using fml.messages.version.restriction.* strings
customFactories.put("vr", (name, formatString, locale) -> new CustomReadOnlyFormat(MavenVersionStringHelper::parseVersionRange));
// {0,featurebound} -> transform feature bound to cleartext string
customFactories.put("featurebound", (name, formatString, locale) -> new CustomReadOnlyFormat(MavenVersionStringHelper::parseFeatureBoundValue));
diff --git a/src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java b/src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java
index 19a52ceaaa..ce06a0724c 100644
--- a/src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java
+++ b/src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java
@@ -427,7 +427,7 @@ public static void enableMilkFluid() {
}
public NeoForgeMod(IEventBus modEventBus, Dist dist) {
- LOGGER.info(NEOFORGEMOD, "NeoForge mod loading, preferredVersion {}, for MC {} with MCP {}", NeoForgeVersion.getVersion(), NeoFormVersion.getMCVersion(), NeoFormVersion.getMCPVersion());
+ LOGGER.info(NEOFORGEMOD, "NeoForge mod loading, version {}, for MC {} with MCP {}", NeoForgeVersion.getVersion(), NeoFormVersion.getMCVersion(), NeoFormVersion.getMCPVersion());
ForgeSnapshotsMod.logStartupWarning();
CrashReportCallables.registerCrashCallable("Crash Report UUID", () -> {
@@ -436,7 +436,7 @@ public NeoForgeMod(IEventBus modEventBus, Dist dist) {
return uuid.toString();
});
- LOGGER.debug(NEOFORGEMOD, "Loading Network data for FML net preferredVersion: {}", NetworkConstants.init());
+ LOGGER.debug(NEOFORGEMOD, "Loading Network data for FML net version: {}", NetworkConstants.init());
CrashReportCallables.registerCrashCallable("FML", NeoForgeVersion::getSpec);
CrashReportCallables.registerCrashCallable("NeoForge", () -> NeoForgeVersion.getGroup() + ":" + NeoForgeVersion.getVersion());
@@ -470,7 +470,7 @@ public NeoForgeMod(IEventBus modEventBus, Dist dist) {
ForgeDeferredRegistriesSetup.setup(modEventBus);
// Forge does not display problems when the remote is not matching.
ModLoadingContext.get().registerExtensionPoint(IExtensionPoint.DisplayTest.class, () -> new IExtensionPoint.DisplayTest(() -> "ANY", (remote, isServer) -> true));
- StartupMessageManager.addModMessage("NeoForge preferredVersion " + NeoForgeVersion.getVersion());
+ StartupMessageManager.addModMessage("NeoForge version " + NeoForgeVersion.getVersion());
NeoForge.EVENT_BUS.addListener(VillagerTradingManager::loadTrades);
NeoForge.EVENT_BUS.register(new NeoForgeEventHandler());
diff --git a/src/main/java/net/neoforged/neoforge/common/capabilities/ICapabilityProvider.java b/src/main/java/net/neoforged/neoforge/common/capabilities/ICapabilityProvider.java
index 08eb36acd1..12063e45b0 100644
--- a/src/main/java/net/neoforged/neoforge/common/capabilities/ICapabilityProvider.java
+++ b/src/main/java/net/neoforged/neoforge/common/capabilities/ICapabilityProvider.java
@@ -26,8 +26,8 @@ public interface ICapabilityProvider {
LazyOptional getCapability(@NotNull final Capability cap, final @Nullable Direction side);
/*
- * Purely added as a bouncer to sided preferredVersion, to make modders stop complaining about calling with a null value.
- * This should never be OVERRIDDEN, modders should only ever implement the sided preferredVersion.
+ * Purely added as a bouncer to sided version, to make modders stop complaining about calling with a null value.
+ * This should never be OVERRIDDEN, modders should only ever implement the sided version.
*/
@NotNull
default LazyOptional getCapability(@NotNull final Capability cap) {
diff --git a/src/main/java/net/neoforged/neoforge/common/data/ExistingFileHelper.java b/src/main/java/net/neoforged/neoforge/common/data/ExistingFileHelper.java
index 24d303e510..ead9ebb696 100644
--- a/src/main/java/net/neoforged/neoforge/common/data/ExistingFileHelper.java
+++ b/src/main/java/net/neoforged/neoforge/common/data/ExistingFileHelper.java
@@ -95,7 +95,7 @@ public String getPrefix() {
* @param existingPacks a collection of paths to existing packs
* @param existingMods a set of mod IDs for existing mods
* @param enable {@code true} if validation is enabled
- * @param assetIndex the identifier for the asset index, generally Minecraft's current major preferredVersion
+ * @param assetIndex the identifier for the asset index, generally Minecraft's current major version
* @param assetsDir the directory in which to find vanilla assets and indexes
*/
public ExistingFileHelper(Collection existingPacks, final Set existingMods, boolean enable, @Nullable final String assetIndex, @Nullable final File assetsDir) {
diff --git a/src/main/java/net/neoforged/neoforge/common/extensions/IBlockAndTintGetterExtension.java b/src/main/java/net/neoforged/neoforge/common/extensions/IBlockAndTintGetterExtension.java
index faf4120928..c177f3b878 100644
--- a/src/main/java/net/neoforged/neoforge/common/extensions/IBlockAndTintGetterExtension.java
+++ b/src/main/java/net/neoforged/neoforge/common/extensions/IBlockAndTintGetterExtension.java
@@ -18,7 +18,7 @@ private BlockAndTintGetter self() {
/**
* Computes the shade for a given normal.
- * Alternate preferredVersion of the vanilla method taking in a {@link Direction}.
+ * Alternate version of the vanilla method taking in a {@link Direction}.
*/
default float getShade(float normalX, float normalY, float normalZ, boolean shade) {
return self().getShade(Direction.getNearest(normalX, normalY, normalZ), shade);
diff --git a/src/main/java/net/neoforged/neoforge/common/extensions/IBlockExtension.java b/src/main/java/net/neoforged/neoforge/common/extensions/IBlockExtension.java
index ada4649606..08a9736db1 100644
--- a/src/main/java/net/neoforged/neoforge/common/extensions/IBlockExtension.java
+++ b/src/main/java/net/neoforged/neoforge/common/extensions/IBlockExtension.java
@@ -258,7 +258,7 @@ default Direction getBedDirection(BlockState state, LevelReader level, BlockPos
}
/**
- * Location sensitive preferredVersion of getExplosionResistance
+ * Location sensitive version of getExplosionResistance
*
* @param level The current level
* @param pos Block position in level
@@ -463,7 +463,7 @@ default boolean getWeakChanges(BlockState state, LevelReader level, BlockPos pos
}
/**
- * Sensitive preferredVersion of getSoundType
+ * Sensitive version of getSoundType
*
* @param state The state
* @param level The level
diff --git a/src/main/java/net/neoforged/neoforge/common/extensions/IBlockStateExtension.java b/src/main/java/net/neoforged/neoforge/common/extensions/IBlockStateExtension.java
index 13442aa7bf..e106b8b243 100644
--- a/src/main/java/net/neoforged/neoforge/common/extensions/IBlockStateExtension.java
+++ b/src/main/java/net/neoforged/neoforge/common/extensions/IBlockStateExtension.java
@@ -188,7 +188,7 @@ default Direction getBedDirection(LevelReader level, BlockPos pos) {
}
/**
- * Location sensitive preferredVersion of getExplosionResistance
+ * Location sensitive version of getExplosionResistance
*
* @param level The current level
* @param pos Block position in level
@@ -385,7 +385,7 @@ default boolean getWeakChanges(LevelReader level, BlockPos pos) {
}
/**
- * Sensitive preferredVersion of getSoundType
+ * Sensitive version of getSoundType
*
* @param level The level
* @param pos The position. Note that the level may not necessarily have {@code state} here!
diff --git a/src/main/java/net/neoforged/neoforge/common/extensions/IEnchantmentExtension.java b/src/main/java/net/neoforged/neoforge/common/extensions/IEnchantmentExtension.java
index 6362cfd7fa..f0cbfe0024 100644
--- a/src/main/java/net/neoforged/neoforge/common/extensions/IEnchantmentExtension.java
+++ b/src/main/java/net/neoforged/neoforge/common/extensions/IEnchantmentExtension.java
@@ -18,7 +18,7 @@ private Enchantment self() {
}
/**
- * ItemStack aware preferredVersion of {@link Enchantment#getDamageBonus(int, MobType)}
+ * ItemStack aware version of {@link Enchantment#getDamageBonus(int, MobType)}
*
* @param level the level of the enchantment
* @param mobType the mob type being attacked
diff --git a/src/main/java/net/neoforged/neoforge/common/extensions/IFriendlyByteBufExtension.java b/src/main/java/net/neoforged/neoforge/common/extensions/IFriendlyByteBufExtension.java
index fbb48d8857..bced087f2b 100644
--- a/src/main/java/net/neoforged/neoforge/common/extensions/IFriendlyByteBufExtension.java
+++ b/src/main/java/net/neoforged/neoforge/common/extensions/IFriendlyByteBufExtension.java
@@ -93,7 +93,7 @@ default void writeRegistryId(@NotNull IForgeRegistry registry, @NotNull T
/**
* Reads an registry-entry from the specified buffer. Notice however that the type cannot be checked without providing an additional class parameter
- * - see {@link #readRegistryIdSafe(Class)} for an safe preferredVersion.
+ * - see {@link #readRegistryIdSafe(Class)} for an safe version.
*
* @param The type of the registry-entry. Notice that this should match the actual type written to the buffer.
* @throws NullPointerException if the registry could not be found.
diff --git a/src/main/java/net/neoforged/neoforge/common/extensions/IItemExtension.java b/src/main/java/net/neoforged/neoforge/common/extensions/IItemExtension.java
index 557b7234b7..68f5d738d8 100644
--- a/src/main/java/net/neoforged/neoforge/common/extensions/IItemExtension.java
+++ b/src/main/java/net/neoforged/neoforge/common/extensions/IItemExtension.java
@@ -53,7 +53,7 @@ private Item self() {
}
/**
- * ItemStack sensitive preferredVersion of getItemAttributeModifiers
+ * ItemStack sensitive version of getItemAttributeModifiers
*/
@SuppressWarnings("deprecation")
default Multimap getAttributeModifiers(EquipmentSlot slot, ItemStack stack) {
@@ -212,7 +212,7 @@ default boolean onLeftClickEntity(ItemStack stack, Player player, Entity entity)
}
/**
- * ItemStack sensitive preferredVersion of {@link Item#getCraftingRemainingItem()}.
+ * ItemStack sensitive version of {@link Item#getCraftingRemainingItem()}.
* Returns a full ItemStack instance of the result.
*
* @param itemStack The current ItemStack
@@ -227,7 +227,7 @@ default ItemStack getCraftingRemainingItem(ItemStack itemStack) {
}
/**
- * ItemStack sensitive preferredVersion of {@link Item#hasCraftingRemainingItem()}.
+ * ItemStack sensitive version of {@link Item#hasCraftingRemainingItem()}.
*
* @param stack The current item stack
* @return True if this item has a crafting remaining item
@@ -434,7 +434,7 @@ default boolean canPerformAction(ItemStack stack, ToolAction toolAction) {
}
/**
- * ItemStack sensitive preferredVersion of {@link Item#isCorrectToolForDrops(BlockState)}
+ * ItemStack sensitive version of {@link Item#isCorrectToolForDrops(BlockState)}
*
* @param stack The itemstack used to harvest the block
* @param state The block trying to harvest
@@ -446,7 +446,7 @@ default boolean isCorrectToolForDrops(ItemStack stack, BlockState state) {
/**
* Gets the maximum number of items that this stack should be able to hold. This
- * is a ItemStack (and thus NBT) sensitive preferredVersion of {@link Item#getMaxStackSize()}.
+ * is a ItemStack (and thus NBT) sensitive version of {@link Item#getMaxStackSize()}.
*
* @param stack The ItemStack
* @return The maximum size this item can be stacked to
@@ -457,7 +457,7 @@ default int getMaxStackSize(ItemStack stack) {
}
/**
- * ItemStack sensitive preferredVersion of {@link Item#getEnchantmentValue()}.
+ * ItemStack sensitive version of {@link Item#getEnchantmentValue()}.
*
* @param stack The ItemStack
* @return the enchantment value
diff --git a/src/main/java/net/neoforged/neoforge/common/extensions/IItemStackExtension.java b/src/main/java/net/neoforged/neoforge/common/extensions/IItemStackExtension.java
index 87ababfa27..40ce83d624 100644
--- a/src/main/java/net/neoforged/neoforge/common/extensions/IItemStackExtension.java
+++ b/src/main/java/net/neoforged/neoforge/common/extensions/IItemStackExtension.java
@@ -49,7 +49,7 @@ private ItemStack self() {
}
/**
- * ItemStack sensitive preferredVersion of {@link Item#getCraftingRemainingItem()}.
+ * ItemStack sensitive version of {@link Item#getCraftingRemainingItem()}.
* Returns a full ItemStack instance of the result.
*
* @return The resulting ItemStack
@@ -59,7 +59,7 @@ default ItemStack getCraftingRemainingItem() {
}
/**
- * ItemStack sensitive preferredVersion of {@link Item#hasCraftingRemainingItem()}.
+ * ItemStack sensitive version of {@link Item#hasCraftingRemainingItem()}.
*
* @return True if this item has a crafting remaining item
*/
@@ -183,7 +183,7 @@ default Map getAllEnchantments() {
}
/**
- * ItemStack sensitive preferredVersion of {@link Item#getEnchantmentValue()}.
+ * ItemStack sensitive version of {@link Item#getEnchantmentValue()}.
*
* @return the enchantment value of this ItemStack
*/
diff --git a/src/main/java/net/neoforged/neoforge/common/util/MavenVersionStringHelper.java b/src/main/java/net/neoforged/neoforge/common/util/MavenVersionStringHelper.java
index c55291ecf4..9d80e1d8dd 100644
--- a/src/main/java/net/neoforged/neoforge/common/util/MavenVersionStringHelper.java
+++ b/src/main/java/net/neoforged/neoforge/common/util/MavenVersionStringHelper.java
@@ -24,32 +24,32 @@ public static String versionRangeToString(final VersionRange range) {
public static String restrictionToString(final Restriction restriction) {
if (restriction.getLowerBound() == null && restriction.getUpperBound() == null) {
- return I18nExtension.parseMessage("fml.messages.preferredVersion.restriction.any");
+ return I18nExtension.parseMessage("fml.messages.version.restriction.any");
} else if (restriction.getLowerBound() != null && restriction.getUpperBound() != null) {
if (Objects.equals(artifactVersionToString(restriction.getLowerBound()), artifactVersionToString(restriction.getUpperBound()))) {
return artifactVersionToString(restriction.getLowerBound());
} else {
if (restriction.isLowerBoundInclusive() && restriction.isUpperBoundInclusive()) {
- return I18nExtension.parseMessage("fml.messages.preferredVersion.restriction.bounded.inclusive", restriction.getLowerBound(), restriction.getUpperBound());
+ return I18nExtension.parseMessage("fml.messages.version.restriction.bounded.inclusive", restriction.getLowerBound(), restriction.getUpperBound());
} else if (restriction.isLowerBoundInclusive()) {
- return I18nExtension.parseMessage("fml.messages.preferredVersion.restriction.bounded.upperexclusive", restriction.getLowerBound(), restriction.getUpperBound());
+ return I18nExtension.parseMessage("fml.messages.version.restriction.bounded.upperexclusive", restriction.getLowerBound(), restriction.getUpperBound());
} else if (restriction.isUpperBoundInclusive()) {
- return I18nExtension.parseMessage("fml.messages.preferredVersion.restriction.bounded.lowerexclusive", restriction.getLowerBound(), restriction.getUpperBound());
+ return I18nExtension.parseMessage("fml.messages.version.restriction.bounded.lowerexclusive", restriction.getLowerBound(), restriction.getUpperBound());
} else {
- return I18nExtension.parseMessage("fml.messages.preferredVersion.restriction.bounded.exclusive", restriction.getLowerBound(), restriction.getUpperBound());
+ return I18nExtension.parseMessage("fml.messages.version.restriction.bounded.exclusive", restriction.getLowerBound(), restriction.getUpperBound());
}
}
} else if (restriction.getLowerBound() != null) {
if (restriction.isLowerBoundInclusive()) {
- return I18nExtension.parseMessage("fml.messages.preferredVersion.restriction.lower.inclusive", restriction.getLowerBound());
+ return I18nExtension.parseMessage("fml.messages.version.restriction.lower.inclusive", restriction.getLowerBound());
} else {
- return I18nExtension.parseMessage("fml.messages.preferredVersion.restriction.lower.exclusive", restriction.getLowerBound());
+ return I18nExtension.parseMessage("fml.messages.version.restriction.lower.exclusive", restriction.getLowerBound());
}
} else {
if (restriction.isUpperBoundInclusive()) {
- return I18nExtension.parseMessage("fml.messages.preferredVersion.restriction.upper.inclusive", restriction.getUpperBound());
+ return I18nExtension.parseMessage("fml.messages.version.restriction.upper.inclusive", restriction.getUpperBound());
} else {
- return I18nExtension.parseMessage("fml.messages.preferredVersion.restriction.upper.exclusive", restriction.getUpperBound());
+ return I18nExtension.parseMessage("fml.messages.version.restriction.upper.exclusive", restriction.getUpperBound());
}
}
}
diff --git a/src/main/java/net/neoforged/neoforge/event/ModMismatchEvent.java b/src/main/java/net/neoforged/neoforge/event/ModMismatchEvent.java
index ba9025fcae..1efcb0463e 100644
--- a/src/main/java/net/neoforged/neoforge/event/ModMismatchEvent.java
+++ b/src/main/java/net/neoforged/neoforge/event/ModMismatchEvent.java
@@ -50,7 +50,7 @@ public class ModMismatchEvent extends Event implements IModBusEvent {
private final HashMap versionDifferences;
/**
- * Which mods have specified that they have handled preferredVersion mismatches.
+ * Which mods have specified that they have handled version mismatches.
*/
private final HashMap resolved;
@@ -77,10 +77,10 @@ public LevelStorageSource.LevelDirectory getLevelDirectory() {
}
/**
- * Fetch a previous preferredVersion of a given mod, if it has been mismatched.
+ * Fetch a previous version of a given mod, if it has been mismatched.
*
- * @param modId The mod to fetch previous preferredVersion for.
- * @return The previously known mod preferredVersion, or {@link Optional#empty()} if unknown/not found.
+ * @param modId The mod to fetch previous version for.
+ * @return The previously known mod version, or {@link Optional#empty()} if unknown/not found.
*/
@Nullable
public ArtifactVersion getPreviousVersion(String modId) {
@@ -99,7 +99,7 @@ public ArtifactVersion getCurrentVersion(String modid) {
}
/**
- * Marks the mod preferredVersion mismatch as having been resolved safely by the current mod.
+ * Marks the mod version mismatch as having been resolved safely by the current mod.
*/
public void markResolved(String modId) {
final var resolvedBy = ModLoadingContext.get().getActiveContainer();
diff --git a/src/main/java/net/neoforged/neoforge/event/RegisterStructureConversionsEvent.java b/src/main/java/net/neoforged/neoforge/event/RegisterStructureConversionsEvent.java
index bce158f085..aa924fda64 100644
--- a/src/main/java/net/neoforged/neoforge/event/RegisterStructureConversionsEvent.java
+++ b/src/main/java/net/neoforged/neoforge/event/RegisterStructureConversionsEvent.java
@@ -22,7 +22,7 @@
* conversions for their structures, if they wish to override this default behavior.
*
* This event will only fire if {@link StructuresBecomeConfiguredFix} is used, as a result of converting a
- * pre-1.18.2 world to the current preferredVersion.
+ * pre-1.18.2 world to the current version.
*
* This event is not {@linkplain ICancellableEvent cancelable}, and does not {@linkplain HasResult have a result}.
*
diff --git a/src/main/java/net/neoforged/neoforge/event/entity/EntityEvent.java b/src/main/java/net/neoforged/neoforge/event/entity/EntityEvent.java
index d07ce8c931..fd1dcd2d76 100644
--- a/src/main/java/net/neoforged/neoforge/event/entity/EntityEvent.java
+++ b/src/main/java/net/neoforged/neoforge/event/entity/EntityEvent.java
@@ -72,7 +72,7 @@ public EnteringSection(Entity entity, long packedOldPos, long packedNewPos) {
}
/**
- * A packed preferredVersion of the old section's position. This is to be used with the various methods in {@link SectionPos},
+ * A packed version of the old section's position. This is to be used with the various methods in {@link SectionPos},
* such as {@link SectionPos#of(long)} or {@link SectionPos#x(long)} to avoid allocation.
*
* @return the packed position of the old section
@@ -82,7 +82,7 @@ public long getPackedOldPos() {
}
/**
- * A packed preferredVersion of the new section's position. This is to be used with the various methods in {@link SectionPos},
+ * A packed version of the new section's position. This is to be used with the various methods in {@link SectionPos},
* such as {@link SectionPos#of(long)} or {@link SectionPos#x(long)} to avoid allocation.
*
* @return the packed position of the new section
diff --git a/src/main/java/net/neoforged/neoforge/event/entity/living/LivingDestroyBlockEvent.java b/src/main/java/net/neoforged/neoforge/event/entity/living/LivingDestroyBlockEvent.java
index 0b4e20abba..726fc58ccd 100644
--- a/src/main/java/net/neoforged/neoforge/event/entity/living/LivingDestroyBlockEvent.java
+++ b/src/main/java/net/neoforged/neoforge/event/entity/living/LivingDestroyBlockEvent.java
@@ -15,7 +15,7 @@
import net.neoforged.neoforge.common.NeoForge;
/**
- * Fired when the ender dragon or wither attempts to destroy a block and when ever a zombie attempts to break a door. Basically a event preferredVersion of {@link Block#canEntityDestroy(BlockState, BlockGetter, BlockPos, Entity)}
+ * Fired when the ender dragon or wither attempts to destroy a block and when ever a zombie attempts to break a door. Basically a event version of {@link Block#canEntityDestroy(BlockState, BlockGetter, BlockPos, Entity)}
*
* This event is {@link ICancellableEvent}.
* If this event is canceled, the block will not be destroyed.
diff --git a/src/main/java/net/neoforged/neoforge/fluids/FluidUtil.java b/src/main/java/net/neoforged/neoforge/fluids/FluidUtil.java
index c4fa0bfc48..2e6308743a 100644
--- a/src/main/java/net/neoforged/neoforge/fluids/FluidUtil.java
+++ b/src/main/java/net/neoforged/neoforge/fluids/FluidUtil.java
@@ -443,7 +443,7 @@ public static FluidActionResult tryPickUpFluid(@NotNull ItemStack emptyContainer
}
/**
- * ItemStack preferredVersion of {@link #tryPlaceFluid(Player, Level, InteractionHand, BlockPos, IFluidHandler, FluidStack)}.
+ * ItemStack version of {@link #tryPlaceFluid(Player, Level, InteractionHand, BlockPos, IFluidHandler, FluidStack)}.
* Use the returned {@link FluidActionResult} to update the container ItemStack.
*
* @param player Player who places the fluid. May be null for blocks like dispensers.
diff --git a/src/main/java/net/neoforged/neoforge/internal/NeoForgeStatesProvider.java b/src/main/java/net/neoforged/neoforge/internal/NeoForgeStatesProvider.java
index 5822b6a597..53c440079b 100644
--- a/src/main/java/net/neoforged/neoforge/internal/NeoForgeStatesProvider.java
+++ b/src/main/java/net/neoforged/neoforge/internal/NeoForgeStatesProvider.java
@@ -5,17 +5,18 @@
package net.neoforged.neoforge.internal;
-import java.util.List;
import net.neoforged.fml.IModLoadingState;
import net.neoforged.fml.IModStateProvider;
import net.neoforged.fml.ModLoadingPhase;
import net.neoforged.fml.ModLoadingState;
import net.neoforged.neoforge.common.capabilities.CapabilityManager;
-import net.neoforged.neoforge.network.NetworkRegistry;
+import net.neoforged.neoforge.network.registration.NetworkRegistry;
import net.neoforged.neoforge.registries.GameData;
import net.neoforged.neoforge.registries.ObjectHolderRegistry;
import net.neoforged.neoforge.registries.RegistryManager;
+import java.util.List;
+
public class NeoForgeStatesProvider implements IModStateProvider {
final ModLoadingState CREATE_REGISTRIES = ModLoadingState.withInline("CREATE_REGISTRIES", "CONSTRUCT", ModLoadingPhase.GATHER, ml -> RegistryManager.postNewRegistryEvent());
final ModLoadingState OBJECT_HOLDERS = ModLoadingState.withInline("OBJECT_HOLDERS", "CREATE_REGISTRIES", ModLoadingPhase.GATHER, ml -> ObjectHolderRegistry.findObjectHolders());
@@ -23,7 +24,7 @@ public class NeoForgeStatesProvider implements IModStateProvider {
final ModLoadingState UNFREEZE = ModLoadingState.withInline("UNFREEZE_DATA", "INJECT_CAPABILITIES", ModLoadingPhase.GATHER, ml -> GameData.unfreezeData());
final ModLoadingState LOAD_REGISTRIES = ModLoadingState.withInline("LOAD_REGISTRIES", "UNFREEZE_DATA", ModLoadingPhase.GATHER, ml -> GameData.postRegisterEvents());
final ModLoadingState FREEZE = ModLoadingState.withInline("FREEZE_DATA", "COMPLETE", ModLoadingPhase.COMPLETE, ml -> GameData.freezeData());
- final ModLoadingState NETLOCK = ModLoadingState.withInline("NETWORK_LOCK", "FREEZE_DATA", ModLoadingPhase.COMPLETE, ml -> NetworkRegistry.lock());
+ final ModLoadingState NETLOCK = ModLoadingState.withInline("NETWORK_LOCK", "FREEZE_DATA", ModLoadingPhase.COMPLETE, ml -> NetworkRegistry.getInstance().setup());
@Override
public List getAllStates() {
diff --git a/src/main/java/net/neoforged/neoforge/internal/versions/neoforge/NeoForgeVersion.java b/src/main/java/net/neoforged/neoforge/internal/versions/neoforge/NeoForgeVersion.java
index 2a8836cd3d..3d29e09fd2 100644
--- a/src/main/java/net/neoforged/neoforge/internal/versions/neoforge/NeoForgeVersion.java
+++ b/src/main/java/net/neoforged/neoforge/internal/versions/neoforge/NeoForgeVersion.java
@@ -26,7 +26,7 @@ public class NeoForgeVersion {
static {
LOGGER.debug(Logging.CORE, "NeoForge Version package {} from {}", NeoForgeVersion.class.getPackage(), NeoForgeVersion.class.getClassLoader());
String vers = JarVersionLookupHandler.getImplementationVersion(NeoForgeVersion.class).orElse(FMLLoader.versionInfo().neoForgeVersion());
- if (vers == null) throw new RuntimeException("Missing NeoForge preferredVersion, cannot continue");
+ if (vers == null) throw new RuntimeException("Missing NeoForge version, cannot continue");
String spec = JarVersionLookupHandler.getSpecificationVersion(NeoForgeVersion.class).orElse(System.getenv("NEOFORGE_SPEC"));
if (spec == null) throw new RuntimeException("Missing NeoForge spec, cannot continue");
String group = JarVersionLookupHandler.getImplementationTitle(NeoForgeVersion.class).orElse("net.neoforged");
@@ -36,7 +36,7 @@ public class NeoForgeVersion {
neoForgeVersion = vers;
neoForgeSpec = spec;
neoForgeGroup = group;
- LOGGER.debug(Logging.CORE, "Found NeoForge preferredVersion {}", neoForgeVersion);
+ LOGGER.debug(Logging.CORE, "Found NeoForge version {}", neoForgeVersion);
LOGGER.debug(Logging.CORE, "Found NeoForge spec {}", neoForgeSpec);
LOGGER.debug(Logging.CORE, "Found NeoForge group {}", neoForgeGroup);
}
diff --git a/src/main/java/net/neoforged/neoforge/internal/versions/neoform/NeoFormVersion.java b/src/main/java/net/neoforged/neoforge/internal/versions/neoform/NeoFormVersion.java
index cfb1f1145a..a6f22798c2 100644
--- a/src/main/java/net/neoforged/neoforge/internal/versions/neoform/NeoFormVersion.java
+++ b/src/main/java/net/neoforged/neoforge/internal/versions/neoform/NeoFormVersion.java
@@ -18,13 +18,13 @@ public class NeoFormVersion {
static {
LOGGER.debug(Logging.CORE, "NeoForm Version package {} from {}", NeoFormVersion.class.getPackage(), NeoFormVersion.class.getClassLoader());
mcVersion = JarVersionLookupHandler.getSpecificationVersion(NeoFormVersion.class).orElse(FMLLoader.versionInfo().mcVersion());
- if (mcVersion == null) throw new RuntimeException("Missing MC preferredVersion, cannot continue");
+ if (mcVersion == null) throw new RuntimeException("Missing MC version, cannot continue");
neoFormVersion = JarVersionLookupHandler.getImplementationVersion(NeoFormVersion.class).orElse(FMLLoader.versionInfo().neoFormVersion());
- if (neoFormVersion == null) throw new RuntimeException("Missing NeoForm preferredVersion, cannot continue");
+ if (neoFormVersion == null) throw new RuntimeException("Missing NeoForm version, cannot continue");
- LOGGER.debug(Logging.CORE, "Found MC preferredVersion information {}", mcVersion);
- LOGGER.debug(Logging.CORE, "Found NeoForm preferredVersion information {}", neoFormVersion);
+ LOGGER.debug(Logging.CORE, "Found MC version information {}", mcVersion);
+ LOGGER.debug(Logging.CORE, "Found NeoForm version information {}", neoFormVersion);
}
public static String getMCVersion() {
diff --git a/src/main/java/net/neoforged/neoforge/items/ItemHandlerHelper.java b/src/main/java/net/neoforged/neoforge/items/ItemHandlerHelper.java
index 85477bedec..c1a5d5ad15 100644
--- a/src/main/java/net/neoforged/neoforge/items/ItemHandlerHelper.java
+++ b/src/main/java/net/neoforged/neoforge/items/ItemHandlerHelper.java
@@ -40,7 +40,7 @@ public static boolean canItemStacksStack(@NotNull ItemStack a, @NotNull ItemStac
}
/**
- * A relaxed preferredVersion of canItemStacksStack that stacks itemstacks with different metadata if they don't have subtypes.
+ * A relaxed version of canItemStacksStack that stacks itemstacks with different metadata if they don't have subtypes.
* This usually only applies when players pick up items.
*/
public static boolean canItemStacksStackRelaxed(@NotNull ItemStack a, @NotNull ItemStack b) {
diff --git a/src/main/java/net/neoforged/neoforge/network/ConfigSync.java b/src/main/java/net/neoforged/neoforge/network/ConfigSync.java
index 5a00faa63a..6bf08c9e4f 100644
--- a/src/main/java/net/neoforged/neoforge/network/ConfigSync.java
+++ b/src/main/java/net/neoforged/neoforge/network/ConfigSync.java
@@ -5,17 +5,20 @@
package net.neoforged.neoforge.network;
+import net.minecraft.client.Minecraft;
+import net.neoforged.fml.config.ConfigTracker;
+import net.neoforged.fml.config.ModConfig;
+import net.neoforged.neoforge.network.payload.ConfigFilePayload;
+import org.jetbrains.annotations.ApiStatus;
+
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
-import net.minecraft.client.Minecraft;
-import net.neoforged.fml.config.ConfigTracker;
-import net.neoforged.fml.config.ModConfig;
-import net.neoforged.neoforge.network.simple.MessageFunctions;
+@ApiStatus.Internal
public class ConfigSync {
public static final ConfigSync INSTANCE = new ConfigSync(ConfigTracker.INSTANCE);
private final ConfigTracker tracker;
@@ -24,7 +27,7 @@ private ConfigSync(final ConfigTracker tracker) {
this.tracker = tracker;
}
- public List> syncConfigs(boolean isLocal) {
+ public List syncConfigs() {
final Map configData = tracker.configSets().get(ModConfig.Type.SERVER).stream().collect(Collectors.toMap(ModConfig::getFileName, mc -> {
try {
return Files.readAllBytes(mc.getFullPath());
@@ -32,12 +35,15 @@ public List> syncC
throw new RuntimeException(e);
}
}));
- return configData.entrySet().stream().map(e -> new MessageFunctions.LoginPacket<>("Config " + e.getKey(), new HandshakeMessages.S2CConfigData(e.getKey(), e.getValue()))).toList();
+
+ return configData.entrySet().stream()
+ .map(e -> new ConfigFilePayload(e.getValue(), e.getKey()))
+ .toList();
}
- public void receiveSyncedConfig(final HandshakeMessages.S2CConfigData s2CConfigData, final NetworkEvent.Context contextSupplier) {
+ public void receiveSyncedConfig(final byte[] contents, final String fileName) {
if (!Minecraft.getInstance().isLocalServer()) {
- Optional.ofNullable(tracker.fileMap().get(s2CConfigData.getFileName())).ifPresent(mc -> mc.acceptSyncedConfig(s2CConfigData.getBytes()));
+ Optional.ofNullable(tracker.fileMap().get(fileName)).ifPresent(mc -> mc.acceptSyncedConfig(contents));
}
}
}
diff --git a/src/main/java/net/neoforged/neoforge/network/ConfigurationInitialization.java b/src/main/java/net/neoforged/neoforge/network/ConfigurationInitialization.java
new file mode 100644
index 0000000000..70d2ff00e3
--- /dev/null
+++ b/src/main/java/net/neoforged/neoforge/network/ConfigurationInitialization.java
@@ -0,0 +1,17 @@
+package net.neoforged.neoforge.network;
+
+import net.neoforged.bus.api.SubscribeEvent;
+import net.neoforged.fml.common.Mod;
+import net.neoforged.neoforge.network.configuration.SyncConfig;
+import net.neoforged.neoforge.network.configuration.SyncRegistries;
+import net.neoforged.neoforge.network.event.OnGameConfiguration;
+
+@Mod.EventBusSubscriber(modid = "neoforge", bus = Mod.EventBusSubscriber.Bus.MOD)
+public class ConfigurationInitialization {
+
+ @SubscribeEvent
+ public static void onGameConfiguration(OnGameConfiguration event) {
+ event.register(new SyncRegistries());
+ event.register(new SyncConfig(event.getListener()));
+ }
+}
diff --git a/src/main/java/net/neoforged/neoforge/network/DualStackUtils.java b/src/main/java/net/neoforged/neoforge/network/DualStackUtils.java
index 96b7020072..40ce89644b 100644
--- a/src/main/java/net/neoforged/neoforge/network/DualStackUtils.java
+++ b/src/main/java/net/neoforged/neoforge/network/DualStackUtils.java
@@ -82,7 +82,7 @@ public static boolean checkIPv6(final InetAddress inetAddress) {
} else {
if (shouldLogDebug) {
final String addr = inetAddress == null ? "null" : "\"" + inetAddress.getHostAddress() + "\"";
- LOGGER.debug("Unable to determine IP preferredVersion of address: " + addr);
+ LOGGER.debug("Unable to determine IP version of address: " + addr);
}
if (INITIAL_PREFER_IPv4_STACK.equalsIgnoreCase("false") && INITIAL_PREFER_IPv6_ADDRESSES.equalsIgnoreCase("true")) {
diff --git a/src/main/java/net/neoforged/neoforge/network/HandshakeMessages.java b/src/main/java/net/neoforged/neoforge/network/HandshakeMessages.java
deleted file mode 100644
index 82a8217fa4..0000000000
--- a/src/main/java/net/neoforged/neoforge/network/HandshakeMessages.java
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * Copyright (c) Forge Development LLC and contributors
- * SPDX-License-Identifier: LGPL-2.1-only
- */
-
-package net.neoforged.neoforge.network;
-
-import com.google.common.collect.Maps;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.stream.Collectors;
-import net.minecraft.core.Registry;
-import net.minecraft.network.FriendlyByteBuf;
-import net.minecraft.resources.ResourceKey;
-import net.minecraft.resources.ResourceLocation;
-import net.neoforged.fml.ModList;
-import net.neoforged.neoforge.client.gui.ModMismatchDisconnectedScreen;
-import net.neoforged.neoforge.network.simple.SimpleLoginMessage;
-import net.neoforged.neoforge.registries.DataPackRegistriesHooks;
-import net.neoforged.neoforge.registries.ForgeRegistry;
-import net.neoforged.neoforge.registries.RegistryManager;
-import net.neoforged.neoforgespi.language.IModInfo;
-import org.apache.commons.lang3.tuple.Pair;
-import org.jetbrains.annotations.Nullable;
-
-public class HandshakeMessages {
- static abstract class LoginIndexedMessage implements SimpleLoginMessage {
- private int loginIndex;
-
- public void setLoginIndex(final int loginIndex) {
- this.loginIndex = loginIndex;
- }
-
- public int getLoginIndex() {
- return loginIndex;
- }
- }
-
- /**
- * Server to client "list of mods". Always first handshake message after the data sent by S2CModData.
- */
- public static class S2CModList extends LoginIndexedMessage {
- private List mods;
- private Map channels;
- private List registries;
- private final List>> dataPackRegistries;
-
- public S2CModList() {
- this.mods = ModList.get().getMods().stream().map(IModInfo::getModId).collect(Collectors.toList());
- this.channels = NetworkRegistry.buildChannelVersions();
- this.registries = RegistryManager.getRegistryNamesForSyncToClient();
- this.dataPackRegistries = List.copyOf(DataPackRegistriesHooks.getSyncedCustomRegistries());
- }
-
- private S2CModList(List mods, Map channels, List registries, List>> dataPackRegistries) {
- this.mods = mods;
- this.channels = channels;
- this.registries = registries;
- this.dataPackRegistries = dataPackRegistries;
- }
-
- public static S2CModList decode(FriendlyByteBuf input) {
- List mods = new ArrayList<>();
- int len = input.readVarInt();
- for (int x = 0; x < len; x++)
- mods.add(input.readUtf(0x100));
-
- Map channels = new HashMap<>();
- len = input.readVarInt();
- for (int x = 0; x < len; x++)
- channels.put(input.readResourceLocation(), input.readUtf(0x100));
-
- List registries = new ArrayList<>();
- len = input.readVarInt();
- for (int x = 0; x < len; x++)
- registries.add(input.readResourceLocation());
-
- List>> dataPackRegistries = input.readCollection(ArrayList::new, buf -> ResourceKey.createRegistryKey(buf.readResourceLocation()));
- return new S2CModList(mods, channels, registries, dataPackRegistries);
- }
-
- @Override
- public void encode(FriendlyByteBuf output) {
- output.writeVarInt(mods.size());
- mods.forEach(m -> output.writeUtf(m, 0x100));
-
- output.writeVarInt(channels.size());
- channels.forEach((k, v) -> {
- output.writeResourceLocation(k);
- output.writeUtf(v, 0x100);
- });
-
- output.writeVarInt(registries.size());
- registries.forEach(output::writeResourceLocation);
-
- Set>> dataPackRegistries = DataPackRegistriesHooks.getSyncedCustomRegistries();
- output.writeCollection(dataPackRegistries, (buf, key) -> buf.writeResourceLocation(key.location()));
- }
-
- public List getModList() {
- return mods;
- }
-
- public List getRegistries() {
- return this.registries;
- }
-
- public Map getChannels() {
- return this.channels;
- }
-
- /**
- * @return list of ids of non-vanilla syncable datapack registries on the server.
- */
- public List>> getCustomDataPackRegistries() {
- return this.dataPackRegistries;
- }
- }
-
- /**
- * Prefixes S2CModList by sending additional data about the mods installed on the server to the client
- * The mod data is stored as follows: [modId -> [modName, modVersion]]
- */
- public static class S2CModData extends LoginIndexedMessage {
- private final Map> mods;
-
- public S2CModData() {
- this.mods = ModList.get().getMods().stream().collect(Collectors.toMap(IModInfo::getModId, info -> Pair.of(info.getDisplayName(), info.getVersion().toString())));
- }
-
- private S2CModData(Map> mods) {
- this.mods = mods;
- }
-
- public static S2CModData decode(FriendlyByteBuf input) {
- Map> mods = input.readMap(o -> o.readUtf(0x100), o -> Pair.of(o.readUtf(0x100), o.readUtf(0x100)));
- return new S2CModData(mods);
- }
-
- @Override
- public void encode(FriendlyByteBuf output) {
- output.writeMap(mods, (o, s) -> o.writeUtf(s, 0x100), (o, p) -> {
- o.writeUtf(p.getLeft(), 0x100);
- o.writeUtf(p.getRight(), 0x100);
- });
- }
-
- public Map> getMods() {
- return mods;
- }
- }
-
- public static class C2SModListReply extends LoginIndexedMessage {
- private List mods;
- private Map channels;
- private Map registries;
-
- public C2SModListReply() {
- this.mods = ModList.get().getMods().stream().map(IModInfo::getModId).collect(Collectors.toList());
- this.channels = NetworkRegistry.buildChannelVersions();
- this.registries = Maps.newHashMap(); //TODO: Fill with known hashes, which requires keeping a file cache
- }
-
- private C2SModListReply(List mods, Map channels, Map registries) {
- this.mods = mods;
- this.channels = channels;
- this.registries = registries;
- }
-
- public static C2SModListReply decode(FriendlyByteBuf input) {
- List mods = new ArrayList<>();
- int len = input.readVarInt();
- for (int x = 0; x < len; x++)
- mods.add(input.readUtf(0x100));
-
- Map channels = new HashMap<>();
- len = input.readVarInt();
- for (int x = 0; x < len; x++)
- channels.put(input.readResourceLocation(), input.readUtf(0x100));
-
- Map registries = new HashMap<>();
- len = input.readVarInt();
- for (int x = 0; x < len; x++)
- registries.put(input.readResourceLocation(), input.readUtf(0x100));
-
- return new C2SModListReply(mods, channels, registries);
- }
-
- @Override
- public void encode(FriendlyByteBuf output) {
- output.writeVarInt(mods.size());
- mods.forEach(m -> output.writeUtf(m, 0x100));
-
- output.writeVarInt(channels.size());
- channels.forEach((k, v) -> {
- output.writeResourceLocation(k);
- output.writeUtf(v, 0x100);
- });
-
- output.writeVarInt(registries.size());
- registries.forEach((k, v) -> {
- output.writeResourceLocation(k);
- output.writeUtf(v, 0x100);
- });
- }
-
- public List getModList() {
- return mods;
- }
-
- public Map getRegistries() {
- return this.registries;
- }
-
- public Map getChannels() {
- return this.channels;
- }
- }
-
- public static class C2SAcknowledge extends LoginIndexedMessage {
- @Override
- public void encode(FriendlyByteBuf buf) {
-
- }
-
- public static C2SAcknowledge decode(FriendlyByteBuf buf) {
- return new C2SAcknowledge();
- }
- }
-
- public static class S2CRegistry extends LoginIndexedMessage {
- private final ResourceLocation registryName;
- @Nullable
- private final ForgeRegistry.Snapshot snapshot;
-
- public S2CRegistry(final ResourceLocation name, @Nullable ForgeRegistry.Snapshot snapshot) {
- this.registryName = name;
- this.snapshot = snapshot;
- }
-
- @Override
- public void encode(final FriendlyByteBuf buffer) {
- buffer.writeResourceLocation(registryName);
- buffer.writeBoolean(hasSnapshot());
- if (hasSnapshot())
- buffer.writeBytes(snapshot.getPacketData());
- }
-
- public static S2CRegistry decode(final FriendlyByteBuf buffer) {
- ResourceLocation name = buffer.readResourceLocation();
- ForgeRegistry.Snapshot snapshot = null;
- if (buffer.readBoolean())
- snapshot = ForgeRegistry.Snapshot.read(buffer);
- return new S2CRegistry(name, snapshot);
- }
-
- public ResourceLocation getRegistryName() {
- return registryName;
- }
-
- public boolean hasSnapshot() {
- return snapshot != null;
- }
-
- @Nullable
- public ForgeRegistry.Snapshot getSnapshot() {
- return snapshot;
- }
- }
-
- public static class S2CConfigData extends LoginIndexedMessage {
- private final String fileName;
- private final byte[] fileData;
-
- public S2CConfigData(final String configFileName, final byte[] configFileData) {
- this.fileName = configFileName;
- this.fileData = configFileData;
- }
-
- @Override
- public void encode(final FriendlyByteBuf buffer) {
- buffer.writeUtf(this.fileName);
- buffer.writeByteArray(this.fileData);
- }
-
- public static S2CConfigData decode(final FriendlyByteBuf buffer) {
- return new S2CConfigData(buffer.readUtf(32767), buffer.readByteArray());
- }
-
- public String getFileName() {
- return fileName;
- }
-
- public byte[] getBytes() {
- return fileData;
- }
- }
-
- /**
- * Notifies the client of a channel mismatch on the server, so a {@link ModMismatchDisconnectedScreen} is used to notify the user of the disconnection.
- * This packet also sends the data of a channel mismatch (currently, the ids and versions of the mismatched channels) to the client for it to display the correct information in said screen.
- */
- public static class S2CChannelMismatchData extends LoginIndexedMessage {
- private final Map mismatchedChannelData;
-
- public S2CChannelMismatchData(Map mismatchedChannelData) {
- this.mismatchedChannelData = mismatchedChannelData;
- }
-
- public static S2CChannelMismatchData decode(FriendlyByteBuf input) {
- Map mismatchedMods = input.readMap(i -> new ResourceLocation(i.readUtf(0x100)), i -> i.readUtf(0x100));
-
- return new S2CChannelMismatchData(mismatchedMods);
- }
-
- public void encode(FriendlyByteBuf output) {
- output.writeMap(mismatchedChannelData, (o, r) -> o.writeUtf(r.toString(), 0x100), (o, v) -> o.writeUtf(v, 0x100));
- }
-
- public Map getMismatchedChannelData() {
- return mismatchedChannelData;
- }
- }
-}
diff --git a/src/main/java/net/neoforged/neoforge/network/NetworkInitialization.java b/src/main/java/net/neoforged/neoforge/network/NetworkInitialization.java
index ffba15f419..8796e2110b 100644
--- a/src/main/java/net/neoforged/neoforge/network/NetworkInitialization.java
+++ b/src/main/java/net/neoforged/neoforge/network/NetworkInitialization.java
@@ -5,13 +5,12 @@
package net.neoforged.neoforge.network;
-import net.minecraft.network.protocol.PacketFlow;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.internal.versions.neoforge.NeoForgeVersion;
import net.neoforged.neoforge.network.event.RegisterPacketHandlerEvent;
-import net.neoforged.neoforge.network.handlers.ClientForgeRegistryHandler;
-import net.neoforged.neoforge.network.handlers.ServerForgeRegistryHandler;
+import net.neoforged.neoforge.network.handlers.ClientPayloadHandler;
+import net.neoforged.neoforge.network.handlers.ServerPayloadHandler;
import net.neoforged.neoforge.network.payload.FrozenRegistryPayload;
import net.neoforged.neoforge.network.payload.FrozenRegistrySyncCompletePayload;
import net.neoforged.neoforge.network.payload.FrozenRegistrySyncStartPayload;
@@ -25,57 +24,29 @@ public class NetworkInitialization {
@SubscribeEvent
public static void register(final RegisterPacketHandlerEvent event) {
final IPayloadRegistrar registrar = event.registrar(NeoForgeVersion.MOD_ID)
- .versioned(buildNetworkVersion());
+ .versioned(NeoForgeVersion.getSpec())
+ .optional();
registrar
.configuration(
FrozenRegistrySyncStartPayload.ID,
FrozenRegistrySyncStartPayload::new,
- handlers -> handlers.client(ClientForgeRegistryHandler.getInstance()::handle)
+ handlers -> handlers.client(ClientPayloadHandler.getInstance()::handle)
)
.configuration(
FrozenRegistryPayload.ID,
FrozenRegistryPayload::new,
- handlers -> handlers.client(ClientForgeRegistryHandler.getInstance()::handle)
+ handlers -> handlers.client(ClientPayloadHandler.getInstance()::handle)
)
.configuration(
FrozenRegistrySyncCompletePayload.ID,
FrozenRegistrySyncCompletePayload::new,
- handlers -> handlers.client(ClientForgeRegistryHandler.getInstance()::handle)
- .server(ServerForgeRegistryHandler.getInstance()::handle)
+ handlers -> handlers.client(ClientPayloadHandler.getInstance()::handle)
+ .server(ServerPayloadHandler.getInstance()::handle)
);
}
- /**
- * Build the network version from the current forge version.
- *
- * @return The network version.
- */
- private static int buildNetworkVersion() {
- String activeVersion = NeoForgeVersion.getVersion();
- if (activeVersion.contains("-")) {
- activeVersion = activeVersion.substring(0, activeVersion.indexOf("-"));
- }
- String[] versionParts = activeVersion.split("\\.");
- int[] versionInts = new int[versionParts.length];
- for (int i = 0; i < versionParts.length; i++) {
- versionInts[i] = Integer.parseInt(versionParts[i]);
- }
-
- final int major = versionInts[0];
- final int minor = versionInts[1];
- final int patch = versionInts[2];
-
- return major << 16 | minor << 8 | patch;
- }
-/* public static SimpleChannel getHandshakeChannel() {
- SimpleChannel handshakeChannel = NetworkRegistry.ChannelBuilder.named(NetworkConstants.FML_HANDSHAKE_RESOURCE).clientAcceptedVersions(a -> true).serverAcceptedVersions(a -> true).networkProtocolVersion(() -> NetworkConstants.NETVERSION).simpleChannel();
-
- handshakeChannel.simpleLoginMessageBuilder(HandshakeMessages.S2CConfigData.class, 4, LoginNetworkDirection.LOGIN_TO_CLIENT).decoder(HandshakeMessages.S2CConfigData::decode).buildLoginPacketList(ConfigSync.INSTANCE::syncConfigs).consumerNetworkThread(HandshakeHandler.consumerFor(HandshakeHandler::handleConfigSync)).add();
-
- return handshakeChannel;
- }
-
+/*
public static SimpleChannel getPlayChannel() {
SimpleChannel playChannel = NetworkRegistry.ChannelBuilder.named(NetworkConstants.FML_PLAY_RESOURCE).clientAcceptedVersions(a -> true).serverAcceptedVersions(a -> true).networkProtocolVersion(() -> NetworkConstants.NETVERSION).simpleChannel();
diff --git a/src/main/java/net/neoforged/neoforge/network/ServerStatusPing.java b/src/main/java/net/neoforged/neoforge/network/ServerStatusPing.java
index f806d75cc7..3c6653fece 100644
--- a/src/main/java/net/neoforged/neoforge/network/ServerStatusPing.java
+++ b/src/main/java/net/neoforged/neoforge/network/ServerStatusPing.java
@@ -33,7 +33,7 @@
* "channels": [
* {
* "res": "fml:handshake",
- * "preferredVersion": "1.2.3.4",
+ * "version": "1.2.3.4",
* "required": true
* }
* ],
@@ -139,7 +139,7 @@ public ByteBuf toBuf() {
// The following techniques are used to keep the size down:
// 1. Try and group channels by ModID, this relies on the assumption that a mod "examplemod" uses a channel
// like "examplemod:network". In that case only the "path" of the ResourceLocation is written
- // 2. Avoid sending IGNORESERVERONLY in plain text, instead use a flag (if set, no preferredVersion string is sent)
+ // 2. Avoid sending IGNORESERVERONLY in plain text, instead use a flag (if set, no version string is sent)
//
// The size can be estimated as follows (assuming there are no non-mod network channels)
// bytes = 2
@@ -147,7 +147,7 @@ public ByteBuf toBuf() {
// + (mod_count * avg_channel_count_per_mod) * (avg_mod_channel_length + avg_mod_channel_version_length + 1)
// + 1
// for 600 mods with an average ModID and channel length of 20, an average channel of 1 per mod and an
- // average preferredVersion length of 5 this turns out to be 31203 bytes, which easily fits into the upper limit of
+ // average version length of 5 this turns out to be 31203 bytes, which easily fits into the upper limit of
// roughly 60000 bytes. As such it is estimated that the upper limit will never be reached.
// we still check though and potentially truncate the list
var reachedSizeLimit = false;
diff --git a/src/main/java/net/neoforged/neoforge/network/configuration/SyncConfig.java b/src/main/java/net/neoforged/neoforge/network/configuration/SyncConfig.java
new file mode 100644
index 0000000000..0ff6a6ad12
--- /dev/null
+++ b/src/main/java/net/neoforged/neoforge/network/configuration/SyncConfig.java
@@ -0,0 +1,25 @@
+package net.neoforged.neoforge.network.configuration;
+
+import net.minecraft.network.protocol.common.ServerCommonPacketListener;
+import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
+import net.minecraft.network.protocol.configuration.ServerConfigurationPacketListener;
+import net.neoforged.neoforge.network.ConfigSync;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.function.Consumer;
+
+public record SyncConfig(ServerConfigurationPacketListener listener) implements ICustomConfigurationTask {
+
+ public static Type TYPE = new Type("neoforge:sync_config");
+
+ @Override
+ public @NotNull Type type() {
+ return TYPE;
+ }
+
+ @Override
+ public void run(Consumer sender) {
+ ConfigSync.INSTANCE.syncConfigs().forEach(sender);
+ listener.finishCurrentTask(type());
+ }
+}
diff --git a/src/main/java/net/neoforged/neoforge/network/event/OnGameConfiguration.java b/src/main/java/net/neoforged/neoforge/network/event/OnGameConfiguration.java
index 9bacbefcdc..d73ca85d39 100644
--- a/src/main/java/net/neoforged/neoforge/network/event/OnGameConfiguration.java
+++ b/src/main/java/net/neoforged/neoforge/network/event/OnGameConfiguration.java
@@ -1,6 +1,6 @@
package net.neoforged.neoforge.network.event;
-import net.minecraft.server.network.ConfigurationTask;
+import net.minecraft.network.protocol.configuration.ServerConfigurationPacketListener;
import net.neoforged.bus.api.Event;
import net.neoforged.fml.event.IModBusEvent;
import net.neoforged.neoforge.network.configuration.ICustomConfigurationTask;
@@ -10,8 +10,14 @@
public class OnGameConfiguration extends Event implements IModBusEvent {
+ private final ServerConfigurationPacketListener listener;
+
private final Queue configurationTasks = new LinkedList<>();
+ public OnGameConfiguration(ServerConfigurationPacketListener listener) {
+ this.listener = listener;
+ }
+
public void register(ICustomConfigurationTask task) {
configurationTasks.add(task);
}
@@ -19,4 +25,8 @@ public void register(ICustomConfigurationTask task) {
public Queue getConfigurationTasks() {
return new LinkedList<>(configurationTasks);
}
+
+ public ServerConfigurationPacketListener getListener() {
+ return listener;
+ }
}
diff --git a/src/main/java/net/neoforged/neoforge/network/filters/VanillaPacketSplitter.java b/src/main/java/net/neoforged/neoforge/network/filters/VanillaPacketSplitter.java
index 3724295fb2..accfd3e802 100644
--- a/src/main/java/net/neoforged/neoforge/network/filters/VanillaPacketSplitter.java
+++ b/src/main/java/net/neoforged/neoforge/network/filters/VanillaPacketSplitter.java
@@ -50,7 +50,8 @@ public class VanillaPacketSplitter {
@SubscribeEvent
public static void register(final RegisterPacketHandlerEvent event) {
event.registrar(NeoForgeVersion.MOD_ID)
- .versioned(versioning -> versioning.withVersion(VERSION).optional())
+ .versioned(NeoForgeVersion.getSpec())
+ .optional()
.common(
SplitPacketPayload.ID,
SplitPacketPayload::new,
diff --git a/src/main/java/net/neoforged/neoforge/network/handlers/ClientForgeRegistryHandler.java b/src/main/java/net/neoforged/neoforge/network/handlers/ClientPayloadHandler.java
similarity index 65%
rename from src/main/java/net/neoforged/neoforge/network/handlers/ClientForgeRegistryHandler.java
rename to src/main/java/net/neoforged/neoforge/network/handlers/ClientPayloadHandler.java
index d14e115334..6abadc6a5b 100644
--- a/src/main/java/net/neoforged/neoforge/network/handlers/ClientForgeRegistryHandler.java
+++ b/src/main/java/net/neoforged/neoforge/network/handlers/ClientPayloadHandler.java
@@ -2,8 +2,11 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
+import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
+import net.neoforged.neoforge.network.ConfigSync;
import net.neoforged.neoforge.network.handling.ConfigurationPayloadContext;
+import net.neoforged.neoforge.network.payload.ConfigFilePayload;
import net.neoforged.neoforge.network.payload.FrozenRegistryPayload;
import net.neoforged.neoforge.network.payload.FrozenRegistrySyncCompletePayload;
import net.neoforged.neoforge.network.payload.FrozenRegistrySyncStartPayload;
@@ -12,41 +15,48 @@
import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
-public class ClientForgeRegistryHandler {
+public class ClientPayloadHandler {
- private static final ClientForgeRegistryHandler INSTANCE = new ClientForgeRegistryHandler();
+ private static final ClientPayloadHandler INSTANCE = new ClientPayloadHandler();
- public static ClientForgeRegistryHandler getInstance() {
+ public static ClientPayloadHandler getInstance() {
return INSTANCE;
}
private final Set toSynchronize = Sets.newHashSet();
private final Map synchronizedRegistries = Maps.newHashMap();
- private boolean isSynchronizing = false;
- private ClientForgeRegistryHandler() {}
+ private ClientPayloadHandler() {}
public void handle(ConfigurationPayloadContext context, FrozenRegistryPayload payload) {
synchronizedRegistries.put(payload.registryName(), payload.snapshot());
+ toSynchronize.remove(payload.registryName());
}
public void handle(ConfigurationPayloadContext context, FrozenRegistrySyncStartPayload payload) {
- this.isSynchronizing = true;
-
this.toSynchronize.addAll(payload.toAccess());
this.synchronizedRegistries.clear();
}
public void handle(ConfigurationPayloadContext context, FrozenRegistrySyncCompletePayload payload) {
+ if (!this.toSynchronize.isEmpty()) {
+ context.packetHandler().disconnect(Component.translatable("neoforge.registries.sync.failed", this.toSynchronize.stream().map(Object::toString).collect(Collectors.joining(", "))));
+ return;
+ }
+
//This method normally returns missing entries, but we just accept what the server send us and ignore the rest.
GameData.injectSnapshot(synchronizedRegistries, false, false);
this.toSynchronize.clear();
this.synchronizedRegistries.clear();
- this.isSynchronizing = false;
context.handler().send(new FrozenRegistrySyncCompletePayload());
}
+
+ public void handle(ConfigurationPayloadContext context, ConfigFilePayload payload) {
+ ConfigSync.INSTANCE.receiveSyncedConfig(payload.contents(), payload.fileName());
+ }
}
diff --git a/src/main/java/net/neoforged/neoforge/network/handlers/ServerForgeRegistryHandler.java b/src/main/java/net/neoforged/neoforge/network/handlers/ServerPayloadHandler.java
similarity index 68%
rename from src/main/java/net/neoforged/neoforge/network/handlers/ServerForgeRegistryHandler.java
rename to src/main/java/net/neoforged/neoforge/network/handlers/ServerPayloadHandler.java
index d31e923fd3..6abb94ef94 100644
--- a/src/main/java/net/neoforged/neoforge/network/handlers/ServerForgeRegistryHandler.java
+++ b/src/main/java/net/neoforged/neoforge/network/handlers/ServerPayloadHandler.java
@@ -4,15 +4,15 @@
import net.neoforged.neoforge.network.handling.ConfigurationPayloadContext;
import net.neoforged.neoforge.network.payload.FrozenRegistrySyncCompletePayload;
-public class ServerForgeRegistryHandler {
+public class ServerPayloadHandler {
- private static final ServerForgeRegistryHandler INSTANCE = new ServerForgeRegistryHandler();
+ private static final ServerPayloadHandler INSTANCE = new ServerPayloadHandler();
- public static ServerForgeRegistryHandler getInstance() {
+ public static ServerPayloadHandler getInstance() {
return INSTANCE;
}
- private ServerForgeRegistryHandler() {
+ private ServerPayloadHandler() {
}
public void handle(ConfigurationPayloadContext context, FrozenRegistrySyncCompletePayload payload) {
diff --git a/src/main/java/net/neoforged/neoforge/network/handling/ConfigurationPayloadContext.java b/src/main/java/net/neoforged/neoforge/network/handling/ConfigurationPayloadContext.java
index 007ffb4b37..f4179f4214 100644
--- a/src/main/java/net/neoforged/neoforge/network/handling/ConfigurationPayloadContext.java
+++ b/src/main/java/net/neoforged/neoforge/network/handling/ConfigurationPayloadContext.java
@@ -7,7 +7,6 @@
import java.util.OptionalInt;
public record ConfigurationPayloadContext(
- OptionalInt version,
IReplyHandler handler,
IPacketHandler packetHandler,
ITaskCompletedHandler taskCompletedHandler,
diff --git a/src/main/java/net/neoforged/neoforge/network/handling/IConfigurationPayloadHandler.java b/src/main/java/net/neoforged/neoforge/network/handling/IConfigurationPayloadHandler.java
index 16e0b45980..333883aad5 100644
--- a/src/main/java/net/neoforged/neoforge/network/handling/IConfigurationPayloadHandler.java
+++ b/src/main/java/net/neoforged/neoforge/network/handling/IConfigurationPayloadHandler.java
@@ -8,7 +8,6 @@
* @param The type of payload.
*/
@FunctionalInterface
-
public interface IConfigurationPayloadHandler {
/**
diff --git a/src/main/java/net/neoforged/neoforge/network/handling/IPacketHandler.java b/src/main/java/net/neoforged/neoforge/network/handling/IPacketHandler.java
index 59a75f5953..1444352d0f 100644
--- a/src/main/java/net/neoforged/neoforge/network/handling/IPacketHandler.java
+++ b/src/main/java/net/neoforged/neoforge/network/handling/IPacketHandler.java
@@ -1,12 +1,12 @@
package net.neoforged.neoforge.network.handling;
+import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;
/**
* Describes a handler for a packet.
* Allows for the handling of full packets from custom payloads
*/
-@FunctionalInterface
public interface IPacketHandler {
/**
@@ -15,4 +15,11 @@ public interface IPacketHandler {
* @param packet The packet.
*/
void handle(Packet> packet);
+
+ /**
+ * Trigger a disconnect from the network.
+ *
+ * @param reason The reason for the disconnect.
+ */
+ void disconnect(Component reason);
}
diff --git a/src/main/java/net/neoforged/neoforge/network/handling/IPayloadContext.java b/src/main/java/net/neoforged/neoforge/network/handling/IPayloadContext.java
index 7ab6557fcf..5c99128294 100644
--- a/src/main/java/net/neoforged/neoforge/network/handling/IPayloadContext.java
+++ b/src/main/java/net/neoforged/neoforge/network/handling/IPayloadContext.java
@@ -8,8 +8,6 @@
import java.util.OptionalInt;
public interface IPayloadContext {
- OptionalInt version();
-
IReplyHandler handler();
IPacketHandler packetHandler();
diff --git a/src/main/java/net/neoforged/neoforge/network/handling/PlayPayloadContext.java b/src/main/java/net/neoforged/neoforge/network/handling/PlayPayloadContext.java
index 2ec634c56b..f0ef96ba82 100644
--- a/src/main/java/net/neoforged/neoforge/network/handling/PlayPayloadContext.java
+++ b/src/main/java/net/neoforged/neoforge/network/handling/PlayPayloadContext.java
@@ -4,10 +4,10 @@
import net.minecraft.network.ConnectionProtocol;
import net.minecraft.network.protocol.PacketFlow;
+import java.util.Optional;
import java.util.OptionalInt;
public record PlayPayloadContext(
- OptionalInt version,
IReplyHandler handler,
IPacketHandler packetHandler,
ISynchronizedWorkHandler workHandler,
diff --git a/src/main/java/net/neoforged/neoforge/network/negotiation/NegotiableNetworkComponent.java b/src/main/java/net/neoforged/neoforge/network/negotiation/NegotiableNetworkComponent.java
index 4a4a9efcef..fad09eab3a 100644
--- a/src/main/java/net/neoforged/neoforge/network/negotiation/NegotiableNetworkComponent.java
+++ b/src/main/java/net/neoforged/neoforge/network/negotiation/NegotiableNetworkComponent.java
@@ -9,57 +9,8 @@
public record NegotiableNetworkComponent(
ResourceLocation id,
- OptionalInt preferredVersion,
- OptionalInt minVersion,
- OptionalInt maxVersion,
+ Optional version,
Optional flow,
boolean optional
) {
-
- /**
- * Builds the version range for this component.
- *
- * If no version range and no preferred version is specified, then an empty optional is returned.
- * If no version range is specified, but a preferred version is, then a range with the preferred version as min and max is returned.
- * If a min version is specified, but no max version is, then a range with the min version as min and:
- *
- * - If a preferred version is specified, then the preferred version is used as max
- * - If no preferred version is specified, then the min version is used as max
- *
- * is returned.
- * If a max version is specified, but no min version is, then a range with the max version as max and:
- *
- * - If a preferred version is specified, then the preferred version is used as min
- * - If no preferred version is specified, then the max version is used as min
- *
- * is returned.
- * If both a min and max version is specified, then a range with the min version as min and the max version as max is returned.
- *
- * @return The potential version range for this component.
- */
- public Optional> buildVersionRange() {
- if (minVersion().isEmpty() && maxVersion().isEmpty() && preferredVersion().isEmpty()) return Optional.empty();
-
- if (minVersion().isEmpty() && maxVersion().isEmpty()) {
- return Optional.of(new Range<>(Integer.class, preferredVersion().getAsInt(), preferredVersion().getAsInt()));
- }
-
- if (minVersion().isEmpty()) {
- if (preferredVersion().isPresent()) {
- return Optional.of(new Range<>(Integer.class, preferredVersion().getAsInt(), maxVersion().getAsInt()));
- }
-
- return Optional.of(new Range<>(Integer.class, maxVersion().getAsInt(), maxVersion().getAsInt()));
- }
-
- if (maxVersion().isEmpty()) {
- if (preferredVersion().isPresent()) {
- return Optional.of(new Range<>(Integer.class, minVersion().getAsInt(), preferredVersion().getAsInt()));
- }
-
- return Optional.of(new Range<>(Integer.class, minVersion().getAsInt(), minVersion().getAsInt()));
- }
-
- return Optional.of(new Range<>(Integer.class, minVersion().getAsInt(), maxVersion().getAsInt()));
- }
}
diff --git a/src/main/java/net/neoforged/neoforge/network/negotiation/NegotiatedNetworkComponent.java b/src/main/java/net/neoforged/neoforge/network/negotiation/NegotiatedNetworkComponent.java
index c75739e783..6f742d1075 100644
--- a/src/main/java/net/neoforged/neoforge/network/negotiation/NegotiatedNetworkComponent.java
+++ b/src/main/java/net/neoforged/neoforge/network/negotiation/NegotiatedNetworkComponent.java
@@ -2,10 +2,11 @@
import net.minecraft.resources.ResourceLocation;
+import java.util.Optional;
import java.util.OptionalInt;
public record NegotiatedNetworkComponent(
ResourceLocation id,
- OptionalInt version
+ Optional version
) {
}
diff --git a/src/main/java/net/neoforged/neoforge/network/negotiation/NetworkComponentNegotiator.java b/src/main/java/net/neoforged/neoforge/network/negotiation/NetworkComponentNegotiator.java
index 6b512592a2..af2145c2e6 100644
--- a/src/main/java/net/neoforged/neoforge/network/negotiation/NetworkComponentNegotiator.java
+++ b/src/main/java/net/neoforged/neoforge/network/negotiation/NetworkComponentNegotiator.java
@@ -5,13 +5,14 @@
import com.google.common.collect.Table;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
-import net.neoforged.neoforge.common.util.Range;
import org.apache.commons.compress.utils.Lists;
-import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.VisibleForTesting;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
/**
* Negotiates the network components between the server and client.
@@ -30,18 +31,9 @@ public class NetworkComponentNegotiator {
* For each of the matching channels the following is executed:
*
* - Check if packet flow directions are set, and if at least one is set match it to the other, by missing or wrong value fail the negotiation.
- * - If one side has no version range provided, but has a preferred version, then it is checked against the other sides range. If the check fails then it fail.
- * - If one side has a range, but the other has no version, then negotiation fails.
- * - If one side has a preferred version, but no range, then the preferred version is interpreted as the sole acceptable range.
- * - Check if the version ranges overlap, if this is not the case, then return.
- *
- * At this point the channels are considered compatible, and a version is to be selected:
- *
- * - If the server has a preferred version, and that version is part of the agreed upon range, then that version is selected
- * - If the client has a preferred version, and that version is part of the agreed upon range, then that version is selected
- * - If neither the server, nor the client, has a preferred version, and a agreed upon range exists, the highest version is picked.
- * - If neither the server nor the client has a preferred version, and no agreed upon range exists, then no version is selected.
+ * - Check if both sides have the same version, or none set.
*
+ * At this point the channels are considered compatible, pick the servers version. It does not matter what side is picked since either both have the same version, or no version at all.
*
*
*
@@ -116,30 +108,8 @@ public static NegotiationResult negotiate(List serve
continue;
}
- Optional> serverRange = serverComponent.buildVersionRange();
- Optional> clientRange = clientComponent.buildVersionRange();
- OptionalInt version;
- if (serverRange.isEmpty() && clientRange.isEmpty()) {
- //No range available, means also no preferred version available.
- version = OptionalInt.empty();
- } else if (serverRange.isEmpty()) {
- //Should have produced a failure reason above, so this should not happen.
- throw new IllegalStateException("Server range is empty, but client range is not empty. This should not happen.");
- } else if (clientRange.isEmpty()) {
- //Should have produced a failure reason above, so this should not happen.
- throw new IllegalStateException("Client range is empty, but server range is not empty. This should not happen.");
- } else {
- final Range overlap = serverRange.get().overlap(clientRange.get());
- if (serverComponent.preferredVersion().isPresent() && overlap.contains(serverComponent.preferredVersion().getAsInt())) {
- version = serverComponent.preferredVersion();
- } else if (clientComponent.preferredVersion().isPresent() && overlap.contains(clientComponent.preferredVersion().getAsInt())) {
- version = clientComponent.preferredVersion();
- } else {
- version = OptionalInt.of(overlap.max());
- }
- }
-
- result.add(new NegotiatedNetworkComponent(serverComponent.id(), version));
+ //We can take the servers version here. Either both sides have the same version, or both sides have no version.
+ result.add(new NegotiatedNetworkComponent(serverComponent.id(), serverComponent.version()));
}
if (!failureReasons.isEmpty()) {
@@ -154,11 +124,7 @@ public static NegotiationResult negotiate(List serve
* The following rules are followed:
*
* - Check if packet flow directions are set, and if at least one is set match it to the other, by missing or wrong value fail the negotiation.
- * - If one side has no version range provided, but has a preferred version, then it is checked against the other sides range.
- * - If one side has a range, but the other has no version, then negotiation fails.
- * - If one side has a preferred version, but no range, then the preferred version is interpreted as the sole acceptable range.
- * - Check if the version ranges overlap, if this is not the case, then return.
- * - If no side has a preferred version, or a range, then the check succeeds.
+ * - Check if both sides have the same version, or none set.
*
*
*
@@ -183,32 +149,16 @@ public static Optional validateComponent(NegotiableN
}
}
- Optional> leftRange = left.buildVersionRange();
- Optional> rightRange = right.buildVersionRange();
-
- //Perform a left full, right empty check.
- final Optional> leftRightCheck = checkRange(left, right, requestingSide, leftRange, rightRange);
- if (leftRightCheck.isPresent()) {
- return leftRightCheck.get();
- }
-
- //Perform a left empty, right full check.
- final Optional> rightLeftCheck = checkRange(right, left, requestingSide, rightRange, leftRange);
- if (rightLeftCheck.isPresent()) {
- return rightLeftCheck.get();
+ //If either side has no version set, fail
+ if (left.version().isEmpty() && right.version().isPresent()) {
+ return Optional.of(new ComponentNegotiationResult(false, Component.translatable("neoforge.network.negotiation.failure.version.%s.required".formatted(requestingSide), left.id(), right.version().get())));
}
- //At this point both sides have a range, and both ranges are not empty.
- if (leftRange.isPresent() && rightRange.isPresent()) {
- //Check if the ranges overlap
- //This also performs the check if two channels only have a preferred version, and no range. In that case the ranges have equal min and max values, and they need to line up.
- if (leftRange.get().overlaps(rightRange.get())) {
- //Okay some overlap found so there is a common version that we can support.
- return Optional.empty();
+ //Check if both sides have the same version, or none set.
+ if (left.version().isPresent() && right.version().isPresent()) {
+ if (!left.version().get().equals(right.version().get())) {
+ return Optional.of(new ComponentNegotiationResult(false, Component.translatable("neoforge.network.negotiation.failure.version.mismatch", left.id(), left.version().get(), right.version().get())));
}
-
- //No overlap found, so negotiation fails.
- return Optional.of(new ComponentNegotiationResult(false, Component.translatable("neoforge.network.negotiation.failure.range.%s.overlap".formatted(requestingSide), left.id(), leftRange.get(), right.id(), rightRange.get())));
}
//This happens when both the ranges are empty.
@@ -216,25 +166,6 @@ public static Optional validateComponent(NegotiableN
return Optional.empty();
}
- @SuppressWarnings("OptionalUsedAsFieldOrParameterType")
- @NotNull
- private static Optional> checkRange(NegotiableNetworkComponent left, NegotiableNetworkComponent right, String requestingSide, Optional> leftRange, Optional> rightRange) {
- if (leftRange.isPresent() && rightRange.isEmpty()) {
- if (right.preferredVersion().isPresent()) {
- final Range leftActiveRange = leftRange.get();
- if (!leftActiveRange.contains(right.preferredVersion().getAsInt())) {
- return Optional.of(Optional.of(new ComponentNegotiationResult(false, Component.translatable("neoforge.network.negotiation.failure.preferredVersion.%s.out_of_range".formatted(requestingSide), left.id(), right.preferredVersion().getAsInt(), leftActiveRange))));
- }
-
- return Optional.of(Optional.empty());
- }
-
- return Optional.of(Optional.of(new ComponentNegotiationResult(false, Component.translatable("neoforge.network.negotiation.failure.preferredVersion.%s.required".formatted(requestingSide), left.id(), leftRange.get().toString()))));
- }
-
- return Optional.empty();
- }
-
public record ComponentNegotiationResult(boolean success, @Nullable Component failureReason) {
}
}
diff --git a/src/main/java/net/neoforged/neoforge/network/payload/ConfigFilePayload.java b/src/main/java/net/neoforged/neoforge/network/payload/ConfigFilePayload.java
index 6bc2238e29..47371f2573 100644
--- a/src/main/java/net/neoforged/neoforge/network/payload/ConfigFilePayload.java
+++ b/src/main/java/net/neoforged/neoforge/network/payload/ConfigFilePayload.java
@@ -3,15 +3,24 @@
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
+import org.jetbrains.annotations.NotNull;
-public record ConfigFilePayload() implements CustomPacketPayload {
- @Override
- public void write(FriendlyByteBuf p_294947_) {
+public record ConfigFilePayload(byte[] contents, String fileName) implements CustomPacketPayload {
+
+ public static final ResourceLocation ID = new ResourceLocation("neoforge", "config_file");
+ public ConfigFilePayload(FriendlyByteBuf buf) {
+ this(buf.readByteArray(), buf.readUtf());
+ }
+
+ @Override
+ public void write(FriendlyByteBuf buf) {
+ buf.writeBytes(contents);
+ buf.writeUtf(fileName);
}
@Override
- public ResourceLocation id() {
- return null;
+ public @NotNull ResourceLocation id() {
+ return ID;
}
}
diff --git a/src/main/java/net/neoforged/neoforge/network/payload/FrozenRegistryPayload.java b/src/main/java/net/neoforged/neoforge/network/payload/FrozenRegistryPayload.java
index 3826861a5e..99949a2674 100644
--- a/src/main/java/net/neoforged/neoforge/network/payload/FrozenRegistryPayload.java
+++ b/src/main/java/net/neoforged/neoforge/network/payload/FrozenRegistryPayload.java
@@ -3,14 +3,13 @@
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
-import net.neoforged.neoforge.network.reading.PayloadReadingContext;
import net.neoforged.neoforge.registries.ForgeRegistry;
public record FrozenRegistryPayload(ResourceLocation registryName, ForgeRegistry.Snapshot snapshot) implements CustomPacketPayload {
public static final ResourceLocation ID = new ResourceLocation("neoforge:frozen_registry");
- public FrozenRegistryPayload(FriendlyByteBuf buf, PayloadReadingContext context) {
+ public FrozenRegistryPayload(FriendlyByteBuf buf) {
this(buf.readResourceLocation(), ForgeRegistry.Snapshot.read(buf));
}
diff --git a/src/main/java/net/neoforged/neoforge/network/payload/FrozenRegistrySyncCompletePayload.java b/src/main/java/net/neoforged/neoforge/network/payload/FrozenRegistrySyncCompletePayload.java
index b607a052a5..b26192b6d0 100644
--- a/src/main/java/net/neoforged/neoforge/network/payload/FrozenRegistrySyncCompletePayload.java
+++ b/src/main/java/net/neoforged/neoforge/network/payload/FrozenRegistrySyncCompletePayload.java
@@ -3,14 +3,13 @@
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
-import net.neoforged.neoforge.network.reading.PayloadReadingContext;
import org.jetbrains.annotations.NotNull;
public record FrozenRegistrySyncCompletePayload() implements CustomPacketPayload {
public static final ResourceLocation ID = new ResourceLocation("neoforge:frozen_registry_sync_complete");
- public FrozenRegistrySyncCompletePayload(FriendlyByteBuf buf, PayloadReadingContext context) {
+ public FrozenRegistrySyncCompletePayload(FriendlyByteBuf buf) {
this();
}
diff --git a/src/main/java/net/neoforged/neoforge/network/payload/FrozenRegistrySyncStartPayload.java b/src/main/java/net/neoforged/neoforge/network/payload/FrozenRegistrySyncStartPayload.java
index eabd59fa0f..8fa32c06f4 100644
--- a/src/main/java/net/neoforged/neoforge/network/payload/FrozenRegistrySyncStartPayload.java
+++ b/src/main/java/net/neoforged/neoforge/network/payload/FrozenRegistrySyncStartPayload.java
@@ -3,7 +3,6 @@
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
-import net.neoforged.neoforge.network.reading.PayloadReadingContext;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
@@ -12,7 +11,7 @@ public record FrozenRegistrySyncStartPayload(Set toAccess) imp
public static final ResourceLocation ID = new ResourceLocation("neoforge:frozen_registry_sync_start");
- public FrozenRegistrySyncStartPayload(FriendlyByteBuf buf, PayloadReadingContext context) {
+ public FrozenRegistrySyncStartPayload(FriendlyByteBuf buf) {
this(buf.readSet(FriendlyByteBuf::readResourceLocation));
}
diff --git a/src/main/java/net/neoforged/neoforge/network/payload/ModdedNetworkComponent.java b/src/main/java/net/neoforged/neoforge/network/payload/ModdedNetworkComponent.java
index 43486f317d..7f23665a91 100644
--- a/src/main/java/net/neoforged/neoforge/network/payload/ModdedNetworkComponent.java
+++ b/src/main/java/net/neoforged/neoforge/network/payload/ModdedNetworkComponent.java
@@ -3,17 +3,18 @@
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
+import java.util.Optional;
import java.util.OptionalInt;
-public record ModdedNetworkComponent(ResourceLocation id, OptionalInt version) {
+public record ModdedNetworkComponent(ResourceLocation id, Optional version) {
public ModdedNetworkComponent(FriendlyByteBuf buf) {
- this(buf.readResourceLocation(), buf.readOptionalInt());
+ this(buf.readResourceLocation(), buf.readOptional(FriendlyByteBuf::readUtf));
}
public void write(FriendlyByteBuf buf) {
buf.writeResourceLocation(id);
- buf.writeOptionalInt(version);
+ buf.writeOptional(version, FriendlyByteBuf::writeUtf);
}
}
diff --git a/src/main/java/net/neoforged/neoforge/network/payload/ModdedNetworkQueryComponent.java b/src/main/java/net/neoforged/neoforge/network/payload/ModdedNetworkQueryComponent.java
index 6ccc195d57..54febc9db9 100644
--- a/src/main/java/net/neoforged/neoforge/network/payload/ModdedNetworkQueryComponent.java
+++ b/src/main/java/net/neoforged/neoforge/network/payload/ModdedNetworkQueryComponent.java
@@ -7,14 +7,12 @@
import java.util.Optional;
import java.util.OptionalInt;
-public record ModdedNetworkQueryComponent(ResourceLocation id, OptionalInt version, OptionalInt max, OptionalInt min, Optional flow, boolean optional) {
+public record ModdedNetworkQueryComponent(ResourceLocation id, Optional version, Optional flow, boolean optional) {
public ModdedNetworkQueryComponent(FriendlyByteBuf buf) {
this(
buf.readResourceLocation(),
- buf.readOptionalInt(),
- buf.readOptionalInt(),
- buf.readOptionalInt(),
+ buf.readOptional(FriendlyByteBuf::readUtf),
buf.readOptional(buffer -> buffer.readEnum(PacketFlow.class)),
buf.readBoolean()
);
@@ -22,9 +20,7 @@ public ModdedNetworkQueryComponent(FriendlyByteBuf buf) {
public void write(FriendlyByteBuf buf) {
buf.writeResourceLocation(id);
- buf.writeOptionalInt(version);
- buf.writeOptionalInt(max);
- buf.writeOptionalInt(min);
+ buf.writeOptional(version, FriendlyByteBuf::writeUtf);
buf.writeOptional(flow, FriendlyByteBuf::writeEnum);
buf.writeBoolean(optional);
}
diff --git a/src/main/java/net/neoforged/neoforge/network/payload/SplitPacketPayload.java b/src/main/java/net/neoforged/neoforge/network/payload/SplitPacketPayload.java
index 4dc530d0ac..6364e283e4 100644
--- a/src/main/java/net/neoforged/neoforge/network/payload/SplitPacketPayload.java
+++ b/src/main/java/net/neoforged/neoforge/network/payload/SplitPacketPayload.java
@@ -3,13 +3,12 @@
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
-import net.neoforged.neoforge.network.reading.PayloadReadingContext;
public record SplitPacketPayload(byte[] payload) implements CustomPacketPayload {
public static final ResourceLocation ID = new ResourceLocation("neoforge", "split");
- public SplitPacketPayload(FriendlyByteBuf buf, PayloadReadingContext context) {
+ public SplitPacketPayload(FriendlyByteBuf buf) {
this(buf.readBytes(buf.readVarInt()).array());
}
diff --git a/src/main/java/net/neoforged/neoforge/network/reading/IPayloadReader.java b/src/main/java/net/neoforged/neoforge/network/reading/IPayloadReader.java
deleted file mode 100644
index 9c5f9985dc..0000000000
--- a/src/main/java/net/neoforged/neoforge/network/reading/IPayloadReader.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package net.neoforged.neoforge.network.reading;
-
-import net.minecraft.network.FriendlyByteBuf;
-import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
-
-/**
- * A functional interface for reading a payload from a buffer
- *
- * @param The type of payload this reader can read
- */
-@FunctionalInterface
-public interface IPayloadReader {
-
- /**
- * Parses the packet specified by this reader from the buffer.
- *
- * Of importance to the implementation of this method is that it needs to be thread safe.
- * The callers of this method give no guarantee that it is invoked from the main thread of the game.
- * This means that any access to the game state needs to be done in a thread safe manner.
- * In practice this means that this method should basically never touch anything other then the parameters given to it!
- *
- *
- * @param buffer The buffer to read from
- * @param context The context of the packet
- * @return The payload
- */
- T readPayload(FriendlyByteBuf buffer, PayloadReadingContext context);
-}
diff --git a/src/main/java/net/neoforged/neoforge/network/reading/PayloadReadingContext.java b/src/main/java/net/neoforged/neoforge/network/reading/PayloadReadingContext.java
deleted file mode 100644
index 245f4b8930..0000000000
--- a/src/main/java/net/neoforged/neoforge/network/reading/PayloadReadingContext.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package net.neoforged.neoforge.network.reading;
-
-import net.minecraft.resources.ResourceLocation;
-
-import java.util.OptionalInt;
-
-public record PayloadReadingContext(
- ResourceLocation id,
- OptionalInt version
-) {
-}
diff --git a/src/main/java/net/neoforged/neoforge/network/registration/ModdedConfigurationPayloadRegistration.java b/src/main/java/net/neoforged/neoforge/network/registration/ModdedConfigurationPayloadRegistration.java
deleted file mode 100644
index 82d56be438..0000000000
--- a/src/main/java/net/neoforged/neoforge/network/registration/ModdedConfigurationPayloadRegistration.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package net.neoforged.neoforge.network.registration;
-
-import net.minecraft.network.FriendlyByteBuf;
-import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
-import net.minecraft.resources.ResourceLocation;
-import net.neoforged.neoforge.network.handling.IConfigurationPayloadHandler;
-
-/**
- * Registration for a custom packet payload.
- * This type holds the negotiated preferredVersion of the payload to use, and the handler for it.
- *
- * @param The type of payload.
- */
-public record ModdedConfigurationPayloadRegistration(
- ResourceLocation id,
- Class type,
- IConfigurationPayloadHandler handler,
- FriendlyByteBuf.Reader reader
-) {
-}
diff --git a/src/main/java/net/neoforged/neoforge/network/registration/ModdedPlayPayloadRegistration.java b/src/main/java/net/neoforged/neoforge/network/registration/ModdedPlayPayloadRegistration.java
deleted file mode 100644
index 6c3e698e19..0000000000
--- a/src/main/java/net/neoforged/neoforge/network/registration/ModdedPlayPayloadRegistration.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package net.neoforged.neoforge.network.registration;
-
-import net.minecraft.network.FriendlyByteBuf;
-import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
-import net.minecraft.resources.ResourceLocation;
-import net.neoforged.neoforge.network.handling.IPlayPayloadHandler;
-
-/**
- * Registration for a custom packet payload.
- * This type holds the negotiated preferredVersion of the payload to use, and the handler for it.
- *
- * @param The type of payload.
- */
-public record ModdedPlayPayloadRegistration(
- ResourceLocation id,
- Class type,
- IPlayPayloadHandler handler,
- FriendlyByteBuf.Reader reader
-) {
-}
diff --git a/src/main/java/net/neoforged/neoforge/network/registration/NetworkChannel.java b/src/main/java/net/neoforged/neoforge/network/registration/NetworkChannel.java
index 0c672e1160..4a867df731 100644
--- a/src/main/java/net/neoforged/neoforge/network/registration/NetworkChannel.java
+++ b/src/main/java/net/neoforged/neoforge/network/registration/NetworkChannel.java
@@ -2,10 +2,11 @@
import net.minecraft.resources.ResourceLocation;
+import java.util.Optional;
import java.util.OptionalInt;
public record NetworkChannel(
ResourceLocation id,
- OptionalInt chosenVersion
+ Optional chosenVersion
) {
}
diff --git a/src/main/java/net/neoforged/neoforge/network/registration/NetworkRegistry.java b/src/main/java/net/neoforged/neoforge/network/registration/NetworkRegistry.java
index 10cbf72787..d73f4c4b93 100644
--- a/src/main/java/net/neoforged/neoforge/network/registration/NetworkRegistry.java
+++ b/src/main/java/net/neoforged/neoforge/network/registration/NetworkRegistry.java
@@ -24,10 +24,8 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.network.ServerConfigurationPacketListenerImpl;
import net.minecraft.util.thread.ReentrantBlockableEventLoop;
-import net.neoforged.fml.ModLoader;
import net.neoforged.fml.config.ConfigTracker;
import net.neoforged.neoforge.common.NeoForge;
-import net.neoforged.neoforge.common.NeoForgeMod;
import net.neoforged.neoforge.internal.versions.neoforge.NeoForgeVersion;
import net.neoforged.neoforge.network.connection.ConnectionUtils;
import net.neoforged.neoforge.network.event.RegisterPacketHandlerEvent;
@@ -40,7 +38,6 @@
import net.neoforged.neoforge.network.negotiation.NegotiationResult;
import net.neoforged.neoforge.network.negotiation.NetworkComponentNegotiator;
import net.neoforged.neoforge.network.payload.*;
-import net.neoforged.neoforge.network.reading.PayloadReadingContext;
import net.neoforged.neoforge.network.registration.registrar.ConfigurationRegistration;
import net.neoforged.neoforge.network.registration.registrar.PlayRegistration;
import org.jetbrains.annotations.ApiStatus;
@@ -205,12 +202,7 @@ public FriendlyByteBuf.Reader extends CustomPacketPayload> getReader(ResourceL
}
}
- final PayloadReadingContext readingContext = new PayloadReadingContext(
- channel.id(),
- channel.chosenVersion()
- );
-
- return buf -> registration.readPayload(buf, readingContext);
+ return registration;
} else if (protocol.isConfiguration()) {
final NetworkChannel channel = payloadSetup.configuration().stream()
.filter(entry -> entry.id().equals(id))
@@ -244,13 +236,8 @@ public FriendlyByteBuf.Reader extends CustomPacketPayload> getReader(ResourceL
}
}
}
-
- final PayloadReadingContext readingContext = new PayloadReadingContext(
- channel.id(),
- channel.chosenVersion()
- );
-
- return buf -> registration.readPayload(buf, readingContext);
+
+ return registration;
} else {
//Error case, somebody is trying to send a custom packet during a phase that is not supported.
LOGGER.error("Received a modded custom payload packet from a client that is not in the configuration or play phase. Not parsing packet.");
@@ -308,7 +295,6 @@ public void onModdedPacketAtServer(ServerCommonPacketListener listener, Serverbo
registration.handle(
new ConfigurationPayloadContext(
- channel.chosenVersion(),
configurationPacketListener::send,
new ServerPacketHandler(configurationPacketListener),
configurationPacketListener::finishCurrentTask,
@@ -341,7 +327,6 @@ public void onModdedPacketAtServer(ServerCommonPacketListener listener, Serverbo
registration.handle(
new PlayPayloadContext(
- channel.chosenVersion(),
playPacketListener::send,
new ServerPacketHandler(playPacketListener),
new EventLoopSynchronizedWorkHandler(playPacketListener.getMainThreadEventLoop()),
@@ -406,7 +391,6 @@ public void onModdedPacketAtClient(ClientCommonPacketListener listener, Clientbo
registration.handle(
new ConfigurationPayloadContext(
- channel.chosenVersion(),
configurationPacketListener::send,
new ClientPacketHandler(configurationPacketListener),
(task) -> {
@@ -441,7 +425,6 @@ public void onModdedPacketAtClient(ClientCommonPacketListener listener, Clientbo
registration.handle(
new PlayPayloadContext(
- channel.chosenVersion(),
playPacketListener::send,
new ClientPacketHandler(playPacketListener),
new EventLoopSynchronizedWorkHandler(playPacketListener.getMainThreadEventLoop()),
@@ -480,10 +463,10 @@ public void onModdedPacketAtClient(ClientCommonPacketListener listener, Clientbo
public void onModdedConnectionDetectedAtServer(ServerConfigurationPacketListener sender, Set configuration, Set play) {
final NegotiationResult configurationNegotiationResult = NetworkComponentNegotiator.negotiate(
knownConfigurationRegistrations.entrySet().stream()
- .map(entry -> new NegotiableNetworkComponent(entry.getKey(), entry.getValue().version(), entry.getValue().maxVersion(), entry.getValue().minVersion(), entry.getValue().flow(), entry.getValue().optional()))
+ .map(entry -> new NegotiableNetworkComponent(entry.getKey(), entry.getValue().version(), entry.getValue().flow(), entry.getValue().optional()))
.toList(),
configuration.stream()
- .map(entry -> new NegotiableNetworkComponent(entry.id(), entry.version(), entry.min(), entry.max(), entry.flow(), entry.optional()))
+ .map(entry -> new NegotiableNetworkComponent(entry.id(), entry.version(), entry.flow(), entry.optional()))
.toList()
);
@@ -503,10 +486,10 @@ public void onModdedConnectionDetectedAtServer(ServerConfigurationPacketListener
final NegotiationResult playNegotiationResult = NetworkComponentNegotiator.negotiate(
knownPlayRegistrations.entrySet().stream()
- .map(entry -> new NegotiableNetworkComponent(entry.getKey(), entry.getValue().version(), entry.getValue().maxVersion(), entry.getValue().minVersion(), entry.getValue().flow(), entry.getValue().optional()))
+ .map(entry -> new NegotiableNetworkComponent(entry.getKey(), entry.getValue().version(), entry.getValue().flow(), entry.getValue().optional()))
.toList(),
play.stream()
- .map(entry -> new NegotiableNetworkComponent(entry.id(), entry.version(), entry.min(), entry.max(), entry.flow(), entry.optional()))
+ .map(entry -> new NegotiableNetworkComponent(entry.id(), entry.version(), entry.flow(), entry.optional()))
.toList()
);
@@ -549,7 +532,7 @@ public boolean onVanillaConnectionDetectedAtServer(ServerConfigurationPacketList
final NegotiationResult configurationNegotiationResult = NetworkComponentNegotiator.negotiate(
knownConfigurationRegistrations.entrySet().stream()
- .map(entry -> new NegotiableNetworkComponent(entry.getKey(), entry.getValue().version(), entry.getValue().maxVersion(), entry.getValue().minVersion(), entry.getValue().flow(), entry.getValue().optional()))
+ .map(entry -> new NegotiableNetworkComponent(entry.getKey(), entry.getValue().version(), entry.getValue().flow(), entry.getValue().optional()))
.toList(),
List.of()
);
@@ -567,7 +550,7 @@ public boolean onVanillaConnectionDetectedAtServer(ServerConfigurationPacketList
final NegotiationResult playNegotiationResult = NetworkComponentNegotiator.negotiate(
knownPlayRegistrations.entrySet().stream()
- .map(entry -> new NegotiableNetworkComponent(entry.getKey(), entry.getValue().version(), entry.getValue().maxVersion(), entry.getValue().minVersion(), entry.getValue().flow(), entry.getValue().optional()))
+ .map(entry -> new NegotiableNetworkComponent(entry.getKey(), entry.getValue().version(), entry.getValue().flow(), entry.getValue().optional()))
.toList(),
List.of()
);
@@ -716,10 +699,10 @@ public boolean canSendPacket(Packet> packet, ClientCommonPacketListener listen
public void onNetworkQuery(ClientConfigurationPacketListener listener) {
final ModdedNetworkQueryPayload payload = new ModdedNetworkQueryPayload(
knownConfigurationRegistrations.entrySet().stream()
- .map(entry -> new ModdedNetworkQueryComponent(entry.getKey(), entry.getValue().version(), entry.getValue().maxVersion(), entry.getValue().minVersion(), entry.getValue().flow(), entry.getValue().optional()))
+ .map(entry -> new ModdedNetworkQueryComponent(entry.getKey(), entry.getValue().version(), entry.getValue().flow(), entry.getValue().optional()))
.collect(Collectors.toSet()),
knownPlayRegistrations.entrySet().stream()
- .map(entry -> new ModdedNetworkQueryComponent(entry.getKey(), entry.getValue().version(), entry.getValue().maxVersion(), entry.getValue().minVersion(), entry.getValue().flow(), entry.getValue().optional()))
+ .map(entry -> new ModdedNetworkQueryComponent(entry.getKey(), entry.getValue().version(), entry.getValue().flow(), entry.getValue().optional()))
.collect(Collectors.toSet())
);
@@ -775,7 +758,7 @@ public boolean onVanillaNetworkConnectionEstablished(ClientConfigurationPacketLi
final NegotiationResult configurationNegotiationResult = NetworkComponentNegotiator.negotiate(
List.of(),
knownConfigurationRegistrations.entrySet().stream()
- .map(entry -> new NegotiableNetworkComponent(entry.getKey(), entry.getValue().version(), entry.getValue().maxVersion(), entry.getValue().minVersion(), entry.getValue().flow(), entry.getValue().optional()))
+ .map(entry -> new NegotiableNetworkComponent(entry.getKey(), entry.getValue().version(), entry.getValue().flow(), entry.getValue().optional()))
.toList()
);
@@ -793,7 +776,7 @@ public boolean onVanillaNetworkConnectionEstablished(ClientConfigurationPacketLi
final NegotiationResult playNegotiationResult = NetworkComponentNegotiator.negotiate(
List.of(),
knownPlayRegistrations.entrySet().stream()
- .map(entry -> new NegotiableNetworkComponent(entry.getKey(), entry.getValue().version(), entry.getValue().maxVersion(), entry.getValue().minVersion(), entry.getValue().flow(), entry.getValue().optional()))
+ .map(entry -> new NegotiableNetworkComponent(entry.getKey(), entry.getValue().version(), entry.getValue().flow(), entry.getValue().optional()))
.toList()
);
@@ -850,7 +833,12 @@ private record ServerPacketHandler(ServerCommonPacketListener listener) implemen
@Override
public void handle(Packet> packet) {
- resolvePacketGenerics(packet, listener);
+ resolvePacketGenerics(packet, listener());
+ }
+
+ @Override
+ public void disconnect(Component reason) {
+ listener().disconnect(reason);
}
private static void resolvePacketGenerics(Packet packet, ServerCommonPacketListener listener) {
@@ -868,7 +856,12 @@ private record ClientPacketHandler(ClientCommonPacketListener listener) implemen
@Override
public void handle(Packet> packet) {
- resolvePacketGenerics(packet, listener);
+ resolvePacketGenerics(packet, listener());
+ }
+
+ @Override
+ public void disconnect(Component reason) {
+ listener().getConnection().disconnect(reason);
}
private static void resolvePacketGenerics(Packet packet, ClientCommonPacketListener listener) {
diff --git a/src/main/java/net/neoforged/neoforge/network/registration/registrar/ConfigurationRegistration.java b/src/main/java/net/neoforged/neoforge/network/registration/registrar/ConfigurationRegistration.java
index 27d74f6bb2..54df130d33 100644
--- a/src/main/java/net/neoforged/neoforge/network/registration/registrar/ConfigurationRegistration.java
+++ b/src/main/java/net/neoforged/neoforge/network/registration/registrar/ConfigurationRegistration.java
@@ -5,21 +5,17 @@
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.neoforged.neoforge.network.handling.ConfigurationPayloadContext;
import net.neoforged.neoforge.network.handling.IConfigurationPayloadHandler;
-import net.neoforged.neoforge.network.reading.IPayloadReader;
-import net.neoforged.neoforge.network.reading.PayloadReadingContext;
import java.util.Optional;
import java.util.OptionalInt;
public record ConfigurationRegistration(
- IPayloadReader reader,
+ FriendlyByteBuf.Reader reader,
IConfigurationPayloadHandler handler,
- OptionalInt version,
- OptionalInt minVersion,
- OptionalInt maxVersion,
+ Optional version,
Optional flow,
boolean optional
-) implements IConfigurationPayloadHandler, IPayloadReader {
+) implements IConfigurationPayloadHandler, FriendlyByteBuf.Reader {
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public void handle(ConfigurationPayloadContext context, CustomPacketPayload payload) {
@@ -27,7 +23,7 @@ public void handle(ConfigurationPayloadContext context, CustomPacketPayload payl
}
@Override
- public CustomPacketPayload readPayload(FriendlyByteBuf buffer, PayloadReadingContext context) {
- return reader.readPayload(buffer, context);
+ public CustomPacketPayload apply(FriendlyByteBuf buffer) {
+ return reader.apply(buffer);
}
}
diff --git a/src/main/java/net/neoforged/neoforge/network/registration/registrar/INetworkPayloadVersioningBuilder.java b/src/main/java/net/neoforged/neoforge/network/registration/registrar/INetworkPayloadVersioningBuilder.java
deleted file mode 100644
index ecbe1ad140..0000000000
--- a/src/main/java/net/neoforged/neoforge/network/registration/registrar/INetworkPayloadVersioningBuilder.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package net.neoforged.neoforge.network.registration.registrar;
-
-public interface INetworkPayloadVersioningBuilder {
-
- INetworkPayloadVersioningBuilder withVersion(int version);
-
- INetworkPayloadVersioningBuilder withMinimalVersion(int min);
-
- INetworkPayloadVersioningBuilder withMaximalVersion(int max);
-
- INetworkPayloadVersioningBuilder optional();
-
- default INetworkPayloadVersioningBuilder withAcceptableRange(int min, int max) {
- return withMinimalVersion(min).withMaximalVersion(max);
- }
-}
diff --git a/src/main/java/net/neoforged/neoforge/network/registration/registrar/IPayloadRegistrar.java b/src/main/java/net/neoforged/neoforge/network/registration/registrar/IPayloadRegistrar.java
index c7c1d3501b..3ac151c4a3 100644
--- a/src/main/java/net/neoforged/neoforge/network/registration/registrar/IPayloadRegistrar.java
+++ b/src/main/java/net/neoforged/neoforge/network/registration/registrar/IPayloadRegistrar.java
@@ -5,7 +5,6 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.network.ConfigurationTask;
import net.neoforged.neoforge.network.handling.*;
-import net.neoforged.neoforge.network.reading.IPayloadReader;
import java.util.function.Consumer;
@@ -16,12 +15,12 @@
*
*
* The payload is written to the networks outgoing buffer using the {@link CustomPacketPayload#write(FriendlyByteBuf)} method.
- * However, to read the payload from the incoming buffer, your registered {@link IPayloadReader} is used.
+ * However, to read the payload from the incoming buffer, your registered {@link FriendlyByteBuf.Reader} is used.
*
* When you implement your {@link CustomPacketPayload#write(FriendlyByteBuf)} method you do not need to write the id of the payload,
- * neither do you need to read it in your {@link IPayloadReader} implementation. However, you do need to make sure that the
- * id you pass into {@link #play(ResourceLocation, IPayloadReader, IPlayPayloadHandler)} and
- * {@link #configuration(ResourceLocation, IPayloadReader, IConfigurationPayloadHandler)} is the same as the id you
+ * neither do you need to read it in your {@link FriendlyByteBuf.Reader} implementation. However, you do need to make sure that the
+ * id you pass into {@link #play(ResourceLocation, FriendlyByteBuf.Reader, IPlayPayloadHandler)} and
+ * {@link #configuration(ResourceLocation, FriendlyByteBuf.Reader, IConfigurationPayloadHandler)} is the same as the id you
* return from your {@link CustomPacketPayload#id()}. We suggest using a public static final ResourceLocation
field
* to store it and then reference it in both places.
*
@@ -43,8 +42,8 @@
*
Play payloads: These are payloads that are sent from the client to the server, or from the server to the client, during normal gameplay.
* Configuration payloads: These are payloads that are sent from the server to the client, or from the client to the server, during the login process, before the player is spawned.
*
- * You can register a custom payload for either of these types of payloads using the {@link #play(ResourceLocation, IPayloadReader, IPlayPayloadHandler)}
- * and {@link #configuration(ResourceLocation, IPayloadReader, IConfigurationPayloadHandler)} methods respectively.
+ * You can register a custom payload for either of these types of payloads using the {@link #play(ResourceLocation, FriendlyByteBuf.Reader, IPlayPayloadHandler)}
+ * and {@link #configuration(ResourceLocation, FriendlyByteBuf.Reader, IConfigurationPayloadHandler)} methods respectively.
*
* The difference between the play and configuration phases, if you like to call them that, is that the configuration phase generally requires
* a confirmation payload to be returned to the server to trigger the next phase. In the {@link ConfigurationPayloadContext context} passed into
@@ -56,7 +55,7 @@
* Note: the processing of payloads happens solely on the network thread. You are yourself responsible for ensuring that any data you access
* in your handlers is either thread safe, or that you queue up your work to be done on the main thread, of the relevant side.
* This is particularly important for the {@link IPlayPayloadHandler} or {@link IConfigurationPayloadHandler} implementations that you pass to
- * {@link #play(ResourceLocation, IPayloadReader, IPlayPayloadHandler)} or {@link #configuration(ResourceLocation, IPayloadReader, IConfigurationPayloadHandler)}
+ * {@link #play(ResourceLocation, FriendlyByteBuf.Reader, IPlayPayloadHandler)} or {@link #configuration(ResourceLocation, FriendlyByteBuf.Reader, IConfigurationPayloadHandler)}
* respectively, since those are also invoked on the network thread.
*
* The {@link PlayPayloadContext} and {@link ConfigurationPayloadContext} given to each of these handlers contains a {@link ISynchronizedWorkHandler}
@@ -65,28 +64,7 @@
*
*/
public interface IPayloadRegistrar {
-
- /**
- * Configurers the copy of this registrar that is returned to use a specific version.
- *
- * This is a short circuit for calling {@link INetworkPayloadVersioningBuilder#withVersion(int)} in the callback passed to
- * {@link #versioned(Consumer)}.
- *
- * @param version The version to use.
- * @return A copy of this registrar with the version configured.
- */
- default IPayloadRegistrar versioned(int version) {
- return versioned(builder -> builder.withVersion(version));
- }
-
- /**
- * Configures a copy of this registrar using the given configurer with respect to versioning of the payloads registered throuh it.
- *
- * @param configurer The configurer to use.
- * @return A copy of this registrar with the versioning configured.
- */
- IPayloadRegistrar versioned(Consumer configurer);
-
+
/**
* Registers a new payload type for the play phase.
*
@@ -97,7 +75,7 @@ default IPayloadRegistrar versioned(int version) {
* @return The registrar.
* @implNote This method will capture all internal errors and wrap them in a {@link RegistrationFailedException}.
*/
- IPayloadRegistrar play(ResourceLocation id, IPayloadReader reader, IPlayPayloadHandler handler);
+ IPayloadRegistrar play(ResourceLocation id, FriendlyByteBuf.Reader reader, IPlayPayloadHandler handler);
/**
* Registers a new payload type for the play phase.
@@ -115,7 +93,7 @@ default IPayloadRegistrar versioned(int version) {
* @return The registrar.
* @implNote This method will capture all internal errors and wrap them in a {@link RegistrationFailedException}.
*/
- IPayloadRegistrar play(ResourceLocation id, IPayloadReader reader, Consumer> handler);
+ IPayloadRegistrar play(ResourceLocation id, FriendlyByteBuf.Reader reader, Consumer> handler);
/**
@@ -128,7 +106,7 @@ default IPayloadRegistrar versioned(int version) {
* @return The registrar.
* @implNote This method will capture all internal errors and wrap them in a {@link RegistrationFailedException}.
*/
- IPayloadRegistrar configuration(ResourceLocation id, IPayloadReader reader, IConfigurationPayloadHandler handler);
+ IPayloadRegistrar configuration(ResourceLocation id, FriendlyByteBuf.Reader reader, IConfigurationPayloadHandler handler);
/**
* Registers a new payload type for the configuration phase.
@@ -146,7 +124,7 @@ default IPayloadRegistrar versioned(int version) {
* @return The registrar.
* @implNote This method will capture all internal errors and wrap them in a {@link RegistrationFailedException}.
*/
- IPayloadRegistrar configuration(ResourceLocation id, IPayloadReader reader, Consumer> handler);
+ IPayloadRegistrar configuration(ResourceLocation id, FriendlyByteBuf.Reader reader, Consumer> handler);
/**
* Registers a new payload type for all supported phases.
@@ -157,7 +135,7 @@ default IPayloadRegistrar versioned(int version) {
* @param handler The handler for the payload.
* @return The registrar.
*/
- default IPayloadRegistrar common(ResourceLocation id, IPayloadReader reader, IPayloadHandler handler) {
+ default IPayloadRegistrar common(ResourceLocation id, FriendlyByteBuf.Reader reader, IPayloadHandler handler) {
return play(id, reader, handler::handle).configuration(id, reader, handler::handle);
}
@@ -176,10 +154,31 @@ default IPayloadRegistrar common(ResourceLocatio
* @param handler The handler for the payload.
* @return The registrar.
*/
- default IPayloadRegistrar common(ResourceLocation id, IPayloadReader reader, Consumer> handler) {
+ default IPayloadRegistrar common(ResourceLocation id, FriendlyByteBuf.Reader reader, Consumer> handler) {
final PayloadHandlerBuilder builder = new PayloadHandlerBuilder<>();
handler.accept(builder);
return play(id, reader, builder::handle).configuration(id, reader, builder::handle);
}
+
+ /**
+ * Defines that the payloads registered by this registrar have a specific version associated with them.
+ * Clients connecting to a server with these payloads, will only be able to connect if they have the same version.
+ *
+ * @param version The version to use.
+ * @return The registrar, ready to configure payloads with that version.
+ */
+ IPayloadRegistrar versioned(String version);
+
+ /**
+ * Defines that the payloads registered by this registrar are optional.
+ * Clients connecting to a server which do not have the payloads registered, will still be able to connect.
+ *
+ * If clients have also a version set, and a version mismatch occurs (so both client and server have the payloads registered,
+ * yet have different versions), the connection attempt will fail.
+ * In other words, marking a payload as optional does not exempt it from versioning, if it has that configured.
+ *
+ * @return The registrar, ready to configure payloads as optional.
+ */
+ IPayloadRegistrar optional();
}
diff --git a/src/main/java/net/neoforged/neoforge/network/registration/registrar/ModdedPacketRegistrar.java b/src/main/java/net/neoforged/neoforge/network/registration/registrar/ModdedPacketRegistrar.java
index e206962d23..5d30471762 100644
--- a/src/main/java/net/neoforged/neoforge/network/registration/registrar/ModdedPacketRegistrar.java
+++ b/src/main/java/net/neoforged/neoforge/network/registration/registrar/ModdedPacketRegistrar.java
@@ -2,26 +2,23 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
+import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.network.handling.IConfigurationPayloadHandler;
import net.neoforged.neoforge.network.handling.IPlayPayloadHandler;
-import net.neoforged.neoforge.network.reading.IPayloadReader;
import java.util.Map;
import java.util.Optional;
-import java.util.OptionalInt;
import java.util.function.Consumer;
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
-public class ModdedPacketRegistrar implements IPayloadRegistrar, INetworkPayloadVersioningBuilder {
+public class ModdedPacketRegistrar implements IPayloadRegistrar {
private final String modId;
private final Map> configurationPayloads;
private final Map> playPayloads;
- private OptionalInt version = OptionalInt.empty();
- private OptionalInt minimalVersion = OptionalInt.empty();
- private OptionalInt maximalVersion = OptionalInt.empty();
+ private Optional version = Optional.empty();
private boolean optional = false;
@@ -36,8 +33,6 @@ private ModdedPacketRegistrar(ModdedPacketRegistrar source) {
this.playPayloads = source.playPayloads;
this.configurationPayloads = source.configurationPayloads;
this.version = source.version;
- this.minimalVersion = source.minimalVersion;
- this.maximalVersion = source.maximalVersion;
this.optional = source.optional;
}
@@ -51,53 +46,46 @@ public Map> getPlayRegistrations() {
@Override
- public IPayloadRegistrar play(ResourceLocation id, IPayloadReader reader, IPlayPayloadHandler handler) {
+ public IPayloadRegistrar play(ResourceLocation id, FriendlyByteBuf.Reader reader, IPlayPayloadHandler handler) {
play(
id, new PlayRegistration<>(
- reader, handler, version, minimalVersion, maximalVersion, Optional.empty(), optional
+ reader, handler, version, Optional.empty(), optional
)
);
return this;
}
@Override
- public IPayloadRegistrar configuration(ResourceLocation id, IPayloadReader reader, IConfigurationPayloadHandler handler) {
+ public IPayloadRegistrar configuration(ResourceLocation id, FriendlyByteBuf.Reader reader, IConfigurationPayloadHandler handler) {
configuration(
id, new ConfigurationRegistration<>(
- reader, handler, version, minimalVersion, maximalVersion, Optional.empty(), optional
+ reader, handler, version, Optional.empty(), optional
)
);
return this;
}
@Override
- public IPayloadRegistrar versioned(Consumer configurer) {
- final ModdedPacketRegistrar copy = new ModdedPacketRegistrar(this);
- configurer.accept(copy);
- return copy;
- }
-
- @Override
- public IPayloadRegistrar play(ResourceLocation id, IPayloadReader reader, Consumer> handler) {
+ public IPayloadRegistrar play(ResourceLocation id, FriendlyByteBuf.Reader reader, Consumer> handler) {
final PlayPayloadHandler.Builder builder = new PlayPayloadHandler.Builder<>();
handler.accept(builder);
final PlayPayloadHandler innerHandler = builder.create();
play(
id, new PlayRegistration<>(
- reader, innerHandler, version, minimalVersion, maximalVersion, innerHandler.flow(), optional
+ reader, innerHandler, version, innerHandler.flow(), optional
)
);
return this;
}
@Override
- public IPayloadRegistrar configuration(ResourceLocation id, IPayloadReader reader, Consumer> handler) {
+ public IPayloadRegistrar configuration(ResourceLocation id, FriendlyByteBuf.Reader reader, Consumer> handler) {
final ConfigurationPayloadHandler.Builder builder = new ConfigurationPayloadHandler.Builder<>();
handler.accept(builder);
final ConfigurationPayloadHandler innerHandler = builder.create();
configuration(
id, new ConfigurationRegistration<>(
- reader, innerHandler, version, minimalVersion, maximalVersion, innerHandler.flow(), optional
+ reader, innerHandler, version, innerHandler.flow(), optional
)
);
return this;
@@ -126,26 +114,16 @@ private void validatePayload(ResourceLocation id, final Map
}
@Override
- public INetworkPayloadVersioningBuilder withVersion(int version) {
- this.version = OptionalInt.of(version);
- return this;
+ public IPayloadRegistrar versioned(String version) {
+ final ModdedPacketRegistrar clone = new ModdedPacketRegistrar(this);
+ clone.version = Optional.of(version);
+ return clone;
}
@Override
- public INetworkPayloadVersioningBuilder withMinimalVersion(int min) {
- this.minimalVersion = OptionalInt.of(min);
- return this;
- }
-
- @Override
- public INetworkPayloadVersioningBuilder withMaximalVersion(int max) {
- this.maximalVersion = OptionalInt.of(max);
- return this;
- }
-
- @Override
- public INetworkPayloadVersioningBuilder optional() {
- this.optional = true;
- return this;
+ public IPayloadRegistrar optional() {
+ final ModdedPacketRegistrar clone = new ModdedPacketRegistrar(this);
+ clone.optional = true;
+ return clone;
}
}
diff --git a/src/main/java/net/neoforged/neoforge/network/registration/registrar/PlayRegistration.java b/src/main/java/net/neoforged/neoforge/network/registration/registrar/PlayRegistration.java
index fe2e794c70..ce7b428702 100644
--- a/src/main/java/net/neoforged/neoforge/network/registration/registrar/PlayRegistration.java
+++ b/src/main/java/net/neoforged/neoforge/network/registration/registrar/PlayRegistration.java
@@ -5,22 +5,17 @@
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.neoforged.neoforge.network.handling.IPlayPayloadHandler;
import net.neoforged.neoforge.network.handling.PlayPayloadContext;
-import net.neoforged.neoforge.network.reading.IPayloadReader;
-import net.neoforged.neoforge.network.reading.PayloadReadingContext;
import java.util.Optional;
import java.util.OptionalInt;
public record PlayRegistration(
- IPayloadReader reader,
+ FriendlyByteBuf.Reader reader,
IPlayPayloadHandler handler,
- OptionalInt version,
- OptionalInt minVersion,
- OptionalInt maxVersion,
-
+ Optional version,
Optional flow,
boolean optional
-) implements IPlayPayloadHandler, IPayloadReader {
+) implements IPlayPayloadHandler, FriendlyByteBuf.Reader {
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public void handle(PlayPayloadContext context, CustomPacketPayload payload) {
@@ -28,7 +23,7 @@ public void handle(PlayPayloadContext context, CustomPacketPayload payload) {
}
@Override
- public CustomPacketPayload readPayload(FriendlyByteBuf buffer, PayloadReadingContext context) {
- return reader.readPayload(buffer, context);
+ public CustomPacketPayload apply(FriendlyByteBuf buffer) {
+ return reader.apply(buffer);
}
}
diff --git a/src/main/java/net/neoforged/neoforge/server/ServerLifecycleHooks.java b/src/main/java/net/neoforged/neoforge/server/ServerLifecycleHooks.java
index 02f56b0667..4fb63c13e5 100644
--- a/src/main/java/net/neoforged/neoforge/server/ServerLifecycleHooks.java
+++ b/src/main/java/net/neoforged/neoforge/server/ServerLifecycleHooks.java
@@ -50,10 +50,6 @@
import net.neoforged.neoforge.event.server.ServerStoppedEvent;
import net.neoforged.neoforge.event.server.ServerStoppingEvent;
import net.neoforged.neoforge.gametest.GameTestHooks;
-import net.neoforged.neoforge.network.ConnectionType;
-import net.neoforged.neoforge.network.NetworkConstants;
-import net.neoforged.neoforge.network.NetworkHooks;
-import net.neoforged.neoforge.network.NetworkRegistry;
import net.neoforged.neoforge.registries.ForgeRegistries;
import net.neoforged.neoforge.registries.ForgeRegistries.Keys;
import net.neoforged.neoforge.registries.GameData;
@@ -149,37 +145,9 @@ public static boolean handleServerLogin(final ClientIntentionPacket packet, fina
return false;
}
- if (packet.intention() == ClientIntent.LOGIN) {
- final ConnectionType connectionType = ConnectionType.forVersionFlag(packet.getFMLVersion());
- final int versionNumber = connectionType.getFMLVersionNumber(packet.getFMLVersion());
-
- if (connectionType == ConnectionType.MODDED && versionNumber != NetworkConstants.FMLNETVERSION) {
- rejectConnection(manager, connectionType, "This modded server is not impl compatible with your modded client. Please verify your NeoForge preferredVersion closely matches the server. Got net preferredVersion " + versionNumber + " this server is net preferredVersion " + NetworkConstants.FMLNETVERSION);
- return false;
- }
-
- if (connectionType == ConnectionType.VANILLA && !NetworkRegistry.acceptsVanillaClientConnections()) {
- rejectConnection(manager, connectionType, "This server has mods that require NeoForge to be installed on the client. Contact your server admin for more details.");
- return false;
- }
- }
-
if (packet.intention() == ClientIntent.STATUS) return true;
- NetworkHooks.registerServerLoginChannel(manager, packet);
return true;
-
- }
-
- private static void rejectConnection(final Connection manager, ConnectionType type, String message) {
- manager.setClientboundProtocolAfterHandshake(ClientIntent.LOGIN);
- String ip = "local";
- if (manager.getRemoteAddress() != null)
- ip = manager.getRemoteAddress().toString();
- LOGGER.info(SERVERHOOKS, "[{}] Disconnecting {} connection attempt: {}", ip, type, message);
- MutableComponent text = Component.literal(message);
- manager.send(new ClientboundLoginDisconnectPacket(text));
- manager.disconnect(text);
}
public static void handleExit(int retVal) {
diff --git a/src/main/java/net/neoforged/neoforge/server/command/ModListCommand.java b/src/main/java/net/neoforged/neoforge/server/command/ModListCommand.java
index 96b7696cda..49a7f5b603 100644
--- a/src/main/java/net/neoforged/neoforge/server/command/ModListCommand.java
+++ b/src/main/java/net/neoforged/neoforge/server/command/ModListCommand.java
@@ -20,7 +20,7 @@ class ModListCommand {
.executes(ctx -> {
ctx.getSource().sendSuccess(() -> Component.translatable("commands.neoforge.mods.list",
ModList.get().applyForEachModFile(modFile ->
- // locator - filename : firstmod (preferredVersion) - numberofmods\n
+ // locator - filename : firstmod (version) - numberofmods\n
String.format(Locale.ROOT, "%s %s : %s (%s) - %d",
modFile.getProvider().name().replace(' ', '_'),
modFile.getFileName(),
diff --git a/src/main/java/net/neoforged/neoforge/server/command/TextComponentHelper.java b/src/main/java/net/neoforged/neoforge/server/command/TextComponentHelper.java
index 0996778013..49444bbf3f 100644
--- a/src/main/java/net/neoforged/neoforge/server/command/TextComponentHelper.java
+++ b/src/main/java/net/neoforged/neoforge/server/command/TextComponentHelper.java
@@ -5,15 +5,15 @@
package net.neoforged.neoforge.server.command;
-import java.util.Locale;
import net.minecraft.commands.CommandSource;
import net.minecraft.locale.Language;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
-import net.neoforged.neoforge.network.ConnectionType;
-import net.neoforged.neoforge.network.NetworkHooks;
+import net.neoforged.neoforge.network.registration.NetworkRegistry;
+
+import java.util.Locale;
public class TextComponentHelper {
private TextComponentHelper() {}
@@ -30,10 +30,9 @@ public static MutableComponent createComponentTranslation(CommandSource source,
}
private static boolean isVanillaClient(CommandSource sender) {
- if (sender instanceof ServerPlayer) {
- ServerPlayer playerMP = (ServerPlayer) sender;
+ if (sender instanceof ServerPlayer playerMP) {
ServerGamePacketListenerImpl channel = playerMP.connection;
- return NetworkHooks.getConnectionType(() -> channel.connection) == ConnectionType.VANILLA;
+ return NetworkRegistry.getInstance().isVanillaConnection(channel.getConnection());
}
return false;
}
diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml
index fa535a7ac5..8323d05a40 100644
--- a/src/main/resources/META-INF/mods.toml
+++ b/src/main/resources/META-INF/mods.toml
@@ -6,7 +6,7 @@ license="LGPL v2.1"
[[mods]]
modId="neoforge"
- # We use the global NeoForge preferredVersion
+ # We use the global NeoForge version
version="${global.neoForgeVersion}"
#updateJSONURL="https://maven.neoforged.net/releases/net/neoforged/forge/promotions_slim.json"
displayName="NeoForge"