Skip to content

Commit

Permalink
Remove the version range support.
Browse files Browse the repository at this point in the history
Implement entire configuration phase.
  • Loading branch information
marchermans committed Nov 17, 2023
1 parent 708da11 commit 42166c6
Show file tree
Hide file tree
Showing 70 changed files with 366 additions and 904 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
+
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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_) {
}
Expand All @@ -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);
}
Expand All @@ -44,7 +48,7 @@
boolean flag = !this.suspendFlushingOnServerThread || !this.server.isSameThread();

try {
@@ -121,7 +125,13 @@
@@ -121,7 +126,13 @@
throw new ReportedException(crashreport);
}
}
Expand All @@ -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;
}

Expand All @@ -75,7 +79,7 @@
+ }
+
+ @Override
+ public MinecraftServer getServer() {
+ public ReentrantBlockableEventLoop<?> getMainThreadEventLoop() {
+ return server;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -43,18 +45,18 @@
this.send(new ClientboundCustomPayloadPacket(new BrandPayload(this.server.getServerModName())));
LayeredRegistryAccess<RegistryLayer> 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);
}
}
Expand Down Expand Up @@ -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);
Expand All @@ -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 @@
}
}

Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ record Row(MutableComponent name, MutableComponent reason) {
}
List<Row> 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<ResourceLocation, Component> modData : mismatchedChannelData.entrySet()) {
Expand All @@ -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
Expand All @@ -127,7 +127,7 @@ record Row(MutableComponent name, MutableComponent reason) {
private List<Pair<FormattedCharSequence, FormattedCharSequence>> 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<FormattedCharSequence> nameLines = font.split(name, adaptedNameWidth);
List<FormattedCharSequence> reasonLines = font.split(reason.setStyle(style), versionWidth - 4);
List<Pair<FormattedCharSequence, FormattedCharSequence>> splitLines = new ArrayList<>();
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/net/neoforged/neoforge/common/CommonHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
});

Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public static void enableMilkFluid() {
}

public NeoForgeMod() {
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", () -> {
Expand All @@ -412,7 +412,7 @@ public NeoForgeMod() {
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());

Expand Down Expand Up @@ -447,7 +447,7 @@ public NeoForgeMod() {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public interface ICapabilityProvider {
<T> LazyOptional<T> getCapability(@NotNull final Capability<T> 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 <T> LazyOptional<T> getCapability(@NotNull final Capability<T> cap) {
Expand Down
Loading

0 comments on commit 42166c6

Please sign in to comment.