Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(network): stop disconnect when adding custom recipe book types and connecting to vanilla servers #9994

Open
wants to merge 1 commit into
base: 1.20.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions patches/minecraft/net/minecraft/client/Minecraft.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
static Minecraft instance;
private static final Logger LOGGER = LogUtils.getLogger();
public static final boolean ON_OSX = Util.getPlatform() == Util.OS.OSX;
@@ -348,7 +_,7 @@
@Nullable
private IntegratedServer singleplayerServer;
@Nullable
- private Connection pendingConnection;
+ public Connection pendingConnection;
private boolean isLocalServer;
@Nullable
public Entity cameraEntity;
@@ -438,7 +_,6 @@
}
}, Util.nonCriticalIoPool());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
--- a/net/minecraft/stats/RecipeBookSettings.java
+++ b/net/minecraft/stats/RecipeBookSettings.java
@@ -11,7 +_,7 @@
@@ -6,12 +_,14 @@
import java.util.EnumMap;
import java.util.Map;
import net.minecraft.Util;
+import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.inventory.RecipeBookType;
+import net.minecraftforge.network.ConnectionType;

public final class RecipeBookSettings {
- private static final Map<RecipeBookType, Pair<String, String>> TAG_FIELDS = ImmutableMap.of(
Expand All @@ -18,6 +25,29 @@
private final Map<RecipeBookType, RecipeBookSettings.TypeSettings> states;

private RecipeBookSettings(Map<RecipeBookType, RecipeBookSettings.TypeSettings> p_12730_) {
@@ -53,8 +_,14 @@

public static RecipeBookSettings read(FriendlyByteBuf p_12753_) {
Map<RecipeBookType, RecipeBookSettings.TypeSettings> map = Maps.newEnumMap(RecipeBookType.class);
+ var connection = Minecraft.getInstance().getConnection() == null ? Minecraft.getInstance().pendingConnection : Minecraft.getInstance().getConnection().getConnection();
+ var connectionType = connection == null ? ConnectionType.VANILLA : net.minecraftforge.network.NetworkContext.get(connection).getType();

for (RecipeBookType recipebooktype : RecipeBookType.values()) {
+ if (connectionType == ConnectionType.VANILLA && recipebooktype.isModded()) {
+ continue;
+ }
+
boolean flag = p_12753_.readBoolean();
boolean flag1 = p_12753_.readBoolean();
map.put(recipebooktype, new RecipeBookSettings.TypeSettings(flag, flag1));
@@ -110,6 +_,7 @@

for (RecipeBookType recipebooktype : RecipeBookType.values()) {
RecipeBookSettings.TypeSettings recipebooksettings$typesettings = p_12733_.states.get(recipebooktype);
+ if (recipebooksettings$typesettings == null) continue;
this.states.put(recipebooktype, recipebooksettings$typesettings.copy());
}
}
@@ -158,5 +_,10 @@
public String toString() {
return "[open=" + this.open + ", filtering=" + this.filtering + "]";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
--- a/net/minecraft/world/inventory/RecipeBookType.java
+++ b/net/minecraft/world/inventory/RecipeBookType.java
@@ -1,8 +_,18 @@
@@ -1,8 +_,24 @@
package net.minecraft.world.inventory;

-public enum RecipeBookType {
+import net.minecraft.network.protocol.Packet;
+
+public enum RecipeBookType implements net.minecraftforge.common.IExtensibleEnum {
CRAFTING,
FURNACE,
Expand All @@ -18,5 +20,9 @@
+ public void init() {
+ String name = this.name().toLowerCase(java.util.Locale.ROOT).replace("_","");
+ net.minecraft.stats.RecipeBookSettings.addTagsForType(this, "is" + name + "GuiOpen", "is" + name + "FilteringCraftable");
+ }
+
+ public boolean isModded() {
+ return this != CRAFTING && this != FURNACE && this != BLAST_FURNACE && this != SMOKER;
+ }
}