From ff2b2107f7530ec2e37911cb5bb38e47d4ac75bd Mon Sep 17 00:00:00 2001 From: Maya <10861407+serenibyss@users.noreply.github.com> Date: Mon, 11 Nov 2024 07:55:18 -0600 Subject: [PATCH] Merge mixin from BQ3-Thermos-patch mod --- .../hodgepodge/config/FixesConfig.java | 7 ++++ .../mitchej123/hodgepodge/mixins/Mixins.java | 4 +++ .../early/minecraft/MixinContainerPlayer.java | 36 +++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinContainerPlayer.java diff --git a/src/main/java/com/mitchej123/hodgepodge/config/FixesConfig.java b/src/main/java/com/mitchej123/hodgepodge/config/FixesConfig.java index 1cae4adc..ff5c91a3 100644 --- a/src/main/java/com/mitchej123/hodgepodge/config/FixesConfig.java +++ b/src/main/java/com/mitchej123/hodgepodge/config/FixesConfig.java @@ -319,6 +319,13 @@ public class FixesConfig { /* ====== Minecraft fixes end ===== */ + // bukkit fixes + + @Config.Comment("Fix crash on Bukkit with BetterQuesting") + @Config.DefaultBoolean(true) + @Config.RequiresMcRestart + public static boolean fixBukkitBetterQuestingCrash; + // affecting multiple mods @Config.Comment("Remove old/stale/outdated update checks.") diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java b/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java index 493b1ca1..473b84d4 100644 --- a/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java @@ -450,6 +450,10 @@ public enum Mixins { .addMixinClasses("minecraft.MixinRendererLivingEntity_HitEffectBrightness") .setApplyIf(() -> FixesConfig.fixHitEffectBrightness).addTargetedMod(TargetedMod.VANILLA)), + FIX_BUKKIT_PLAYER_CONTAINER(new Builder("Fix Bukkit BetterQuesting crash").setPhase(Phase.EARLY).setSide(Side.BOTH) + .addTargetedMod(TargetedMod.BUKKIT).addMixinClasses("minecraft.MixinContainerPlayer") + .setApplyIf(() -> FixesConfig.fixBukkitBetterQuestingCrash)), + MEMORY_FIXES_CLIENT( new Builder("Memory fixes").setPhase(Phase.EARLY).setSide(Side.CLIENT).addTargetedMod(TargetedMod.VANILLA) .addMixinClasses("memory.MixinFMLClientHandler").setApplyIf(() -> FixesConfig.enableMemoryFixes)), diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinContainerPlayer.java b/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinContainerPlayer.java new file mode 100644 index 00000000..a1d0386e --- /dev/null +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/early/minecraft/MixinContainerPlayer.java @@ -0,0 +1,36 @@ +package com.mitchej123.hodgepodge.mixins.early.minecraft; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.ContainerPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.network.play.server.S2FPacketSetSlot; + +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(ContainerPlayer.class) +public abstract class MixinContainerPlayer extends Container { + + @Shadow + public IInventory craftResult; + + // inject point relies on a bukkit patch: + // https://github.com/GTNewHorizons/Thermos/blob/ab8a329b10f0857cb246e5d791ede8e1f7419c63/patches/net/minecraft/inventory/ContainerPlayer.java.patch#L58 + @Inject( + method = "onCraftMatrixChanged", + at = @At(value = "INVOKE", target = "Ljava/util/List;get(I)Ljava/lang/Object;"), + cancellable = true) + private void hodgepodge$bukkitCraftMatrixChangedProxy(CallbackInfo ci) { + if (crafters.get(0) instanceof EntityPlayerMP playerMP) { + ItemStack result = craftResult.getStackInSlot(0); + playerMP.playerNetServerHandler + .sendPacket(new S2FPacketSetSlot(playerMP.openContainer.windowId, 0, result)); + } + ci.cancel(); + } +}