Merge 1.20 into 1.20.2
This commit is contained in:
commit
0149a113a8
|
|
@ -0,0 +1,47 @@
|
||||||
|
package org.embeddedt.modernfix.forge.mixin.bugfix.recipe_book_type_desync;
|
||||||
|
|
||||||
|
import com.llamalad7.mixinextras.sugar.Local;
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.stats.RecipeBookSettings;
|
||||||
|
import net.minecraft.world.inventory.RecipeBookType;
|
||||||
|
import org.embeddedt.modernfix.ModernFix;
|
||||||
|
import org.embeddedt.modernfix.annotation.ClientOnlyMixin;
|
||||||
|
import org.embeddedt.modernfix.forge.packet.NetworkUtils;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
|
@Mixin(RecipeBookSettings.class)
|
||||||
|
@ClientOnlyMixin
|
||||||
|
public class RecipeBookSettingsMixin {
|
||||||
|
private static int mfix$maxVanillaOrdinal;
|
||||||
|
|
||||||
|
static {
|
||||||
|
int ord = 0;
|
||||||
|
for(Field f : RecipeBookType.class.getDeclaredFields()) {
|
||||||
|
if(RecipeBookType.class.isAssignableFrom(f.getType()) && Modifier.isStatic(f.getModifiers()) && Modifier.isPublic(f.getModifiers())) {
|
||||||
|
try {
|
||||||
|
f.setAccessible(true);
|
||||||
|
RecipeBookType type = (RecipeBookType)f.get(null);
|
||||||
|
ord = Math.max(type.ordinal(), ord);
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
ord = Integer.MAX_VALUE - 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mfix$maxVanillaOrdinal = ord;
|
||||||
|
}
|
||||||
|
@Redirect(method = "read(Lnet/minecraft/network/FriendlyByteBuf;)Lnet/minecraft/stats/RecipeBookSettings;", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/FriendlyByteBuf;readBoolean()Z"))
|
||||||
|
private static boolean useDefaultBooleanIfVanilla(FriendlyByteBuf buf, @Local(ordinal = 0) RecipeBookType type) {
|
||||||
|
if(type.ordinal() >= (mfix$maxVanillaOrdinal + 1) && NetworkUtils.isCurrentlyVanilla) {
|
||||||
|
ModernFix.LOGGER.warn("Not reading recipe book data for type '{}' as we are using vanilla connection", type.name());
|
||||||
|
return false; // skip actually reading buffer
|
||||||
|
}
|
||||||
|
return buf.readBoolean();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
package org.embeddedt.modernfix.forge.mixin.core;
|
||||||
|
|
||||||
|
import net.minecraft.network.Connection;
|
||||||
|
import net.minecraftforge.network.NetworkHooks;
|
||||||
|
import org.embeddedt.modernfix.forge.packet.NetworkUtils;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
@Mixin(NetworkHooks.class)
|
||||||
|
public abstract class NetworkHooksMixin {
|
||||||
|
@Shadow public static boolean isVanillaConnection(Connection manager) {
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "handleClientLoginSuccess", at = @At("RETURN"), remap = false)
|
||||||
|
private static void setVanillaGlobalFlag(Connection manager, CallbackInfo ci) {
|
||||||
|
NetworkUtils.isCurrentlyVanilla = isVanillaConnection(manager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package org.embeddedt.modernfix.forge.packet;
|
||||||
|
|
||||||
|
public class NetworkUtils {
|
||||||
|
public static boolean isCurrentlyVanilla;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user