Skip to content

Commit

Permalink
add option to ignore Item NBTs
Browse files Browse the repository at this point in the history
  • Loading branch information
aria1th committed Dec 20, 2023
1 parent e3a5e33 commit 4572cd5
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfigHotkey> getHotkeyList() {
ImmutableList.Builder<ConfigHotkey> hotkeyList = new ImmutableList.Builder<ConfigHotkey>().addAll(Hotkeys.HOTKEY_LIST);
hotkeyList.addAll(ImmutableList.of(
Expand Down Expand Up @@ -145,7 +147,8 @@ public static ImmutableList<ConfigHotkey> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/io/github/eatmyvenom/litematicin/utils/Printer.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,29 +111,44 @@ 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)) {
if (stack.getItem() instanceof ToolItem || stack.getItem() instanceof FlintAndSteelItem) {
// 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;
}
}
}
Expand Down

0 comments on commit 4572cd5

Please sign in to comment.