Skip to content

Commit 385523c

Browse files
committed
Merge 1.19.2 into 1.20
2 parents 225366e + c387e91 commit 385523c

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.embeddedt.modernfix.forge.mixin.bugfix.recipe_book_type_desync;
2+
3+
import com.llamalad7.mixinextras.sugar.Local;
4+
import net.minecraft.network.FriendlyByteBuf;
5+
import net.minecraft.stats.RecipeBookSettings;
6+
import net.minecraft.world.inventory.RecipeBookType;
7+
import org.embeddedt.modernfix.ModernFix;
8+
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
9+
import org.embeddedt.modernfix.forge.packet.NetworkUtils;
10+
import org.spongepowered.asm.mixin.Mixin;
11+
import org.spongepowered.asm.mixin.injection.At;
12+
import org.spongepowered.asm.mixin.injection.Redirect;
13+
14+
import java.lang.reflect.Field;
15+
import java.lang.reflect.Modifier;
16+
17+
@Mixin(RecipeBookSettings.class)
18+
@ClientOnlyMixin
19+
public class RecipeBookSettingsMixin {
20+
private static int mfix$maxVanillaOrdinal;
21+
22+
static {
23+
int ord = 0;
24+
for(Field f : RecipeBookType.class.getDeclaredFields()) {
25+
if(RecipeBookType.class.isAssignableFrom(f.getType()) && Modifier.isStatic(f.getModifiers()) && Modifier.isPublic(f.getModifiers())) {
26+
try {
27+
f.setAccessible(true);
28+
RecipeBookType type = (RecipeBookType)f.get(null);
29+
ord = Math.max(type.ordinal(), ord);
30+
} catch(Exception e) {
31+
e.printStackTrace();
32+
ord = Integer.MAX_VALUE - 1;
33+
break;
34+
}
35+
}
36+
}
37+
mfix$maxVanillaOrdinal = ord;
38+
}
39+
@Redirect(method = "read(Lnet/minecraft/network/FriendlyByteBuf;)Lnet/minecraft/stats/RecipeBookSettings;", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/FriendlyByteBuf;readBoolean()Z"))
40+
private static boolean useDefaultBooleanIfVanilla(FriendlyByteBuf buf, @Local(ordinal = 0) RecipeBookType type) {
41+
if(type.ordinal() >= (mfix$maxVanillaOrdinal + 1) && NetworkUtils.isCurrentlyVanilla) {
42+
ModernFix.LOGGER.warn("Not reading recipe book data for type '{}' as we are using vanilla connection", type.name());
43+
return false; // skip actually reading buffer
44+
}
45+
return buf.readBoolean();
46+
}
47+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.embeddedt.modernfix.forge.mixin.core;
2+
3+
import net.minecraft.network.Connection;
4+
import net.minecraftforge.network.NetworkHooks;
5+
import org.embeddedt.modernfix.forge.packet.NetworkUtils;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.Shadow;
8+
import org.spongepowered.asm.mixin.injection.At;
9+
import org.spongepowered.asm.mixin.injection.Inject;
10+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
11+
12+
@Mixin(NetworkHooks.class)
13+
public abstract class NetworkHooksMixin {
14+
@Shadow public static boolean isVanillaConnection(Connection manager) {
15+
throw new AssertionError();
16+
}
17+
18+
@Inject(method = "handleClientLoginSuccess", at = @At("RETURN"), remap = false)
19+
private static void setVanillaGlobalFlag(Connection manager, CallbackInfo ci) {
20+
NetworkUtils.isCurrentlyVanilla = isVanillaConnection(manager);
21+
}
22+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.embeddedt.modernfix.forge.packet;
2+
3+
public class NetworkUtils {
4+
public static boolean isCurrentlyVanilla;
5+
}

0 commit comments

Comments
 (0)