diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackInventory.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackInventory.java index 4a3af1e..6039642 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackInventory.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackInventory.java @@ -10,11 +10,9 @@ import net.minecraft.util.collection.DefaultedList; public class BackpackInventory implements Inventory { public static final int SECTION_SIZE = 9; private final DefaultedList stacks; - public final PlayerEntity accessor; private BackpackScreenHandler container; - public BackpackInventory(BackpackScreenHandler container, PlayerEntity player) { - this.accessor = player; + public BackpackInventory(BackpackScreenHandler container) { this.stacks = DefaultedList.ofSize(SECTION_SIZE * ItemBackpack.SLOTSIZE, ItemStack.EMPTY); this.container = container; } diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackScreen.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackScreen.java index aa0bfb4..e51b17a 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackScreen.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackScreen.java @@ -19,17 +19,12 @@ public class BackpackScreen extends HandledScreen impleme private final static Identifier TEXTURE = new Identifier(RegistryManager.QUICKIEFABRIC, "textures/gui/backpack.png"); private final static Identifier SLOT_TEXTURE = new Identifier(RegistryManager.QUICKIEFABRIC, "textures/gui/slot.png"); private int slots; - private Integer containerHeight; - private Integer containerWidth; + private final Integer containerHeight = 222; + private final Integer containerWidth = 176; public BackpackScreen(BackpackScreenHandler handler, PlayerInventory inventory, Text text) { super(handler, inventory, new TranslatableText("container.quickiefabric.backpack")); slots = ItemBackpack.SLOTSIZE; - if ((slots / 9) == 4) { - this.containerHeight = 184; - } else if ((slots / 9) > 4) { - this.containerHeight = 222; - } } @Override diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackScreenHandler.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackScreenHandler.java index 557f6cb..1d9ff46 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackScreenHandler.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/container/BackpackScreenHandler.java @@ -13,114 +13,116 @@ import net.minecraft.util.Hand; import net.minecraft.util.collection.DefaultedList; public class BackpackScreenHandler extends ScreenHandler { - - private final BackpackInventory inv; - private final PlayerEntity player; - private int backpackSlots; - private Hand hand; - - public BackpackScreenHandler(int syncId, PlayerInventory playerInv) { - super(RegistryManager.BACKPACK_SCREEN_HANDLER, syncId); - this.inv = new BackpackInventory(this, playerInv.player); - this.player = playerInv.player; - this.hand = player.getActiveHand(); - backpackSlots = ItemBackpack.SLOTSIZE; - int spacing; - if(backpackSlots % 9 == 0) - spacing = 30 + (backpackSlots /9) * 18 + ((backpackSlots /9) < 5 ? 0 : 2); - else - spacing = 30 + (backpackSlots /9 + 1) * 18 + ((backpackSlots /9) < 5 ? 0 : 2); + private final BackpackInventory backpackInventory; + private final PlayerEntity player; + private int backpackSlots; + private Hand hand; - for(int y = 0; y < (backpackSlots /9); y++) { - for(int x = 0; x < 9; ++x) { - this.addSlot(new Slot(inv, x + y * 9, 8 + x * 18, 18 + y * 18)); - } - } - if((backpackSlots % 9) != 0) - for(int x = 0; x < (backpackSlots % 9); x++) { - this.addSlot(new Slot(inv, x + (backpackSlots /9) * 9, 8 + x * 18, 18 + (backpackSlots /9) * 18)); - } + public BackpackScreenHandler(int syncId, PlayerInventory playerInventory) { + super(RegistryManager.BACKPACK_SCREEN_HANDLER, syncId); + this.player = playerInventory.player; + this.backpackInventory = new BackpackInventory(this); + backpackSlots = ItemBackpack.SLOTSIZE; + int spacing; + if (backpackSlots % 9 == 0) { + spacing = 30 + (backpackSlots / 9) * 18 + ((backpackSlots / 9) < 5 ? 0 : 2); + } else { + spacing = 30 + (backpackSlots / 9 + 1) * 18 + ((backpackSlots / 9) < 5 ? 0 : 2); + } + for (int y = 0; y < (backpackSlots / 9); y++) { + for (int x = 0; x < 9; ++x) { + this.addSlot(new Slot(backpackInventory, x + y * 9, 8 + x * 18, 18 + y * 18)); + } + } + if ((backpackSlots % 9) != 0) { + for (int x = 0; x < (backpackSlots % 9); x++) { + this.addSlot( + new Slot(backpackInventory, x + (backpackSlots / 9) * 9, 8 + x * 18, 18 + (backpackSlots / 9) * 18)); + } + for (int y = 0; y < 3; ++y) { + for (int x = 0; x < 9; ++x) { + this.addSlot(new Slot(playerInventory, x + y * 9 + 9, 8 + x * 18, spacing + y * 18)); + } + } + for (int x = 0; x < 9; ++x) { + this.addSlot(new Slot(playerInventory, x, 8 + x * 18, 58 + spacing)); + } + } + } - for(int y = 0; y < 3; ++y) { - for(int x = 0; x < 9; ++x) { - this.addSlot(new Slot(playerInv, x + y * 9 + 9, 8 + x * 18, spacing + y * 18)); - } - } + @Override + public boolean canUse(PlayerEntity player) { + return true; + } - for(int x = 0; x < 9; ++x) { - this.addSlot(new Slot(playerInv, x, 8 + x * 18, 58 + spacing)); - } + public void onContentChanged(Inventory inv) { + super.onContentChanged(inv); + if (inv == this.backpackInventory) { + this.updateInv(); + } + } - DefaultedList ad = DefaultedList.ofSize(backpackSlots, ItemStack.EMPTY); - ItemBackpack.getInventory(player.getStackInHand(this.hand), ad); - if(ad.size() == 0) - return; + public void close(PlayerEntity player) { + super.close(player); + this.backpackInventory.onClose(player); + } - for(int x = 0; x < 9; x++) - for(int y = 0; y < backpackSlots /9; y++) { - this.getSlot(x + y * 9).setStack(ad.get(x+y*9)); - } + public void updateInv() { + this.sendContentUpdates(); + } - for(int x = 0; x < (backpackSlots % 9); x++) { - this.getSlot(x + (backpackSlots /9)*9).setStack(ad.get(x+(backpackSlots /9)*9)); - } + @Override + public ItemStack transferSlot(PlayerEntity player, int slotNum) { + ItemStack copy = ItemStack.EMPTY; + Slot clickedSlot = this.slots.get(slotNum); + if (clickedSlot != null && clickedSlot.hasStack()) { + ItemStack clickedStack = clickedSlot.getStack(); + copy = clickedStack.copy(); + if (slotNum < backpackSlots) { + if (!this.insertItem(clickedStack, backpackSlots, this.slots.size(), true)) { + return ItemStack.EMPTY; + } + } else if (!this.insertItem(clickedStack, 0, backpackSlots, false)) { + return ItemStack.EMPTY; + } - } - - @Override - public boolean canUse(PlayerEntity player) { - return true; - } + if (clickedStack.isEmpty()) { + clickedSlot.setStack(ItemStack.EMPTY); + } else { + clickedSlot.markDirty(); + } + } - public void onContentChanged(Inventory inv) { - super.onContentChanged(inv); - if (inv == this.inv) { - this.updateInv(); - } - } + return copy; + } - public void close(PlayerEntity player) { - super.close(player); - this.inv.onClose(player); - } + @Override + public ItemStack onSlotClick(int i, int j, SlotActionType slotActionType, PlayerEntity playerEntity) { + if (i > 0) { + if (this.getSlot(i).getStack().equals(playerEntity.getStackInHand(hand))) { + return ItemStack.EMPTY; + } + } + return super.onSlotClick(i, j, slotActionType, playerEntity); + } - public void updateInv() { - this.sendContentUpdates(); - } - - @Override - public ItemStack transferSlot(PlayerEntity player, int slotNum) { - ItemStack copy = ItemStack.EMPTY; - Slot clickedSlot = this.slots.get(slotNum); - if (clickedSlot != null && clickedSlot.hasStack()) { - ItemStack clickedStack = clickedSlot.getStack(); - copy = clickedStack.copy(); - if (slotNum < backpackSlots) { - if (!this.insertItem(clickedStack, backpackSlots, this.slots.size(), true)) { - return ItemStack.EMPTY; - } - } else if (!this.insertItem(clickedStack, 0, backpackSlots, false)) { - return ItemStack.EMPTY; - } - - if (clickedStack.isEmpty()) { - clickedSlot.setStack(ItemStack.EMPTY); - } else { - clickedSlot.markDirty(); - } - } - - return copy; - } - - @Override - public ItemStack onSlotClick(int int_1, int int_2, SlotActionType slotActionType_1, PlayerEntity playerEntity_1) { - if(int_1 > 0) { - if (this.getSlot(int_1).getStack().equals(playerEntity_1.getStackInHand(hand))) - return ItemStack.EMPTY; - } - return super.onSlotClick(int_1, int_2, slotActionType_1, playerEntity_1); - } + public BackpackScreenHandler withHand(Hand hand) { + this.hand = hand; + DefaultedList ad = DefaultedList.ofSize(backpackSlots, ItemStack.EMPTY); + ItemBackpack.getInventory(player.getStackInHand(this.hand), ad); + if (ad.size() == 0) { + return this; + } + for (int x = 0; x < 9; x++) { + for (int y = 0; y < backpackSlots / 9; y++) { + this.getSlot(x + y * 9).setStack(ad.get(x + y * 9)); + } + } + for (int x = 0; x < (backpackSlots % 9); x++) { + this.getSlot(x + (backpackSlots / 9) * 9).setStack(ad.get(x + (backpackSlots / 9) * 9)); + } + return this; + } } diff --git a/src/main/java/de/jottyfan/minecraft/quickiefabric/items/ItemBackpack.java b/src/main/java/de/jottyfan/minecraft/quickiefabric/items/ItemBackpack.java index 6c9c009..0112239 100644 --- a/src/main/java/de/jottyfan/minecraft/quickiefabric/items/ItemBackpack.java +++ b/src/main/java/de/jottyfan/minecraft/quickiefabric/items/ItemBackpack.java @@ -41,7 +41,7 @@ public class ItemBackpack extends Item implements DyeableItem { LOGGER.info("found registered screen {}", id.toString()); } SimpleNamedScreenHandlerFactory factory = new SimpleNamedScreenHandlerFactory( - (id, inventory, buf) -> new BackpackScreenHandler(id, player.inventory), + (id, inventory, buf) -> new BackpackScreenHandler(id, player.inventory).withHand(hand), Text.method_30163(RegistryManager.BACKPACK_CONTAINTER.toString())); player.openHandledScreen(factory); } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 4b6c2aa..7e68e6f 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -1,36 +1,36 @@ { - "schemaVersion": 1, - "id": "quickiefabric", - "version": "${version}", - - "name": "quickiefabric", - "description": "Quickiefabric is the fabric implementation of Quickie, a mot to speed up daily work in Minecraft.", - "authors": [ - "Jottyfan" - ], - "contact": { - "homepage": "https://gitlab.com/jottyfan/quickiefabric", - "sources": "https://gitlab.com/jottyfan/quickiefabric" - }, - - "license": "MIT", - "icon": "assets/quickiefabric/icon.png", - - "environment": "*", - "entrypoints": { - "main": [ - "de.jottyfan.minecraft.quickiefabric.QuickieFabric" - ] - }, - "mixins": [ - "quickiefabric.mixins.json" - ], - "depends": { - "fabricloader": ">=0.7.4", - "fabric": "*", - "minecraft": "1.16.x" - }, - "suggests": { - "flamingo": "*" - } + "schemaVersion": 1, + "id": "quickiefabric", + "version": "${version}", + "name": "quickiefabric", + "description": "Quickiefabric is the fabric implementation of Quickie, a mot to speed up daily work in Minecraft.", + "authors": [ + "Jottyfan" + ], + "contact": { + "homepage": "https://gitlab.com/jottyfan/quickiefabric", + "sources": "https://gitlab.com/jottyfan/quickiefabric" + }, + "license": "MIT", + "icon": "assets/quickiefabric/icon.png", + "environment": "*", + "entrypoints": { + "main": [ + "de.jottyfan.minecraft.quickiefabric.QuickieFabric" + ], + "client": [ + "de.jottyfan.minecraft.quickiefabric.QuickieFabricClient" + ] + }, + "mixins": [ + "quickiefabric.mixins.json" + ], + "depends": { + "fabricloader": ">=0.7.4", + "fabric": "*", + "minecraft": "1.16.x" + }, + "suggests": { + "flamingo": "*" + } }