Skip to content

Commit

Permalink
Fix misplaced patch in Mob and prevent the addition of trailing space…
Browse files Browse the repository at this point in the history
…s in patches (#451)
  • Loading branch information
pupnewfster authored Jan 1, 2024
1 parent 11074e7 commit 2d0f920
Show file tree
Hide file tree
Showing 23 changed files with 109 additions and 127 deletions.
18 changes: 17 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import java.util.regex.Matcher
import java.util.regex.Pattern

plugins {
id 'net.neoforged.gradleutils' version '3.0.0-alpha.10' apply false
id 'com.diffplug.spotless' version '6.22.0' apply false
Expand Down Expand Up @@ -87,6 +90,19 @@ spotless {
}
return fileContents
}
bumpThisNumberIfACustomStepChanges(1)

//Trim any trailing whitespace from patch additions
def trailingWhitespace = Pattern.compile('^\\+.*[ \t]+\$', Pattern.UNIX_LINES | Pattern.MULTILINE)
custom 'trimTrailingWhitespacePatches', { String fileContents ->
Matcher matcher = trailingWhitespace.matcher(fileContents)
StringBuilder sb = new StringBuilder()
while (matcher.find()) {
matcher.appendReplacement(sb, matcher.group().trim())
}
matcher.appendTail(sb)
return sb.toString()
}

bumpThisNumberIfACustomStepChanges(2)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
--- a/com/mojang/realmsclient/gui/screens/RealmsGenericErrorScreen.java
+++ b/com/mojang/realmsclient/gui/screens/RealmsGenericErrorScreen.java
@@ -65,6 +_,15 @@
return Component.empty().append(this.lines.title).append(": ").append(this.lines.detail);
@@ -66,6 +_,15 @@
}

+ @Override
@Override
+ public boolean keyPressed(int key, int scanCode, int modifiers) {
+ if (key == org.lwjgl.glfw.GLFW.GLFW_KEY_ESCAPE) {
+ minecraft.setScreen(this.nextScreen);
Expand All @@ -13,6 +12,7 @@
+ return super.keyPressed(key, scanCode, modifiers);
+ }
+
@Override
+ @Override
public void render(GuiGraphics p_283497_, int p_88680_, int p_88681_, float p_88682_) {
super.render(p_283497_, p_88680_, p_88681_, p_88682_);
p_283497_.drawCenteredString(this.font, this.lines.title, this.width / 2, 80, -1);
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
+ final List<String> systemInformation = new java.util.ArrayList<>();
+ var event = new net.neoforged.neoforge.client.event.CustomizeGuiOverlayEvent.DebugText(minecraft.getWindow(), p_281427_, minecraft.getFrameTime(), gameInformation, systemInformation);
+ net.neoforged.neoforge.common.NeoForge.EVENT_BUS.post(event);
+
+
+ this.drawGameInformation(p_281427_, gameInformation);
+ this.drawSystemInformation(p_281427_, systemInformation);
if (this.renderFpsCharts) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
--- a/net/minecraft/client/gui/screens/worldselection/WorldCreationUiState.java
+++ b/net/minecraft/client/gui/screens/worldselection/WorldCreationUiState.java
@@ -223,11 +_,11 @@
public WorldCreationUiState.WorldTypeEntry getWorldType() {
return this.worldType;
}
-
+
@@ -227,7 +_,7 @@
@Nullable
public PresetEditor getPresetEditor() {
Holder<WorldPreset> holder = this.getWorldType().preset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
+ if (!net.neoforged.neoforge.network.registration.NetworkRegistry.getInstance().canSendPacket(p_295097_, this)) {
+ return;
+ }
+
+
this.connection.send(p_295097_);
}

Expand All @@ -47,7 +47,7 @@
static record PendingRequest(UUID id, URL url, String hash) {
}
+ }
+
+
+ @Override
+ public Connection getConnection() {
+ return connection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
+ net.neoforged.neoforge.network.registration.NetworkRegistry.getInstance().onModdedPacketAtClient(this, p_295727_);
+ return;
+ }
+
+
this.handleUnknownCustomPayload(p_295411_);
}

