diff --git a/src/main/java/dev/cammiescorner/camsbackpacks/CamsBackpacks.java b/src/main/java/dev/cammiescorner/camsbackpacks/CamsBackpacks.java index a206fca..c132f0e 100644 --- a/src/main/java/dev/cammiescorner/camsbackpacks/CamsBackpacks.java +++ b/src/main/java/dev/cammiescorner/camsbackpacks/CamsBackpacks.java @@ -1,5 +1,6 @@ package dev.cammiescorner.camsbackpacks; +import com.google.common.base.MoreObjects; import dev.cammiescorner.camsbackpacks.common.network.EquipBackpackPacket; import dev.cammiescorner.camsbackpacks.common.network.OpenBackpackScreenPacket; import dev.cammiescorner.camsbackpacks.common.network.PlaceBackpackPacket; @@ -11,7 +12,9 @@ import eu.midnightdust.lib.config.MidnightConfig; import net.minecraft.resources.ResourceLocation; import org.quiltmc.loader.api.ModContainer; +import org.quiltmc.loader.api.ModMetadata; import org.quiltmc.loader.api.QuiltLoader; +import org.quiltmc.loader.api.plugin.ModMetadataExt; import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; import org.quiltmc.qsl.networking.api.ServerPlayNetworking; @@ -38,4 +41,8 @@ public void onInitialize(ModContainer mod) { public static ResourceLocation id(String path) { return new ResourceLocation(MOD_ID, path); } + + public static String getIssuesURL() { + return QuiltLoader.getModContainer(MOD_ID).map(ModContainer::metadata).map(meta -> meta.getContactInfo("issues")).orElse(MOD_ID); + } } diff --git a/src/main/java/dev/cammiescorner/camsbackpacks/client/screen/BackpackScreen.java b/src/main/java/dev/cammiescorner/camsbackpacks/client/screen/BackpackScreen.java index d915c90..723f9d3 100644 --- a/src/main/java/dev/cammiescorner/camsbackpacks/client/screen/BackpackScreen.java +++ b/src/main/java/dev/cammiescorner/camsbackpacks/client/screen/BackpackScreen.java @@ -5,7 +5,7 @@ import dev.cammiescorner.camsbackpacks.CamsBackpacks; import dev.cammiescorner.camsbackpacks.client.CamsBackpacksClient; import dev.cammiescorner.camsbackpacks.common.network.EquipBackpackPacket; -import dev.cammiescorner.camsbackpacks.common.screen.BackpackScreenHandler; +import dev.cammiescorner.camsbackpacks.common.menu.BackpackMenu; import dev.cammiescorner.camsbackpacks.core.util.BackpackHelper; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.components.Button; @@ -25,7 +25,7 @@ import org.lwjgl.glfw.GLFW; @SuppressWarnings("ConstantConditions") -public class BackpackScreen extends EffectRenderingInventoryScreen { +public class BackpackScreen extends EffectRenderingInventoryScreen { public static final ResourceLocation TEXTURE = CamsBackpacks.id("textures/gui/backpack.png"); protected Inventory playerInventory; protected Button equipButton; @@ -37,7 +37,7 @@ public class BackpackScreen extends EffectRenderingInventoryScreen ARMOR_SLOTS = List.of(EquipmentSlot.FEET, EquipmentSlot.LEGS, EquipmentSlot.CHEST, EquipmentSlot.HEAD); + + private final Player player; + private final Container inventory; + private final TransientCraftingContainer craftingInv; + private final ResultContainer craftingResultInv; + private final ContainerLevelAccess levelAccess; + public final boolean isBlockEntity; + public BlockPos blockPos; + + public BackpackMenu(int syncId, Inventory playerInventory, BlockPos blockPos, boolean isBlockEntity) { + this(syncId, playerInventory, new SimpleContainer(36), ContainerLevelAccess.NULL, blockPos, isBlockEntity); + } + + public BackpackMenu(int syncId, Inventory playerInventory, Container inventory, ContainerLevelAccess levelAccess, BlockPos blockPos, boolean isBlockEntity) { + super(ModScreenHandlers.BACKPACK_SCREEN_HANDLER, syncId); + checkContainerSize(inventory, 36); + this.player = playerInventory.player; + this.inventory = inventory; + this.craftingInv = new TransientCraftingContainer(this, 3, 3); + this.craftingResultInv = new ResultContainer(); + this.levelAccess = levelAccess; + this.blockPos = blockPos; + this.isBlockEntity = isBlockEntity; + inventory.startOpen(player); + + // Crafting result (slot 0) (global: 0) + addSlot(new ResultSlot(player, craftingInv, craftingResultInv, 0, 273, 71 + 3 * 18)); + + // Crafting table inventory (slots 1-9) (global: 1-9) + for (int y = 0; y < 3; ++y) { + for (int x = 0; x < 3; ++x) { + addSlot(new Slot(craftingInv, x + y * 3, 255 + x * 18, 46 + y * 18)); + } + } + + // Backpack inventory (slots 0-35) (global: 10-45) + for (int y = 0; y < 4; ++y) { + for (int x = 0; x < 9; ++x) { + addSlot(new Slot(inventory, x + y * 9, 81 + x * 18, 18 + y * 18)); + } + } + + // Player inventory (slots 9-35) (global: 46-72) + for (int y = 0; y < 3; ++y) { + for (int x = 0; x < 9; ++x) { + addSlot(new Slot(playerInventory, x + y * 9 + 9, 81 + x * 18, 108 + y * 18)); + } + } + + // Player hotbar (slots 0-8) (global: 73-82) + for (int i = 0; i < 9; ++i) { + addSlot(new Slot(playerInventory, i, 81 + i * 18, 166)); + } + + // Player armor (slot 36-39) (global: 82-85) + for (int i = 0; i < ARMOR_SLOTS.size(); ++i) { + EquipmentSlot equipmentSlot = ARMOR_SLOTS.get(i); + addSlot(new ArmorSlot(playerInventory, equipmentSlot.getIndex(36), 8, 105 - i * 18, equipmentSlot, player)); + } + + // Player offhand (slot 40) (global: 86) + this.addSlot(new OffhandSlot(playerInventory, 40, 8, 123, player)); + + } + + @Override + public void slotsChanged(Container inventory) { + levelAccess.execute((world, pos) -> CraftingMenuAccessor.camsbackpacks$callSlotChangedCraftingGrid(this, world, player, craftingInv, craftingResultInv)); + } + + @Override + public ItemStack quickMoveStack(Player player, int index) { + ItemStack newStack = ItemStack.EMPTY; + Slot slot = this.slots.get(index); + + if (slot.hasItem()) { + ItemStack oldStack = slot.getItem(); + newStack = oldStack.copy(); + + if (index == 0) { // moving out of result slot (0) -> inv first, then backpack, then hotbar + this.levelAccess.execute((world, pos) -> oldStack.getItem().onCraftedBy(oldStack, world, player)); + + // try player inv + if (!moveItemStackTo(oldStack, 46, 73, false)) { + + // try backpack inv + if (!moveItemStackTo(oldStack, 10, 46, false)) { + + // try hotbar + if (!moveItemStackTo(oldStack, 73, 82, false)) { + return ItemStack.EMPTY; + } + } + } + slot.onQuickCraft(oldStack, newStack); + } else if (index <= 9) { // moving out of crafting inv (1-9) -> inv first, then backpack, then hotbar + + // try player inv + if (!moveItemStackTo(oldStack, 46, 73, false)) { + + // try backpack inv + if (!moveItemStackTo(oldStack, 10, 46, false)) { + + // try hotbar + if (!moveItemStackTo(oldStack, 73, 82, false)) { + return ItemStack.EMPTY; + } + } + } + + } else if (index <= 45) { // moving out of backpack inv (10-45) -> armor inv, then hotbar, then regular inv + + // try preferred armor slot + EquipmentSlot equipmentSlot = Mob.getEquipmentSlotForItem(newStack); + int armorSlotId = equipmentSlot.getIndex(82); + if (equipmentSlot.getType() == EquipmentSlot.Type.ARMOR && !getSlot(armorSlotId).hasItem()) { + if (!moveItemStackTo(oldStack, armorSlotId, armorSlotId + 1, false)) { + + // try hotbar + if (!moveItemStackTo(oldStack, 73, 82, false)) { + + // try player inv + if (!moveItemStackTo(oldStack, 46, 73, true)) { + return ItemStack.EMPTY; + } + } + } + } else { + + // try hotbar + if (!moveItemStackTo(oldStack, 73, 82, false)) { + + // try player inv + if (!moveItemStackTo(oldStack, 46, 73, true)) { + return ItemStack.EMPTY; + } + } + } + + } else if (index <= 72) { // moving out of player inv (46-72) -> backpack inv, then hotbar + + // try backpack inv + if (!moveItemStackTo(oldStack, 10, 46, false)) { + + // try hotbar + if (!moveItemStackTo(oldStack, 73, 82, true)) { + return ItemStack.EMPTY; + } + } + + } else if (index <= 81) { // moving out of hotbar (73-81) -> backpack inv, then player inv + + // try backpack inv + if (!moveItemStackTo(oldStack, 10, 46, false)) { + + // try player inv + if (!moveItemStackTo(oldStack, 46, 73, false)) { + return ItemStack.EMPTY; + } + } + + } else if (index <= 86) { // moving out of armor items (82-85) or offhand (86) -> backpack inv, then player inv, then hotbar + + // try backpack inv + if (!moveItemStackTo(oldStack, 10, 46, false)) { + + // try player inv + if (!moveItemStackTo(oldStack, 46, 73, false)) { + + // try hotbar + if (!moveItemStackTo(oldStack, 73, 82, true)) { + return ItemStack.EMPTY; + } + } + } + + } else { + // crash the game so we get bug reports + throw new IllegalArgumentException("[Cammies-Wearable-Backpacks] Tried to quick transfer out of Slot [" + index + "]; please report this to " + CamsBackpacks.getIssuesURL()); + } + + if (oldStack.isEmpty()) { + slot.setByPlayer(ItemStack.EMPTY); + } else { + slot.setChanged(); + } + + if (oldStack.getCount() == newStack.getCount()) { + return ItemStack.EMPTY; + } + + slot.onTake(player, oldStack); + + // can't put back into result slot, so drop remaining items + if (index == 0) { + player.drop(oldStack, false); + } + } + + return newStack; + } + + @Override + public void removed(Player player) { + super.removed(player); + levelAccess.execute((world, pos) -> { + if (!world.isClientSide() && !isBlockEntity) { + ItemStack stack = player.getItemBySlot(EquipmentSlot.CHEST); + CompoundTag tag = stack.getOrCreateTag(); + NonNullList inv = NonNullList.withSize(36, ItemStack.EMPTY); + + for (int i = 0; i < inventory.getContainerSize(); i++) + inv.set(i, inventory.getItem(i)); + + ContainerHelper.saveAllItems(tag, inv); + } + + clearContainer(player, craftingInv); + }); + } + + @Override + public boolean stillValid(Player player) { + return inventory.stillValid(player); + } + +} diff --git a/src/main/java/dev/cammiescorner/camsbackpacks/common/menu/slot/ArmorSlot.java b/src/main/java/dev/cammiescorner/camsbackpacks/common/menu/slot/ArmorSlot.java new file mode 100644 index 0000000..e71cbd6 --- /dev/null +++ b/src/main/java/dev/cammiescorner/camsbackpacks/common/menu/slot/ArmorSlot.java @@ -0,0 +1,53 @@ +package dev.cammiescorner.camsbackpacks.common.menu.slot; + +import com.mojang.datafixers.util.Pair; +import dev.cammiescorner.camsbackpacks.common.items.BackpackItem; +import dev.cammiescorner.camsbackpacks.core.mixin.accessor.InventoryMenuAccessor; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.InventoryMenu; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.enchantment.EnchantmentHelper; + +public class ArmorSlot extends Slot { + + private final EquipmentSlot equipmentSlot; + private final Player player; + + public ArmorSlot(Inventory playerInventory, int slotIndex, int x, int y, EquipmentSlot equipmentSlot, Player player) { + super(playerInventory, slotIndex, x, y); + this.equipmentSlot = equipmentSlot; + this.player = player; + } + + @Override + public void setByPlayer(ItemStack stack) { + InventoryMenuAccessor.camsbackpacks$callOnEquipItem(this.player, this.equipmentSlot, stack, this.getItem()); + super.setByPlayer(stack); + } + + @Override + public int getMaxStackSize() { + return 1; + } + + @Override + public boolean mayPlace(ItemStack stack) { + return equipmentSlot == Mob.getEquipmentSlotForItem(stack); + } + + @Override + public boolean mayPickup(Player playerEntity) { + ItemStack stack = getItem(); + return (stack.isEmpty() || playerEntity.isCreative() || !EnchantmentHelper.hasBindingCurse(stack)) && !(stack.getItem() instanceof BackpackItem) && super.mayPickup(playerEntity); + } + + @Override + public Pair getNoItemIcon() { + return Pair.of(InventoryMenu.BLOCK_ATLAS, InventoryMenuAccessor.camsbackpacks$getEmptySlotsTextures()[equipmentSlot.getIndex()]); + } +} diff --git a/src/main/java/dev/cammiescorner/camsbackpacks/common/menu/slot/OffhandSlot.java b/src/main/java/dev/cammiescorner/camsbackpacks/common/menu/slot/OffhandSlot.java new file mode 100644 index 0000000..bb08bcf --- /dev/null +++ b/src/main/java/dev/cammiescorner/camsbackpacks/common/menu/slot/OffhandSlot.java @@ -0,0 +1,32 @@ +package dev.cammiescorner.camsbackpacks.common.menu.slot; + +import com.mojang.datafixers.util.Pair; +import dev.cammiescorner.camsbackpacks.core.mixin.accessor.InventoryMenuAccessor; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.InventoryMenu; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; + +public class OffhandSlot extends Slot { + + private final Player player; + + public OffhandSlot(Inventory playerInventory, int slotIndex, int x, int y, Player player) { + super(playerInventory, slotIndex, x, y); + this.player = player; + } + + @Override + public void setByPlayer(ItemStack stack) { + InventoryMenuAccessor.camsbackpacks$callOnEquipItem(this.player, EquipmentSlot.OFFHAND, stack, this.getItem()); + super.setByPlayer(stack); + } + + @Override + public Pair getNoItemIcon() { + return Pair.of(InventoryMenu.BLOCK_ATLAS, InventoryMenu.EMPTY_ARMOR_SLOT_SHIELD); + } +} diff --git a/src/main/java/dev/cammiescorner/camsbackpacks/common/network/OpenBackpackScreenPacket.java b/src/main/java/dev/cammiescorner/camsbackpacks/common/network/OpenBackpackScreenPacket.java index 4105ef4..cdb80cb 100644 --- a/src/main/java/dev/cammiescorner/camsbackpacks/common/network/OpenBackpackScreenPacket.java +++ b/src/main/java/dev/cammiescorner/camsbackpacks/common/network/OpenBackpackScreenPacket.java @@ -1,7 +1,7 @@ package dev.cammiescorner.camsbackpacks.common.network; import dev.cammiescorner.camsbackpacks.CamsBackpacks; -import dev.cammiescorner.camsbackpacks.common.screen.BackpackScreenHandler; +import dev.cammiescorner.camsbackpacks.common.menu.BackpackMenu; import io.netty.buffer.Unpooled; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory; import net.minecraft.core.NonNullList; @@ -98,7 +98,7 @@ public Component getDisplayName() { @Override public AbstractContainerMenu createMenu(int syncId, Inventory playerInventory, Player player) { - return new BackpackScreenHandler(syncId, playerInventory, inventory, ContainerLevelAccess.create(player.level(), player.blockPosition()), player.blockPosition(), false); + return new BackpackMenu(syncId, playerInventory, inventory, ContainerLevelAccess.create(player.level(), player.blockPosition()), player.blockPosition(), false); } }); }); diff --git a/src/main/java/dev/cammiescorner/camsbackpacks/common/screen/BackpackScreenHandler.java b/src/main/java/dev/cammiescorner/camsbackpacks/common/screen/BackpackScreenHandler.java deleted file mode 100644 index c2ebf04..0000000 --- a/src/main/java/dev/cammiescorner/camsbackpacks/common/screen/BackpackScreenHandler.java +++ /dev/null @@ -1,181 +0,0 @@ -package dev.cammiescorner.camsbackpacks.common.screen; - -import com.mojang.datafixers.util.Pair; -import dev.cammiescorner.camsbackpacks.common.items.BackpackItem; -import dev.cammiescorner.camsbackpacks.core.mixin.accessor.CraftingMenuAccessor; -import dev.cammiescorner.camsbackpacks.core.mixin.accessor.InventoryMenuAccessor; -import dev.cammiescorner.camsbackpacks.core.registry.ModScreenHandlers; -import net.minecraft.core.BlockPos; -import net.minecraft.core.NonNullList; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.Container; -import net.minecraft.world.ContainerHelper; -import net.minecraft.world.SimpleContainer; -import net.minecraft.world.entity.EquipmentSlot; -import net.minecraft.world.entity.Mob; -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.*; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.enchantment.EnchantmentHelper; - -public class BackpackScreenHandler extends AbstractContainerMenu { - private final Player player; - private final Container inventory; - private final TransientCraftingContainer input; - private final ResultContainer result; - private final ContainerLevelAccess context; - public final boolean isBlockEntity; - public BlockPos blockPos; - - public BackpackScreenHandler(int syncId, Inventory playerInventory, BlockPos blockPos, boolean isBlockEntity) { - this(syncId, playerInventory, new SimpleContainer(36), ContainerLevelAccess.NULL, blockPos, isBlockEntity); - } - - public BackpackScreenHandler(int syncId, Inventory playerInventory, Container inventory, ContainerLevelAccess context, BlockPos blockPos, boolean isBlockEntity) { - super(ModScreenHandlers.BACKPACK_SCREEN_HANDLER, syncId); - checkContainerSize(inventory, 36); - this.player = playerInventory.player; - this.inventory = inventory; - this.input = new TransientCraftingContainer(this, 3, 3); - this.result = new ResultContainer(); - this.context = context; - this.blockPos = blockPos; - this.isBlockEntity = isBlockEntity; - inventory.startOpen(player); - - int y; - int x; - - // Backpack inventory - for (y = 0; y < 4; ++y) - for (x = 0; x < 9; ++x) - addSlot(new Slot(inventory, x + y * 9, 81 + x * 18, 18 + y * 18)); - - // Player inventory - for (y = 0; y < 3; ++y) - for (x = 0; x < 9; ++x) - addSlot(new Slot(playerInventory, x + y * 9 + 9, 81 + x * 18, 108 + y * 18)); - - // Player hotbar - for (y = 0; y < 9; ++y) - addSlot(new Slot(playerInventory, y, 81 + y * 18, 166)); - - final EquipmentSlot[] equipmentSlots = new EquipmentSlot[]{EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET}; - - // Player armour - for (y = 0; y < 4; ++y) { - final EquipmentSlot equipmentSlot = equipmentSlots[y]; - - addSlot(new Slot(playerInventory, 39 - y, 8, 51 + y * 18) { - @Override - public int getMaxStackSize() { - return 1; - } - - @Override - public boolean mayPlace(ItemStack stack) { - return equipmentSlot == Mob.getEquipmentSlotForItem(stack); - } - - @Override - public boolean mayPickup(Player playerEntity) { - ItemStack stack = getItem(); - return (stack.isEmpty() || playerEntity.isCreative() || !EnchantmentHelper.hasBindingCurse(stack)) && !(stack.getItem() instanceof BackpackItem) && super.mayPickup(playerEntity); - } - - @Override - public Pair getNoItemIcon() { - return Pair.of(InventoryMenu.BLOCK_ATLAS, InventoryMenuAccessor.camsbackpacks$getEmptySlotsTextures()[equipmentSlot.getIndex()]); - } - }); - } - - // Player offhand - this.addSlot(new Slot(playerInventory, 40, 8, 123) { - @Override - public Pair getNoItemIcon() { - return Pair.of(InventoryMenu.BLOCK_ATLAS, InventoryMenu.EMPTY_ARMOR_SLOT_SHIELD); - } - }); - - // Crafting table inventory - for (y = 0; y < 3; ++y) - for (x = 0; x < 3; ++x) - addSlot(new Slot(input, x + y * 3, 255 + x * 18, 46 + y * 18)); - - addSlot(new ResultSlot(player, input, result, 0, 273, 71 + 3 * 18)); - } - - @Override - public void slotsChanged(Container inventory) { - context.execute((world, pos) -> CraftingMenuAccessor.camsbackpacks$callSlotChangedCraftingGrid(this, world, player, input, result)); - } - - @Override - public ItemStack quickMoveStack(Player player, int index) { - ItemStack newStack = ItemStack.EMPTY; - Slot slot = this.slots.get(index); - - if (slot.hasItem()) { - ItemStack oldStack = slot.getItem(); - newStack = oldStack.copy(); - EquipmentSlot equipmentSlot = Mob.getEquipmentSlotForItem(newStack); - int armourSlotId = 75 - equipmentSlot.getIndex(); - - if (index < inventory.getContainerSize()) { - if (!moveItemStackTo(oldStack, inventory.getContainerSize(), slots.size() - 15, true)) - return ItemStack.EMPTY; - } else if (equipmentSlot.getType() == EquipmentSlot.Type.ARMOR && !slots.get(armourSlotId).hasItem()) { - if (!this.moveItemStackTo(oldStack, armourSlotId, armourSlotId + 1, false)) - return ItemStack.EMPTY; - } else if (equipmentSlot == EquipmentSlot.OFFHAND && !slots.get(76).hasItem()) { - if (!this.moveItemStackTo(oldStack, 76, 77, false)) - return ItemStack.EMPTY; - } else if (index == 0) { - if (!moveItemStackTo(oldStack, 0, inventory.getContainerSize() + player.getInventory().getContainerSize(), false)) - return ItemStack.EMPTY; - } else if (!moveItemStackTo(oldStack, 0, inventory.getContainerSize(), false)) { - return ItemStack.EMPTY; - } - - - if (oldStack.isEmpty()) - slot.setByPlayer(ItemStack.EMPTY); - else - slot.setChanged(); - - if (oldStack.getCount() == newStack.getCount()) - return ItemStack.EMPTY; - - slot.onTake(player, oldStack); - } - - return newStack; - } - - @Override - public void removed(Player player) { - super.removed(player); - context.execute((world, pos) -> { - if (!world.isClientSide() && !isBlockEntity) { - ItemStack stack = player.getItemBySlot(EquipmentSlot.CHEST); - CompoundTag tag = stack.getOrCreateTag(); - NonNullList inv = NonNullList.withSize(36, ItemStack.EMPTY); - - for (int i = 0; i < inventory.getContainerSize(); i++) - inv.set(i, inventory.getItem(i)); - - ContainerHelper.saveAllItems(tag, inv); - } - - clearContainer(player, input); - }); - } - - @Override - public boolean stillValid(Player player) { - return inventory.stillValid(player); - } -} diff --git a/src/main/java/dev/cammiescorner/camsbackpacks/core/mixin/accessor/InventoryMenuAccessor.java b/src/main/java/dev/cammiescorner/camsbackpacks/core/mixin/accessor/InventoryMenuAccessor.java index 443cbb0..a8ca82f 100644 --- a/src/main/java/dev/cammiescorner/camsbackpacks/core/mixin/accessor/InventoryMenuAccessor.java +++ b/src/main/java/dev/cammiescorner/camsbackpacks/core/mixin/accessor/InventoryMenuAccessor.java @@ -1,9 +1,13 @@ package dev.cammiescorner.camsbackpacks.core.mixin.accessor; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.InventoryMenu; +import net.minecraft.world.item.ItemStack; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; +import org.spongepowered.asm.mixin.gen.Invoker; @Mixin(InventoryMenu.class) public interface InventoryMenuAccessor { @@ -11,4 +15,9 @@ public interface InventoryMenuAccessor { static ResourceLocation[] camsbackpacks$getEmptySlotsTextures() { throw new UnsupportedOperationException(); } + + @Invoker("onEquipItem") + static void camsbackpacks$callOnEquipItem(Player player, EquipmentSlot slot, ItemStack newItem, ItemStack oldItem) { + throw new UnsupportedOperationException(); + } } diff --git a/src/main/java/dev/cammiescorner/camsbackpacks/core/registry/ModScreenHandlers.java b/src/main/java/dev/cammiescorner/camsbackpacks/core/registry/ModScreenHandlers.java index aa91c74..436eaba 100644 --- a/src/main/java/dev/cammiescorner/camsbackpacks/core/registry/ModScreenHandlers.java +++ b/src/main/java/dev/cammiescorner/camsbackpacks/core/registry/ModScreenHandlers.java @@ -1,7 +1,7 @@ package dev.cammiescorner.camsbackpacks.core.registry; import dev.cammiescorner.camsbackpacks.CamsBackpacks; -import dev.cammiescorner.camsbackpacks.common.screen.BackpackScreenHandler; +import dev.cammiescorner.camsbackpacks.common.menu.BackpackMenu; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerType; import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; @@ -9,7 +9,7 @@ public class ModScreenHandlers { - public static final MenuType BACKPACK_SCREEN_HANDLER = new ExtendedScreenHandlerType<>((syncId, inventory, buf) -> new BackpackScreenHandler(syncId, inventory, buf.readBlockPos(), buf.readBoolean())); + public static final MenuType BACKPACK_SCREEN_HANDLER = new ExtendedScreenHandlerType<>((syncId, inventory, buf) -> new BackpackMenu(syncId, inventory, buf.readBlockPos(), buf.readBoolean())); public static void register() { Registry.register(BuiltInRegistries.MENU, CamsBackpacks.id("backpack"), BACKPACK_SCREEN_HANDLER);