From 4eb87b6c2e30b58dc23ef0649c20f88288e9f29a Mon Sep 17 00:00:00 2001 From: wendavid552 Date: Thu, 23 Feb 2023 11:29:33 +0800 Subject: [PATCH] Backport to 1.16.x. --- gradle.properties | 12 +- .../event/RenderEventHandler.java | 74 ++++++---- .../mixin/MixinCraftingScreenHandler.java | 7 +- .../dy/masa/itemscroller/util/InputUtils.java | 8 +- .../itemscroller/util/InventoryUtils.java | 131 ++++++++++-------- .../dy/masa/itemscroller/util/ItemType.java | 4 +- .../villager/VillagerDataStorage.java | 2 +- src/main/resources/fabric.mod.json | 3 +- 8 files changed, 135 insertions(+), 106 deletions(-) diff --git a/gradle.properties b/gradle.properties index d2457c999..64e17ecee 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,12 +15,12 @@ mod_file_name = itemscroller-fabric mod_version = craftaddon-1.0.0 # Required malilib version -malilib_version = 0.12.0 +malilib_version = 0.10.0-dev.21+arne.8 # Minecraft, Fabric and mappings versions -minecraft_version_out = 1.18.2 -minecraft_version = 1.18.2 -mappings_version = 1.18.2+build.1 +minecraft_version_out = 1.16.5 +minecraft_version = 1.16.5 +mappings_version = 1.16.5+build.10 -fabric_loader_version = 0.14.14 -mod_menu_version = 3.1.0 +fabric_loader_version = 0.11.7 +mod_menu_version = 1.16.23 diff --git a/src/main/java/fi/dy/masa/itemscroller/event/RenderEventHandler.java b/src/main/java/fi/dy/masa/itemscroller/event/RenderEventHandler.java index 428c50c5b..3cf70975c 100644 --- a/src/main/java/fi/dy/masa/itemscroller/event/RenderEventHandler.java +++ b/src/main/java/fi/dy/masa/itemscroller/event/RenderEventHandler.java @@ -1,16 +1,22 @@ package fi.dy.masa.itemscroller.event; +import java.nio.FloatBuffer; +import org.lwjgl.opengl.GL11; +import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.render.DiffuseLighting; +import net.minecraft.client.util.GlAllocationUtils; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.ItemStack; +import net.minecraft.util.math.Vec3d; import fi.dy.masa.itemscroller.config.Configs; import fi.dy.masa.itemscroller.recipes.RecipePattern; import fi.dy.masa.itemscroller.recipes.RecipeStorage; import fi.dy.masa.itemscroller.util.AccessorUtils; +import fi.dy.masa.itemscroller.util.ClickPacketBuffer; import fi.dy.masa.itemscroller.util.InputUtils; import fi.dy.masa.itemscroller.util.InventoryUtils; import fi.dy.masa.malilib.render.InventoryOverlay; @@ -21,6 +27,9 @@ public class RenderEventHandler { private static final RenderEventHandler INSTANCE = new RenderEventHandler(); + private static final Vec3d LIGHT0_POS = (new Vec3d( 0.2D, 1.0D, -0.7D)).normalize(); + private static final Vec3d LIGHT1_POS = (new Vec3d(-0.2D, 1.0D, 0.7D)).normalize(); + private static final FloatBuffer FLOAT_BUFFER = GlAllocationUtils.allocateFloatBuffer(4); private static final MatrixStack FRESH_MATRIX_STACK = new MatrixStack(); private final MinecraftClient mc = MinecraftClient.getInstance(); @@ -51,11 +60,9 @@ public void onDrawBackgroundPost(MatrixStack matrixStack) this.calculateRecipePositions(gui); - matrixStack = RenderSystem.getModelViewStack(); - matrixStack.push(); - matrixStack.translate(this.recipeListX, this.recipeListY, 0); - matrixStack.scale((float) this.scale, (float) this.scale, 1); - RenderSystem.applyModelViewMatrix(); + RenderSystem.pushMatrix(); + RenderSystem.translatef(this.recipeListX, this.recipeListY, 0); + RenderSystem.scaled(this.scale, this.scale, 1); String str = StringUtils.translate("itemscroller.gui.label.recipe_page", (first / countPerPage) + 1, recipes.getTotalRecipeCount() / countPerPage); this.mc.textRenderer.draw(matrixStack, str, 16, -12, 0xC0C0C0C0); @@ -80,8 +87,7 @@ public void onDrawBackgroundPost(MatrixStack matrixStack) this.renderRecipeItems(recipe, recipes.getRecipeCountPerPage(), gui); } - matrixStack.pop(); - RenderSystem.applyModelViewMatrix(); + RenderSystem.popMatrix(); RenderSystem.enableBlend(); // Fixes the crafting book icon rendering } } @@ -92,6 +98,13 @@ public void onDrawScreenPost(MinecraftClient mc) { HandledScreen gui = (HandledScreen) this.mc.currentScreen; + int bufferedCount = ClickPacketBuffer.getBufferedActionsCount(); + + if (bufferedCount > 0) + { + mc.textRenderer.draw(FRESH_MATRIX_STACK, "Buffered slot clicks: " + bufferedCount, 10, 10, 0xFFD0D0D0); + } + if (InputUtils.isRecipeViewOpen() == false) { return; @@ -104,9 +117,8 @@ public void onDrawScreenPost(MinecraftClient mc) final int recipeId = this.getHoveredRecipeId(mouseX, mouseY, recipes, gui); float offset = 300f; - MatrixStack matrixStack = RenderSystem.getModelViewStack(); - matrixStack.push(); - matrixStack.translate(0, 0, offset); + RenderSystem.pushMatrix(); + RenderSystem.translatef(0f, 0f, offset); if (recipeId >= 0) { @@ -124,8 +136,7 @@ else if (Configs.Generic.CRAFTING_RENDER_RECIPE_ITEMS.getBooleanValue()) } } - matrixStack.pop(); - RenderSystem.applyModelViewMatrix(); + RenderSystem.popMatrix(); } } @@ -209,18 +220,17 @@ private void renderStoredRecipeStack(ItemStack stack, int recipeId, int row, int int y = row * this.entryHeight; this.renderStackAt(stack, x, y, selected); - float scale = 0.75F; + double scale = 0.75; x = x - (int) (font.getWidth(indexStr) * scale) - 2; y = row * this.entryHeight + this.entryHeight / 2 - font.fontHeight / 2; - matrixStack = FRESH_MATRIX_STACK; - matrixStack.push(); - matrixStack.translate(x, y, 0); - matrixStack.scale(scale, scale, 1); + RenderSystem.pushMatrix(); + RenderSystem.translatef(x, y, 0); + RenderSystem.scaled(scale, scale, 0); - font.draw(matrixStack, indexStr, 0, 0, 0xFFC0C0C0); + font.draw(matrixStack, indexStr, 0, 0, 0xC0C0C0); - matrixStack.pop(); + RenderSystem.popMatrix(); } private void renderRecipeItems(RecipePattern recipe, int recipeCountPerPage, HandledScreen gui) @@ -232,7 +242,7 @@ private void renderRecipeItems(RecipePattern recipe, int recipeCountPerPage, Han for (int i = 0, row = 0; row < recipeDimensions; row++) { - for (int col = 0; col < recipeDimensions && i < recipe.getRecipeLength(); col++, i++) + for (int col = 0; col < recipeDimensions; col++, i++) { int xOff = col * 17; int yOff = row * 17; @@ -255,7 +265,7 @@ private ItemStack getHoveredRecipeIngredient(int mouseX, int mouseY, RecipePatte { for (int i = 0, row = 0; row < recipeDimensions; row++) { - for (int col = 0; col < recipeDimensions && i < recipe.getRecipeLength(); col++, i++) + for (int col = 0; col < recipeDimensions; col++, i++) { int xOff = col * scaledGridEntry; int yOff = row * scaledGridEntry; @@ -276,15 +286,25 @@ private ItemStack getHoveredRecipeIngredient(int mouseX, int mouseY, RecipePatte private void renderStackAt(ItemStack stack, int x, int y, boolean border) { + RenderSystem.pushMatrix(); + final int w = 16; if (border) { // Draw a light/white border around the stack - RenderUtils.drawOutline(x - 1, y - 1, w + 2, w + 2, 0xFFFFFFFF); - } + RenderUtils.drawRect(x - 1, y - 1, w + 1, 1 , 0xFFFFFFFF); + RenderUtils.drawRect(x - 1, y , 1 , w + 1, 0xFFFFFFFF); + RenderUtils.drawRect(x + w, y - 1, 1 , w + 1, 0xFFFFFFFF); + RenderUtils.drawRect(x , y + w, w + 1, 1 , 0xFFFFFFFF); - RenderUtils.drawRect(x, y, w, w, 0x20FFFFFF); // light background for the item + RenderUtils.drawRect(x, y, w, w, 0x20FFFFFF); // light background for the item + + } + else + { + RenderUtils.drawRect(x, y, w, w, 0x20FFFFFF); // light background for the item + } if (InventoryUtils.isStackEmpty(stack) == false) { @@ -296,9 +316,10 @@ private void renderStackAt(ItemStack stack, int x, int y, boolean border) this.mc.getItemRenderer().renderInGui(stack, x, y); this.mc.getItemRenderer().zOffset -= 100; } + + RenderSystem.popMatrix(); } - /* public static void enableGUIStandardItemLighting(float scale) { RenderSystem.pushMatrix(); @@ -344,5 +365,4 @@ private static FloatBuffer singletonBuffer(float val1, float val2, float val3, f return FLOAT_BUFFER; } - */ -} +} \ No newline at end of file diff --git a/src/main/java/fi/dy/masa/itemscroller/mixin/MixinCraftingScreenHandler.java b/src/main/java/fi/dy/masa/itemscroller/mixin/MixinCraftingScreenHandler.java index 2e57298d6..f002a3804 100644 --- a/src/main/java/fi/dy/masa/itemscroller/mixin/MixinCraftingScreenHandler.java +++ b/src/main/java/fi/dy/masa/itemscroller/mixin/MixinCraftingScreenHandler.java @@ -27,12 +27,7 @@ private void onSlotChangedCraftingGrid(net.minecraft.inventory.Inventory invento @Inject(method = "updateResult", at = @At("RETURN")) private static void onUpdateResult( - ScreenHandler screenHandler, - World world, - PlayerEntity player, - CraftingInventory craftingInv, - CraftingResultInventory resultInv, - CallbackInfo ci) + int syncId, World world, PlayerEntity player, CraftingInventory craftingInventory, CraftingResultInventory resultInventory, CallbackInfo ci) { //InventoryUtils.onSlotChangedCraftingGrid(player, craftingInv, resultInv); } diff --git a/src/main/java/fi/dy/masa/itemscroller/util/InputUtils.java b/src/main/java/fi/dy/masa/itemscroller/util/InputUtils.java index c955513c4..7cff43ab1 100644 --- a/src/main/java/fi/dy/masa/itemscroller/util/InputUtils.java +++ b/src/main/java/fi/dy/masa/itemscroller/util/InputUtils.java @@ -21,7 +21,7 @@ public static boolean isRecipeViewOpen() public static boolean canShiftDropItems(HandledScreen gui, MinecraftClient mc, int mouseX, int mouseY) { - if (InventoryUtils.isStackEmpty(gui.getScreenHandler().getCursorStack()) == false) + if (InventoryUtils.isStackEmpty(mc.player.inventory.getCursorStack()) == false) { int left = AccessorUtils.getGuiLeft(gui); int top = AccessorUtils.getGuiTop(gui); @@ -127,16 +127,16 @@ public static MoveAmount getMoveAmount(MoveAction action) public static boolean isAttack(int keyCode) { - return keyCode == KeybindMulti.getKeyCode(MinecraftClient.getInstance().options.attackKey); + return keyCode == KeybindMulti.getKeyCode(MinecraftClient.getInstance().options.keyAttack); } public static boolean isUse(int keyCode) { - return keyCode == KeybindMulti.getKeyCode(MinecraftClient.getInstance().options.useKey); + return keyCode == KeybindMulti.getKeyCode(MinecraftClient.getInstance().options.keyUse); } public static boolean isPickBlock(int keyCode) { - return keyCode == KeybindMulti.getKeyCode(MinecraftClient.getInstance().options.pickItemKey); + return keyCode == KeybindMulti.getKeyCode(MinecraftClient.getInstance().options.keyPickItem); } } diff --git a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java index 6291804d6..e692d7e64 100644 --- a/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java +++ b/src/main/java/fi/dy/masa/itemscroller/util/InventoryUtils.java @@ -74,7 +74,7 @@ public static String getStackString(ItemStack stack) { Identifier rl = Registry.ITEM.getId(stack.getItem()); String idStr = rl != null ? rl.toString() : "null"; String displayName = stack.getName().getString(); - String nbtStr = stack.getNbt() != null ? stack.getNbt().toString() : ""; + String nbtStr = stack.getTag() != null ? stack.getTag().toString() : ""; return String.format("[%s - display: %s - NBT: %s] (%s)", idStr, displayName, nbtStr, stack); } @@ -128,7 +128,8 @@ private static boolean inventoryExistsAbove(Slot slot, ScreenHandler container) public static boolean canShiftPlaceItems(HandledScreen gui) { Slot slot = AccessorUtils.getSlotUnderMouse(gui); - ItemStack stackCursor = gui.getScreenHandler().getCursorStack(); + MinecraftClient mc = MinecraftClient.getInstance(); + ItemStack stackCursor = mc.player.inventory.getCursorStack(); // The target slot needs to be an empty, valid slot, and there needs to be items // in the cursor @@ -140,9 +141,9 @@ public static boolean tryMoveItems(HandledScreen gui, RecipeStorage recipes, boolean scrollingUp) { Slot slot = AccessorUtils.getSlotUnderMouse(gui); - + MinecraftClient mc = MinecraftClient.getInstance(); // We require an empty cursor - if (slot == null || isStackEmpty(gui.getScreenHandler().getCursorStack()) == false) { + if (slot == null || isStackEmpty(mc.player.inventory.getCursorStack()) == false) { return false; } @@ -221,7 +222,8 @@ else if (getStackSize(stack) < slot.getMaxItemCount(stack)) { public static boolean dragMoveItems(HandledScreen gui, MoveAction action, int mouseX, int mouseY, boolean isClick) { - if (isStackEmpty(gui.getScreenHandler().getCursorStack()) == false) { + MinecraftClient mc = MinecraftClient.getInstance(); + if (isStackEmpty(mc.player.inventory.getCursorStack()) == false) { // Updating these here is part of the fix to preventing a drag after shift + // place lastPosX = mouseX; @@ -524,7 +526,8 @@ public static void dropAllMatchingStacks(HandledScreen } public static boolean shiftDropItems(HandledScreen gui) { - ItemStack stackReference = gui.getScreenHandler().getCursorStack(); + MinecraftClient mc = MinecraftClient.getInstance(); + ItemStack stackReference = mc.player.inventory.getCursorStack(); if (isStackEmpty(stackReference) == false && sourceSlot != null) { stackReference = stackReference.copy(); @@ -560,7 +563,8 @@ public static boolean shiftPlaceItems(Slot slot, HandledScreen gui) { // Left or right mouse button was pressed if (slot != null) { - ItemStack stackCursor = gui.getScreenHandler().getCursorStack(); + MinecraftClient mc = MinecraftClient.getInstance(); + ItemStack stackCursor = mc.player.inventory.getCursorStack(); ItemStack stack = EMPTY_STACK; if (isStackEmpty(stackCursor) == false) { @@ -583,7 +587,8 @@ public static void storeSourceSlotCandidate(Slot slot, HandledScreen gui) { * the cursor */ public static void checkForItemPickup(HandledScreen gui) { - ItemStack stackCursor = gui.getScreenHandler().getCursorStack(); + MinecraftClient mc = MinecraftClient.getInstance(); + ItemStack stackCursor = mc.player.inventory.getCursorStack(); // Picked up or swapped items to the cursor, grab a reference to the slot that // the items came from @@ -696,7 +701,7 @@ private static boolean tryMoveSingleItemToOtherInventory(Slot slot, ScreenHandler container = gui.getScreenHandler(); MinecraftClient mc = MinecraftClient.getInstance(); - if (isStackEmpty(gui.getScreenHandler().getCursorStack()) == false || slot.canTakeItems(mc.player) == false + if (isStackEmpty(mc.player.inventory.getCursorStack()) == false || slot.canTakeItems(mc.player) == false || (getStackSize(stackOrig) > 1 && slot.canInsert(stackOrig) == false)) { return false; } @@ -754,7 +759,7 @@ private static boolean tryMoveAllButOneItemToOtherInventory(Slot slot, // Take half of the items from the original slot to the cursor rightClickSlot(gui, slot.id); - ItemStack stackInCursor = gui.getScreenHandler().getCursorStack(); + ItemStack stackInCursor = mc.player.inventory.getCursorStack(); if (isStackEmpty(stackInCursor)) { return false; } @@ -772,7 +777,7 @@ private static boolean tryMoveAllButOneItemToOtherInventory(Slot slot, // Try to put one item into the temporary slot rightClickSlot(gui, slotTmp.id); - stackInCursor = gui.getScreenHandler().getCursorStack(); + stackInCursor = mc.player.inventory.getCursorStack(); // Successfully stored one item if (isStackEmpty(stackInCursor) || getStackSize(stackInCursor) < stackInCursorSizeOrig) { @@ -783,7 +788,7 @@ private static boolean tryMoveAllButOneItemToOtherInventory(Slot slot, } } - if (isStackEmpty(gui.getScreenHandler().getCursorStack()) == false) { + if (isStackEmpty(mc.player.inventory.getCursorStack()) == false) { // Return the rest of the items into the original slot leftClickSlot(gui, slot.id); } @@ -800,7 +805,7 @@ private static boolean tryMoveAllButOneItemToOtherInventory(Slot slot, rightClickSlot(gui, slot.id); // Return the rest of the items to the temporary slot, if any - if (isStackEmpty(gui.getScreenHandler().getCursorStack()) == false) { + if (isStackEmpty(mc.player.inventory.getCursorStack()) == false) { leftClickSlot(gui, tempSlotNum); } @@ -828,7 +833,7 @@ private static boolean tryMoveAllButOneItemToOtherInventory(Slot slot, // a different inventory for (int slotNum : slots) { Slot slotTmp = gui.getScreenHandler().getSlot(slotNum); - stackInCursor = gui.getScreenHandler().getCursorStack(); + stackInCursor = mc.player.inventory.getCursorStack(); if (isStackEmpty(stackInCursor)) { return true; @@ -976,7 +981,7 @@ private static void fillBuySlot(HandledScreen gui, existingStack = slot.getStack(); if (isStackEmpty(existingStack) || areStacksEqual(buyStack, existingStack)) { - moveItemsFromInventory(gui, slotNum, mc.player.getInventory(), buyStack, fillStacks); + moveItemsFromInventory(gui, slotNum, mc.player.inventory, buyStack, fillStacks); } } @@ -1001,7 +1006,7 @@ public static void handleRecipeClick(HandledScreen gui, // Right click: Also craft the items if (isRightClick) { Slot outputSlot = CraftingHandler.getFirstCraftingOutputSlotForGui(gui); - boolean dropKeyDown = mc.options.dropKey.isPressed(); // FIXME 1.14 + boolean dropKeyDown = mc.options.keyDrop.isPressed(); // FIXME 1.14 if (outputSlot != null) { if (dropKeyDown) { @@ -1231,6 +1236,7 @@ private static void fillCraftingGrid(HandledScreen gui, return; } + MinecraftClient mc = MinecraftClient.getInstance(); while (true) { slotNum = getSlotNumberOfLargestMatchingStackFromDifferentInventory(container, slotGrids, ingredientReference); @@ -1247,13 +1253,13 @@ private static void fillCraftingGrid(HandledScreen gui, // Pick up the ingredient stack from the found slot leftClickSlot(gui, slotNum); - ItemStack stackCursor = gui.getScreenHandler().getCursorStack(); + ItemStack stackCursor = mc.player.inventory.getCursorStack(); // Successfully picked up ingredient items if (areStacksEqual(ingredientReference, stackCursor)) { sizeOrig = getStackSize(stackCursor); dragSplitItemsIntoSlots(gui, targetSlots); - stackCursor = gui.getScreenHandler().getCursorStack(); + stackCursor = mc.player.inventory.getCursorStack(); // Items left in cursor if (isStackEmpty(stackCursor) == false) { @@ -1268,7 +1274,7 @@ private static void fillCraftingGrid(HandledScreen gui, // All of them didn't fit into the first slot anymore, switch into the current // source slot - if (isStackEmpty(gui.getScreenHandler().getCursorStack()) == false) { + if (isStackEmpty(mc.player.inventory.getCursorStack()) == false) { slotReturn = slotNum; leftClickSlot(gui, slotReturn); } @@ -1281,20 +1287,21 @@ private static void fillCraftingGrid(HandledScreen gui, } // Somehow items were left in the cursor, break here - if (isStackEmpty(gui.getScreenHandler().getCursorStack()) == false) { + if (isStackEmpty(mc.player.inventory.getCursorStack()) == false) { break; } } // Return the rest of the items to the original slot - if (slotNum >= 0 && isStackEmpty(gui.getScreenHandler().getCursorStack()) == false) { + if (slotNum >= 0 && isStackEmpty(mc.player.inventory.getCursorStack()) == false) { leftClickSlot(gui, slotNum); } } public static void rightClickCraftOneStack(HandledScreen gui) { Slot slot = AccessorUtils.getSlotUnderMouse(gui); - ItemStack stackCursor = gui.getScreenHandler().getCursorStack(); + MinecraftClient mc = MinecraftClient.getInstance(); + ItemStack stackCursor = mc.player.inventory.getCursorStack(); if (slot == null || slot.hasStack() == false || (isStackEmpty(stackCursor) == false) && areStacksEqual(slot.getStack(), stackCursor) == false) { @@ -1311,7 +1318,7 @@ public static Optional getRecipeFromPattern(RecipePattern recipe // Creates dummy inventories/containers.. probs a better way RecipeManager recipeManager = mc.world.getRecipeManager(); - ScreenHandler screenHandler = new Generic3x3ContainerScreenHandler(-1, mc.player.getInventory()); + ScreenHandler screenHandler = new Generic3x3ContainerScreenHandler(-1, mc.player.inventory); CraftingInventory search = new CraftingInventory(screenHandler, 3, 3); ItemStack[] items = recipe.getRecipeItems(); @@ -1567,7 +1574,8 @@ && areStacksEqual(stackReference, slot.getStack())){ private static int putSingleItemIntoSlots(HandledScreen gui, IntArrayList targetSlots, int startIndex) { - ItemStack stackInCursor = gui.getScreenHandler().getCursorStack(); + MinecraftClient mc = MinecraftClient.getInstance(); + ItemStack stackInCursor = mc.player.inventory.getCursorStack(); if (isStackEmpty(stackInCursor)) { return 0; @@ -1595,8 +1603,8 @@ private static int putSingleItemIntoSlots(HandledScreen public static void moveOneSetOfItemsFromSlotToPlayerInventory(HandledScreen gui, Slot slot) { leftClickSlot(gui, slot.id); - - ItemStack stackCursor = gui.getScreenHandler().getCursorStack(); + MinecraftClient mc = MinecraftClient.getInstance(); + ItemStack stackCursor = mc.player.inventory.getCursorStack(); if (isStackEmpty(stackCursor) == false) { IntArrayList slots = getSlotNumbersOfMatchingStacks(gui.getScreenHandler(), slot, false, stackCursor, true, @@ -1618,6 +1626,7 @@ private static void moveOneRecipeItemIntoCraftingGrid(HandledScreen= 0 && isStackEmpty(gui.getScreenHandler().getCursorStack()) == false) { + if (slotNum >= 0 && isStackEmpty(mc.player.inventory.getCursorStack()) == false) { leftClickSlot(gui, slotNum); } } private static boolean moveItemFromCursorToSlots(HandledScreen gui, IntArrayList slotNumbers) { + MinecraftClient mc = MinecraftClient.getInstance(); for (int slotNum : slotNumbers) { leftClickSlot(gui, slotNum); - if (isStackEmpty(gui.getScreenHandler().getCursorStack())) { + if (isStackEmpty(mc.player.inventory.getCursorStack())) { return true; } } @@ -1870,7 +1880,7 @@ private static IntArrayList getSlotNumbersOfEmptySlotsInPlayerInventory(ScreenHa } public static boolean areStacksEqual(ItemStack stack1, ItemStack stack2) { - return stack1.isEmpty() == false && stack1.isItemEqual(stack2) && ItemStack.areNbtEqual(stack1, stack2); + return stack1.isEmpty() == false && stack1.isItemEqual(stack2) && ItemStack.areTagsEqual(stack1, stack2); } private static boolean areSlotsInSameInventory(Slot slot1, Slot[] slots) { @@ -1956,8 +1966,8 @@ private static void clickSlotsToMoveItemsFromSlot(Slot slotFrom, boolean toOtherInventory) { // Left click to pick up the found source stack leftClickSlot(gui, slotFrom.id); - - if (isStackEmpty(gui.getScreenHandler().getCursorStack())) { + MinecraftClient mc = MinecraftClient.getInstance(); + if (isStackEmpty(mc.player.inventory.getCursorStack())) { return; } @@ -1965,19 +1975,19 @@ private static void clickSlotsToMoveItemsFromSlot(Slot slotFrom, ItemStack stackDst = slotDst.getStack(); if (areSlotsInSameInventory(slotDst, slotFrom) != toOtherInventory - && (isStackEmpty(stackDst) || areStacksEqual(stackDst, gui.getScreenHandler().getCursorStack()))) { + && (isStackEmpty(stackDst) || areStacksEqual(stackDst, mc.player.inventory.getCursorStack()))) { // Left click to (try and) place items to the slot leftClickSlot(gui, slotDst.id); } - if (isStackEmpty(gui.getScreenHandler().getCursorStack())) { + if (isStackEmpty(mc.player.inventory.getCursorStack())) { return; } } // Couldn't fit the entire stack to the target inventory, return the rest of the // items - if (isStackEmpty(gui.getScreenHandler().getCursorStack()) == false) { + if (isStackEmpty(mc.player.inventory.getCursorStack()) == false) { leftClickSlot(gui, slotFrom.id); } } @@ -2007,7 +2017,8 @@ private static boolean clickSlotsToMoveSingleItem(HandledScreen gui, rightClickSlot(gui, slotFrom.id); } + MinecraftClient mc = MinecraftClient.getInstance(); for (int slotNum : slotsTo) { // Empty cursor, all done here - if (isStackEmpty(gui.getScreenHandler().getCursorStack())) { + if (isStackEmpty(mc.player.inventory.getCursorStack())) { break; } Slot dstSlot = gui.getScreenHandler().getSlot(slotNum); - if (dstSlot.canInsert(gui.getScreenHandler().getCursorStack()) && (dstSlot.hasStack() == false - || areStacksEqual(dstSlot.getStack(), gui.getScreenHandler().getCursorStack()))) { + if (dstSlot.canInsert(mc.player.inventory.getCursorStack()) && (dstSlot.hasStack() == false + || areStacksEqual(dstSlot.getStack(), mc.player.inventory.getCursorStack()))) { leftClickSlot(gui, slotNum); lastSlot = dstSlot; } } // Return the rest of the items, if any - if (isStackEmpty(gui.getScreenHandler().getCursorStack()) == false) { + if (isStackEmpty(mc.player.inventory.getCursorStack()) == false) { leftClickSlot(gui, slotFrom.id); } @@ -2221,16 +2234,16 @@ private static void moveOneItemToFirstValidSlot(HandledScreen gui) { - ItemStack stackCursor = gui.getScreenHandler().getCursorStack(); + MinecraftClient mc = MinecraftClient.getInstance(); + ItemStack stackCursor = mc.player.inventory.getCursorStack(); if (isStackEmpty(stackCursor) == false) { IntArrayList emptySlots = getSlotNumbersOfEmptySlotsInPlayerInventory(gui.getScreenHandler(), false); @@ -2294,12 +2308,12 @@ public static void tryClearCursor(HandledScreen gui) { } leftClickSlot(gui, slotNum); - stackCursor = gui.getScreenHandler().getCursorStack(); + stackCursor = mc.player.inventory.getCursorStack(); } } } - if (isStackEmpty(gui.getScreenHandler().getCursorStack()) == false) { + if (isStackEmpty(mc.player.inventory.getCursorStack()) == false) { dropItemsFromCursor(gui); } } @@ -2429,7 +2443,8 @@ public static void swapSlots(HandledScreen gui, int slo private static void dragSplitItemsIntoSlots(HandledScreen gui, IntArrayList targetSlots) { - ItemStack stackInCursor = gui.getScreenHandler().getCursorStack(); + MinecraftClient mc = MinecraftClient.getInstance(); + ItemStack stackInCursor = mc.player.inventory.getCursorStack(); if (isStackEmpty(stackInCursor)) { return; diff --git a/src/main/java/fi/dy/masa/itemscroller/util/ItemType.java b/src/main/java/fi/dy/masa/itemscroller/util/ItemType.java index 5ed50b57e..d35151b5d 100644 --- a/src/main/java/fi/dy/masa/itemscroller/util/ItemType.java +++ b/src/main/java/fi/dy/masa/itemscroller/util/ItemType.java @@ -31,7 +31,7 @@ public int hashCode() int result = 1; //result = prime * result + ((stack == null) ? 0 : stack.hashCode()); result = prime * result + this.stack.getItem().hashCode(); - result = prime * result + (this.stack.getNbt() != null ? this.stack.getNbt().hashCode() : 0); + result = prime * result + (this.stack.getTag() != null ? this.stack.getTag().hashCode() : 0); return result; } @@ -58,7 +58,7 @@ public boolean equals(Object obj) return false; } - return ItemStack.areNbtEqual(this.stack, other.stack); + return ItemStack.areTagsEqual(this.stack, other.stack); } } diff --git a/src/main/java/fi/dy/masa/itemscroller/villager/VillagerDataStorage.java b/src/main/java/fi/dy/masa/itemscroller/villager/VillagerDataStorage.java index f190c02cc..8c3aed6ef 100644 --- a/src/main/java/fi/dy/masa/itemscroller/villager/VillagerDataStorage.java +++ b/src/main/java/fi/dy/masa/itemscroller/villager/VillagerDataStorage.java @@ -122,7 +122,7 @@ public FavoriteData getFavoritesForCurrentVillager(TradeOfferList originalTrades return new FavoriteData(VillagerUtils.getGlobalFavoritesFor(originalTrades, this.globalFavorites), true); } - return new FavoriteData(IntArrayList.of(), favorites == null); + return new FavoriteData(IntArrayList.wrap(new int[]{}), favorites == null); } private void readFromNBT(NbtCompound nbt) diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index a0c5b91ca..fc5ab1232 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -33,7 +33,6 @@ ], "depends": { - "minecraft": "1.18.2", - "malilib": "0.12.x" + "malilib": ">=0.10.0-dev.21" } }