Expand Down Expand Up @@ -69,13 +69,13 @@
super.onDisconnect(p_314649_);
this.minecraft.clearDownloadedResourcePacks();
+ }
+
+
+ @Override
+ protected net.minecraft.client.gui.screens.Screen createDisconnectScreen(net.minecraft.network.chat.Component p_296470_) {
+ final net.minecraft.client.gui.screens.Screen superScreen = super.createDisconnectScreen(p_296470_);
+ if (failureReasons.isEmpty())
+ return superScreen;
+
+
+ return new net.neoforged.neoforge.client.gui.ModMismatchDisconnectedScreen(superScreen, p_296470_, failureReasons);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
BlockState blockstate = p_203157_.getBlockState(p_203159_);
return this.getHeight(p_203157_, p_203158_, p_203159_, blockstate, blockstate.getFluidState());
+ }
+
+
+ private void vertex(VertexConsumer p_110985_, double p_110986_, double p_110987_, double p_110988_, float p_110989_, float p_110990_, float p_110991_, float alpha, float p_110992_, float p_110993_, int p_110994_) {
+ p_110985_.vertex(p_110986_, p_110987_, p_110988_).color(p_110989_, p_110990_, p_110991_, alpha).uv(p_110992_, p_110993_).uv2(p_110994_).normal(0.0F, 1.0F, 0.0F).endVertex();
}
Expand Down
53 changes: 26 additions & 27 deletions patches/net/minecraft/network/ConnectionProtocol.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -36,37 +36,33 @@
.addPacket(ServerboundFinishConfigurationPacket.class, ServerboundFinishConfigurationPacket::new)
.addPacket(ServerboundKeepAlivePacket.class, ServerboundKeepAlivePacket::new)
.addPacket(ServerboundPongPacket.class, ServerboundPongPacket::new)
@@ -466,7 +_,23 @@
public static final int NOT_REGISTERED = -1;
@@ -467,6 +_,22 @@
private final String id;
private final Map<PacketFlow, ConnectionProtocol.CodecData<?>> flows;
-
+

+ private static ConnectionProtocol play() {
+ return PLAY;
+ }
+
+
+ private static ConnectionProtocol configuration() {
+ return CONFIGURATION;
+ }
+
+
+ public boolean isPlay() {
+ return this == PLAY;
+ }
+
+
+ public boolean isConfiguration() {
+ return this == CONFIGURATION;
+ }
+
+
private static ConnectionProtocol.ProtocolBuilder protocol() {
return new ConnectionProtocol.ProtocolBuilder();
}
@@ -523,11 +_,28 @@
this.packetSet.classToId.forEach((p_294840_, p_295455_) -> int2objectmap.put(p_295455_.intValue(), p_294840_));
@@ -524,11 +_,28 @@
return int2objectmap;
}
-
+

+ /**
+ * @deprecated Use {@link #createPacket(int, FriendlyByteBuf, io.netty.channel.ChannelHandlerContext)} instead, which provides the channel context for creating custom packet payloads.
+ */
Expand All @@ -75,7 +71,7 @@
public Packet<?> createPacket(int p_294972_, FriendlyByteBuf p_296217_) {
return this.packetSet.createPacket(p_294972_, p_296217_);
}
+

