From 2b6df28d35afca74b448f1a0114dd0b1aef56769 Mon Sep 17 00:00:00 2001 From: Zailer43 Date: Mon, 8 Jul 2024 19:45:50 -0300 Subject: [PATCH] Fixes strange bug that prevents getting items from fzmm while in creative * This happened on servers, when client player and the tab player have a different UUID, and the one on the tab has your UUID and tab player is not in creative --- src/main/java/fzmm/zailer/me/client/FzmmCommand.java | 2 +- .../auto_placer/ClientPlayerInteractionManagerMixin.java | 3 ++- src/main/java/fzmm/zailer/me/utils/FzmmUtils.java | 9 ++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/fzmm/zailer/me/client/FzmmCommand.java b/src/main/java/fzmm/zailer/me/client/FzmmCommand.java index ac6a5a25..7cd47a1f 100644 --- a/src/main/java/fzmm/zailer/me/client/FzmmCommand.java +++ b/src/main/java/fzmm/zailer/me/client/FzmmCommand.java @@ -684,7 +684,7 @@ private static void swapItemWithHand(EquipmentSlot slot) { assert client.interactionManager != null; ClientPlayerEntity player = client.player; - if (!player.isCreative()) { + if (!FzmmUtils.isAllowedToGive()) { FzmmClient.LOGGER.warn("[FzmmCommand] Creative mode is necessary to swap items"); client.inGameHud.getChatHud().addMessage(Text.translatable("fzmm.item.error.actionNotAllowed").setStyle(Style.EMPTY.withColor(FzmmClient.CHAT_BASE_COLOR))); return; diff --git a/src/main/java/fzmm/zailer/me/mixin/item_stack/auto_placer/ClientPlayerInteractionManagerMixin.java b/src/main/java/fzmm/zailer/me/mixin/item_stack/auto_placer/ClientPlayerInteractionManagerMixin.java index bd2801f9..73c96c90 100644 --- a/src/main/java/fzmm/zailer/me/mixin/item_stack/auto_placer/ClientPlayerInteractionManagerMixin.java +++ b/src/main/java/fzmm/zailer/me/mixin/item_stack/auto_placer/ClientPlayerInteractionManagerMixin.java @@ -3,6 +3,7 @@ import com.llamalad7.mixinextras.injector.ModifyReturnValue; import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; import fzmm.zailer.me.client.gui.utils.auto_placer.AutoPlacerHud; +import fzmm.zailer.me.utils.FzmmUtils; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerInteractionManager; import net.minecraft.client.network.SequencedPacketCreator; @@ -38,7 +39,7 @@ public abstract class ClientPlayerInteractionManagerMixin { ItemStack stack = this.client.player.getMainHandStack(); - if (this.client.player.isSneaking() || !this.client.player.isCreative() && !stack.getComponents().isEmpty()) { + if (this.client.player.isSneaking() || !FzmmUtils.isAllowedToGive() && !stack.getComponents().isEmpty()) { return true; } diff --git a/src/main/java/fzmm/zailer/me/utils/FzmmUtils.java b/src/main/java/fzmm/zailer/me/utils/FzmmUtils.java index 227072aa..3e8f8b7e 100644 --- a/src/main/java/fzmm/zailer/me/utils/FzmmUtils.java +++ b/src/main/java/fzmm/zailer/me/utils/FzmmUtils.java @@ -15,7 +15,6 @@ import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.PlayerListEntry; import net.minecraft.entity.EquipmentSlot; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -180,9 +179,13 @@ public static Item getItem(String value) { } public static boolean isAllowedToGive() { - PlayerEntity player = MinecraftClient.getInstance().player; + MinecraftClient client = MinecraftClient.getInstance(); + if (client.interactionManager == null) { + return false; + } - return player != null && (player.isCreative() || FzmmClient.CONFIG.general.giveClientSide()); + return client.interactionManager.getCurrentGameMode().isCreative() + || FzmmClient.CONFIG.general.giveClientSide(); } /**