diff --git a/src/main/java/io/github/eatmyvenom/litematicin/LitematicaMixinMod.java b/src/main/java/io/github/eatmyvenom/litematicin/LitematicaMixinMod.java index 507a8b3f..cb5caabd 100644 --- a/src/main/java/io/github/eatmyvenom/litematicin/LitematicaMixinMod.java +++ b/src/main/java/io/github/eatmyvenom/litematicin/LitematicaMixinMod.java @@ -77,6 +77,8 @@ public class LitematicaMixinMod implements ModInitializer { public static final ConfigHotkey PRINTER_CLEAR_FLUIDS_USE_COBBLESTONE_HOTKEY = new ConfigHotkey("printerClearFluidsUseCobblestoneToggleKey", "", "Printer clear fluids use cobblestone will be toggled ON/OFF"); public static final ConfigHotkey PRINTER_BEDROCK_BREAKING_HOTKEY = new ConfigHotkey("printerBedrockBreakingToggleKey", "", "Printer bedrock breaking will be toggled ON/OFF"); + public static final ConfigBoolean PRINTER_IGNORE_NBT = new ConfigBoolean("printerIgnoreNBT", false, "Printer will ignore NBT data when placing blocks"); + public static ImmutableList getHotkeyList() { ImmutableList.Builder hotkeyList = new ImmutableList.Builder().addAll(Hotkeys.HOTKEY_LIST); hotkeyList.addAll(ImmutableList.of( @@ -145,7 +147,8 @@ public static ImmutableList getHotkeyList() { PRINTER_BEDROCK_DELAY, PRINTER_FAKE_ROTATION, PRINTER_FAKE_ROTATION_DELAY, - PRINTER_FAKE_ROTATION_LIMIT_PER_TICKS) + PRINTER_FAKE_ROTATION_LIMIT_PER_TICKS, + PRINTER_IGNORE_NBT) ).build(); @Override diff --git a/src/main/java/io/github/eatmyvenom/litematicin/utils/InventoryUtils.java b/src/main/java/io/github/eatmyvenom/litematicin/utils/InventoryUtils.java index 5b604c16..51410d4b 100644 --- a/src/main/java/io/github/eatmyvenom/litematicin/utils/InventoryUtils.java +++ b/src/main/java/io/github/eatmyvenom/litematicin/utils/InventoryUtils.java @@ -405,8 +405,36 @@ public static int getSlotWithStack(ClientPlayerEntity player, ItemStack stack) { return stack.getItem() instanceof ToolItem || isToolLikeItem(stack.getItem()) ? getSlotWithItem(inv, stack) :inv.getSlotWithStack(stack); } + public static void printAllItems(PlayerInventory inv, ItemStack stack) { + // Debug + for (int i = 0; i < inv.main.size(); i++) { + boolean areNbtsEqual = ItemStack.areNbtEqual(inv.getStack(i), stack); + boolean areItemsEqual = ItemStack.areItemsEqual(inv.getStack(i), stack); + MessageHolder.sendDebugMessage("Slot " + i + ", " + inv.getStack(i).getItem() + " : " + areItemsEqual + " : " + areNbtsEqual); + } + } + + public static int getSlotWIthStackIgnoreNbt(PlayerInventory inv, ItemStack stack) { + // Debug + int defaultSlot = inv.getSlotWithStack(stack); + if (defaultSlot != -1) { + return defaultSlot; + } + if (!PRINTER_IGNORE_NBT.getBooleanValue()) { + return defaultSlot; + } + for (int i = 0; i < inv.main.size(); i++) { + boolean areItemsEqual = ItemStack.areItemsEqual(inv.getStack(i), stack); + if (areItemsEqual) { + return i; + } + } + return -1; + } + public static int getSlotWithStack(PlayerInventory inv, ItemStack stack) { - return stack.getItem() instanceof ToolItem || isToolLikeItem(stack.getItem()) ? getSlotWithItem(inv, stack) :inv.getSlotWithStack(stack); + int findingStack = getSlotWIthStackIgnoreNbt(inv, stack); + return stack.getItem() instanceof ToolItem || isToolLikeItem(stack.getItem()) ? getSlotWithItem(inv, stack) :findingStack; } @SuppressWarnings("ConstantConditions") diff --git a/src/main/java/io/github/eatmyvenom/litematicin/utils/Printer.java b/src/main/java/io/github/eatmyvenom/litematicin/utils/Printer.java index 478801c0..b4f15727 100644 --- a/src/main/java/io/github/eatmyvenom/litematicin/utils/Printer.java +++ b/src/main/java/io/github/eatmyvenom/litematicin/utils/Printer.java @@ -111,8 +111,13 @@ public static boolean canPickBlock(MinecraftClient mc, BlockState preference, Bl World world = SchematicWorldHandler.getSchematicWorld(); ItemStack stack = getStackForState(mc, preference, world, pos); if (stack.isEmpty()) { + MessageHolder.sendDebugMessage(mc.player, "Cannot pick block " + preference.getBlock().getName() + " at " + pos.toShortString() + " because no stack"); return false; } + // Inventory Cache + if (USE_INVENTORY_CACHE.getBooleanValue() && !ITEMS.isEmpty()) { // if cache is enabled and cache is not empty + return io.github.eatmyvenom.litematicin.utils.InventoryUtils.swapToItem(mc, stack); + } if (!stack.isEmpty() && stack.getItem() != Items.AIR) { PlayerInventory inv = getInventory(mc.player); if (!isCreative(mc.player)) { @@ -120,20 +125,30 @@ public static boolean canPickBlock(MinecraftClient mc, BlockState preference, Bl // manually search through inventories int slot = io.github.eatmyvenom.litematicin.utils.InventoryUtils.getSlotWithItem(inv, stack); if (slot == -1) { + MessageHolder.sendDebugMessage(mc.player, "Cannot pick block " + preference.getBlock().getName() + " at " + pos.toShortString() + " because no slot"); return false; } if (EASY_PLACE_MODE_HOTBAR_ONLY.getBooleanValue()) { - return slot < 9; + boolean isHotbar = slot < 9; + if (!isHotbar) { + MessageHolder.sendDebugMessage(mc.player, "Cannot pick block " + preference.getBlock().getName() + " at " + pos.toShortString() + " because not in hotbar"); + } + return isHotbar; } return true; } else { int slot = getSlotWithStack(inv, stack); if (slot == -1) { + MessageHolder.sendDebugMessage(mc.player, "Cannot pick block " + preference.getBlock().getName() + " at " + pos.toShortString() + " because no slot"); return false; } if (EASY_PLACE_MODE_HOTBAR_ONLY.getBooleanValue()) { - return slot < 9; + boolean isHotbar = slot < 9; + if (!isHotbar) { + MessageHolder.sendDebugMessage(mc.player, "Cannot pick block " + preference.getBlock().getName() + " at " + pos.toShortString() + " because not in hotbar"); + } + return isHotbar; } } }