+ /**
+ * Creates a new packet from the discriminator and the buffer.
+ *
Expand All @@ -88,9 +84,10 @@
+ public Packet<?> createPacket(int p_294972_, FriendlyByteBuf p_296217_, io.netty.channel.ChannelHandlerContext p_130535_) {
+ return this.packetSet.createPacket(p_294972_, p_296217_, p_130535_);
+ }
+
public boolean isValidPacketType(Packet<?> p_294142_) {
return this.packetSet.isKnownPacket(p_294142_.getClass());
}
@@ -539,12 +_,22 @@
final Object2IntMap<Class<? extends Packet<? super T>>> classToId = Util.make(
new Object2IntOpenHashMap<>(), p_129613_ -> p_129613_.defaultReturnValue(-1)
Expand All @@ -110,26 +107,31 @@
+ if (i != k) {
+ throw new IllegalStateException("Deserializer lists must be equal in length! Somebody externally modified the registration!");
+ }
+
+
int j = this.classToId.put(p_178331_, i);
if (j != -1) {
String s = "Packet " + p_178331_ + " is already registered to ID " + j;
@@ -552,11 +_,33 @@
throw new IllegalArgumentException(s);
} else {
this.idToDeserializer.add(p_178332_);
- return this;
- }
- }
-
- public <P extends BundlePacket<T>> ConnectionProtocol.PacketSet<T> withBundlePacket(Class<P> p_265034_, Function<Iterable<Packet<T>>, P> p_265591_) {
+ this.contextualIdToDeserializer.add((p_296217_, p_130535_) -> p_178332_.apply(p_296217_)); //NeoForge: We always want to be able to create a packet from a buffer, even if we don't have a channel context
+ return this;
+ }
+ }
+
+
+ public <P extends Packet<? super T>> ConnectionProtocol.PacketSet<T> addContextualPacket(Class<P> p_178331_, java.util.function.BiFunction<FriendlyByteBuf, io.netty.channel.ChannelHandlerContext, P> readerBuilder) {
+ int i = this.contextualIdToDeserializer.size();
+ int k = this.idToDeserializer.size();
+ if (i != k) {
+ throw new IllegalStateException("Deserializer lists must be equal in length! Somebody externally modified the registration!");
+ }
+
+
+ int j = this.classToId.put(p_178331_, i);
+ if (j != -1) {
+ String s = "Packet " + p_178331_ + " is already registered to ID " + j;
Expand All @@ -140,21 +142,18 @@
+ throw new IllegalStateException("Cannot deserialize contextual packet: " + p_178331_.getSimpleName() + " without context");
+ }));
+ this.contextualIdToDeserializer.add(readerBuilder);
return this;
}
}

- public <P extends BundlePacket<T>> ConnectionProtocol.PacketSet<T> withBundlePacket(Class<P> p_265034_, Function<Iterable<Packet<T>>, P> p_265591_) {
+ return this;
+ }
+ }
+
+ public <P extends BundlePacket<T>> ConnectionProtocol.PacketSet<T> withBundlePacket(Class<P> p_265034_, Function<Iterable<Packet<? super T>>, P> p_265591_) {
if (this.bundlerInfo != BundlerInfo.EMPTY) {
throw new IllegalStateException("Bundle packet already configured");
} else {
@@ -575,11 +_,29 @@
public boolean isKnownPacket(Class<?> p_295070_) {
@@ -576,10 +_,28 @@
return this.classToId.containsKey(p_295070_) || this.extraClasses.contains(p_295070_);
}
-
+

+ /**
+ * @deprecated Use {@link #createPacket(int, FriendlyByteBuf, io.netty.channel.ChannelHandlerContext)} instead, which provides the channel context for creating custom packet payloads.
+ */
Expand All @@ -164,7 +163,7 @@
Function<FriendlyByteBuf, ? extends Packet<? super T>> function = this.idToDeserializer.get(p_178328_);
return function != null ? function.apply(p_178329_) : null;
+ }
+
+
+ /**
+ * Creates a new packet from the given discriminator and buffer.
+ *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
+ packetSender.accept(bundlePacket);
+ }
+ }
+
+
@Nullable
@Override
public BundlerInfo.Bundler startPacketBundling(Packet<?> p_265097_) {
Expand Down
8 changes: 4 additions & 4 deletions patches/net/minecraft/resources/RegistryOps.java.patch
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
--- a/net/minecraft/resources/RegistryOps.java
+++ b/net/minecraft/resources/RegistryOps.java
@@ -45,6 +_,11 @@
super(p_256313_);
@@ -46,6 +_,11 @@
this.lookupProvider = p_255799_;
}
+

+ protected RegistryOps(RegistryOps<T> p_256313_) {
+ super(p_256313_);
+ this.lookupProvider = p_256313_.lookupProvider;
+ }
+
public <E> Optional<HolderOwner<E>> owner(ResourceKey<? extends Registry<? extends E>> p_255757_) {
return this.lookupProvider.lookup(p_255757_).map(RegistryOps.RegistryInfo::owner);
}
@@ -64,6 +_,20 @@
: DataResult.error(() -> "Not a registry ops")
)
Expand Down
17 changes: 7 additions & 10 deletions patches/net/minecraft/resources/ResourceLocation.java.patch
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
--- a/net/minecraft/resources/ResourceLocation.java
+++ b/net/minecraft/resources/ResourceLocation.java
@@ -142,8 +_,14 @@
if (i == 0) {
i = this.namespace.compareTo(p_135826_.namespace);
}
-
+
@@ -146,6 +_,12 @@
return i;
+ }
+
}
+ // Normal compare sorts by path first, this compares namespace first.
+ public int compareNamespaced(ResourceLocation o) {
+ int ret = this.namespace.compareTo(o.namespace);
+ return ret != 0 ? ret : this.path.compareTo(o.path);
}
+ }
+
public String toDebugFileName() {
return this.toString().replace('/', '_').replace(':', '_');
}
3 changes: 1 addition & 2 deletions patches/net/minecraft/server/level/ServerLevel.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@
+ "onTrackingStart called during navigation iteration", new IllegalStateException("onTrackingStart called during navigation iteration")
);
}
-
+

ServerLevel.this.navigatingMobs.remove(mob);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
+ public Type(net.minecraft.resources.ResourceLocation location) {
+ this(location.toString());
+ }
+
+
@Override
public String toString() {
return this.id;
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
+ if (!net.neoforged.neoforge.network.registration.NetworkRegistry.getInstance().canSendPacket(p_295099_, this)) {
+ return;
+ }
+
+
boolean flag = !this.suspendFlushingOnServerThread || !this.server.isSameThread();

try {
Expand All @@ -28,7 +28,7 @@
protected CommonListenerCookie createCookie(ClientInformation p_301973_) {
return new CommonListenerCookie(this.playerProfile(), this.latency, p_301973_);
+ }
+
+
+ /**
+ * Creates a new cookie for this connection.
+ *
Expand All @@ -39,7 +39,7 @@
+ protected CommonListenerCookie createCookie(ClientInformation p_301973_, boolean isModdedConnection) {
+ return new CommonListenerCookie(this.playerProfile(), this.latency, p_301973_, isModdedConnection);
+ }
+
+
+ @Override
+ public Connection getConnection() {
+ return connection;
Expand Down
Loading

0 comments on commit 2d0f920

Please sign in to comment.