Skip to content

Commit

Permalink
Fixes strange bug that prevents getting items from fzmm while in crea…
Browse files Browse the repository at this point in the history
…tive

* 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
  • Loading branch information
Zailer43 committed Jul 8, 2024
1 parent 2e26727 commit 2b6df28
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/fzmm/zailer/me/client/FzmmCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
9 changes: 6 additions & 3 deletions src/main/java/fzmm/zailer/me/utils/FzmmUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

/**
Expand Down

0 comments on commit 2b6df28

Please sign in to comment.