Skip to content

Commit

Permalink
Merge pull request #81 from fcsailboat/fabric/1.21.x
Browse files Browse the repository at this point in the history
修复盔甲槽位背景纹理出现在其他容器槽位
  • Loading branch information
Gu-ZT authored Nov 3, 2024
2 parents 4c1251a + 9cd94b3 commit 52c168a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
28 changes: 14 additions & 14 deletions src/main/java/dev/dubhe/gugle/carpet/mixin/ChestMenuMixin.java
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
package dev.dubhe.gugle.carpet.mixin;

import dev.dubhe.gugle.carpet.api.menu.control.Button;
import dev.dubhe.gugle.carpet.tools.ClientMenuTick;
import dev.dubhe.gugle.carpet.tools.FakePlayerInventoryMenu;
import dev.dubhe.gugle.carpet.tools.SlotIcon;
import net.minecraft.core.component.DataComponents;
import net.minecraft.world.Container;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.ChestMenu;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.component.CustomData;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@SuppressWarnings("AddedMixinMembersNamePattern")
@Mixin(ChestMenu.class)
public abstract class ChestMenuMixin {
public abstract class ChestMenuMixin implements ClientMenuTick {
@Unique
private final ChestMenu thisMenu = (ChestMenu) (Object) this;

@Inject(method = "<init>(Lnet/minecraft/world/inventory/MenuType;ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/Container;I)V", at = @At("RETURN"))
private void init(MenuType<?> menuType, int i, Inventory inventory, Container container, int j, CallbackInfo ci) {
((SlotIcon) thisMenu.getSlot(1)).setIcon(InventoryMenu.EMPTY_ARMOR_SLOT_HELMET);
((SlotIcon) thisMenu.getSlot(2)).setIcon(InventoryMenu.EMPTY_ARMOR_SLOT_CHESTPLATE);
((SlotIcon) thisMenu.getSlot(3)).setIcon(InventoryMenu.EMPTY_ARMOR_SLOT_LEGGINGS);
((SlotIcon) thisMenu.getSlot(4)).setIcon(InventoryMenu.EMPTY_ARMOR_SLOT_BOOTS);
((SlotIcon) thisMenu.getSlot(7)).setIcon(InventoryMenu.EMPTY_ARMOR_SLOT_SHIELD);
}

@Inject(method = "quickMoveStack", at = @At("HEAD"), cancellable = true)
private void quickMove(Player player, int i, CallbackInfoReturnable<ItemStack> cir) {
if (this.isFakePlayerMenu()) {
cir.setReturnValue(FakePlayerInventoryMenu.quickMove(thisMenu, i));
}
}

@Override
public void tick() {
if (this.isFakePlayerMenu()) {
((SlotIcon) thisMenu.getSlot(1)).setIcon(InventoryMenu.EMPTY_ARMOR_SLOT_HELMET);
((SlotIcon) thisMenu.getSlot(2)).setIcon(InventoryMenu.EMPTY_ARMOR_SLOT_CHESTPLATE);
((SlotIcon) thisMenu.getSlot(3)).setIcon(InventoryMenu.EMPTY_ARMOR_SLOT_LEGGINGS);
((SlotIcon) thisMenu.getSlot(4)).setIcon(InventoryMenu.EMPTY_ARMOR_SLOT_BOOTS);
((SlotIcon) thisMenu.getSlot(7)).setIcon(InventoryMenu.EMPTY_ARMOR_SLOT_SHIELD);
}
}

@Unique
private boolean isFakePlayerMenu() {
ItemStack itemStack = thisMenu.getSlot(0).getItem();
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/dev/dubhe/gugle/carpet/mixin/PlayerMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import dev.dubhe.gugle.carpet.GcaSetting;
import dev.dubhe.gugle.carpet.tools.GcaUtils;
import dev.dubhe.gugle.carpet.api.tools.text.ComponentTranslate;
import dev.dubhe.gugle.carpet.tools.ClientUtils;
import dev.dubhe.gugle.carpet.tools.FakePlayerEnderChestContainer;
import dev.dubhe.gugle.carpet.tools.FakePlayerInventoryContainer;
import dev.dubhe.gugle.carpet.tools.FakePlayerInventoryMenu;
import dev.dubhe.gugle.carpet.tools.*;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.SimpleMenuProvider;
Expand Down Expand Up @@ -38,6 +35,10 @@ private void tick(CallbackInfo ci) {
= GcaExtension.fakePlayerInventoryContainerMap.get(gca$self);
entry.getKey().tick();
entry.getValue().tick();
} else if (gca$self.level().isClientSide) {
if (gca$self.containerMenu instanceof ClientMenuTick tick) {
tick.tick();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dev.dubhe.gugle.carpet.tools;

public interface ClientMenuTick {
void tick();
}

0 comments on commit 52c168a

Please sign in to comment.