F

Minecraft 26.2 Fabric – Litematica Instant Smart Switch

Entwickle eine Client-Side-Mod für Minecraft 26.2 mit Fabric, die mit Litematica zusammenarbeitet.

1. Hauptfunktion

Wenn der Spieler mit seinem Fadenkreuz auf einen Block schaut, der in der aktiven Litematica-Schematic benötigt wird, soll automatisch der passende Block ausgewählt werden.

  • Benötigten Block anhand der Schematic erkennen.
  • Passendes Item in der Hotbar suchen.
  • Sofort zum passenden Hotbar-Slot wechseln.
  • Kein automatisches Platzieren.
  • Kein automatisches Abbauen.
  • Kein Wiederherstellen des vorherigen Slots.
  • Bei jedem neuen Zielblock den benötigten Slot neu bestimmen.

2. Hotbar-System (Priorität)

  • Alle 9 Hotbar-Slots durchsuchen.
  • Passenden Slot unmittelbar auswählen.
  • Nur wechseln, wenn ein anderer Slot benötigt wird.
  • Keine unnötigen Slot-Wechsel.
  • Bereits ausgewählten passenden Slot beibehalten.

3. Optionales Inventar-System

Zusätzlich soll geprüft werden, ob eine Inventarsuche technisch möglich ist.

Falls der benötigte Block nicht in der Hotbar liegt:

  • Restliches Spielerinventar durchsuchen.
  • Falls möglich, Item über normale Inventarinteraktionen in die Hotbar verschieben.
  • Keine direkte Platzierung aus dem Inventar.
  • Keine erfundenen Netzwerkfunktionen.
  • Inventarfunktion separat aktivierbar und standardmäßig deaktiviert.

Die Inventarfunktion darf nur mit normalen, serverkonformen Inventarinteraktionen arbeiten. Keine Anti-Cheat-Umgehung.

4. Performance

  • Extrem schnelle Reaktion.
  • Möglichst geringe CPU-Auslastung.
  • Keine unnötigen Berechnungen.
  • Effizientes Caching der Schematic-Daten.
  • Schnelle Erkennung bei Bewegung des Fadenkreuzes.

5. Litematica-Erkennung

  • Aktive Schematic auslesen.
  • Zielposition korrekt bestimmen.
  • Benötigten Block inklusive relevanter Blockstates erkennen.
  • Bereits korrekt platzierte Blöcke ignorieren.
  • Nur auf tatsächlich benötigte Blöcke reagieren.

6. Einstellungen

  • Toggle-Keybind.
  • Inventarsuche ein/aus.
  • HUD-Anzeige des benötigten Blocks.
  • Debug-Modus.
  • Einstellbare Reaktionslogik.

7. Technische Anforderungen

  • Minecraft 26.2
  • Fabric Loader
  • Java
  • Client-Side only
  • Litematica-Kompatibilität
  • Vollständiger kompilierbarer Sourcecode.
  • Gradle-Projekt inklusive Dependencies.
  • Keine automatische Blockplatzierung.
  • Keine Anti-Cheat-Umgehung.
  • Normale Minecraft-Inventar- und Slot-Mechaniken verwenden.
Kodari AI
KodariNov 7 at 10:03 pm 3
LitematicaSmartSwitcher
Client-side Fabric mod for Minecraft 26.2 that integrates with Litematica to automatically select the correct hotbar slot when the player looks at a block required by the active schematic. Detects the needed block and blockstates from the schematic, scans all nine hotbar slots for a matching item, and instantly switches to the appropriate slot only when necessary. Includes an optional, disabled-by-default inventory search feature that moves required items into the hotbar using standard server-compliant inventory interactions. Features efficient schematic data caching, fast crosshair detection, a toggle keybind, HUD display of the required block, and a debug mode. No automatic block placement, no anti-cheat bypass, and no restoration of the previous slot.
  1. Set up the Fabric 26.2 client-only Gradle project and Litematica compatibility.

  2. Add hotbar matching, safe optional inventory swapping, keybind toggles, HUD status, and debug/logic settings.

  3. Include survival-safe behavior: select only, never place or break blocks.

Implemented the client-only Fabric 26.2 project. It checks Litematica’s schematic world at the crosshair, ignores air and blocks already matching the schematic, and selects a matching hotbar item without placing, breaking, or restoring slots.

Default controls: G toggle, H inventory search (off by default), J HUD, K debug HUD, L cycle selection logic. Inventory swaps use vanilla container interactions and only run while the player inventory menu is active. Litematica is optional at compile time; the mod detects its schematic-world API at runtime.

F

Additional requirements:

  • Never switch slots repeatedly when the required item is already selected.
  • Prioritize exact block-item matching.
  • Handle blocks with no direct item representation correctly.
  • Do not select items for air or already completed schematic positions.
  • Ensure crosshair detection works with Litematica's actual schematic placement coordinates.
  • Avoid unnecessary inventory clicks or slot movements.
  • Verify all APIs and dependencies against Minecraft 26.2 and the actual installed Litematica version.
  • Do not assume that successful compilation guarantees runtime compatibility.
Kodari AI
KodariNov 7 at 11:55 pm 1

The generation was stopped before any content could be produced.

F
📎 1 file 2,553 chars
📄
pasted-code-1794096040310.txt
txt 65 lines
▶
## Additional Requirements & Reliability

- Never switch slots repeatedly when the required item is already selected.
- Prioritize exact block-item matching.
- Handle blocks with no direct item representation correctly.
- Do not select items for air or already completed schematic positions.
- Ensure crosshair detection works with Litematica's actual schematic placement coordinates.
- Correctly handle multiple active schematic placements.
- Avoid unnecessary inventory clicks or slot movements.
- Verify all APIs and dependencies against Minecraft 26.2 and the actual installed Litematica version.
- Do not assume that successful compilation guarantees runtime compatibility.
- Test actual in-game behavior with Litematica installed.
- Ensure stable behavior without crashes or unintended slot changes.

## ModMenu Integration & Configuration GUI

Implement full ModMenu integration for Minecraft 26.2 Fabric.

All mod settings must be configurable through the ModMenu configuration screen. Users should never need to manually edit configuration files.

Use Cloth Config or another compatible configuration library if required.

### Configurable Settings

**General**
- Enable/disable Smart Switch.
- Enable/disable inventory search (disabled by default).
- Enable/disable automatic inventory-to-hotbar swapping.
- Toggle HUD display.
- Toggle debug mode.

**Selection & Matching**
- Configure selection logic.
- Configure exact block-item matching.
- Configure blockstate matching.
- Configure reaction/update behavior.
- Configure whether already completed schematic blocks are ignored.
- Configure air-block handling.
- Configure slot-switching behavior.

**Inventory**
- Enable/disable full inventory scanning.
- Configure whether existing hotbar items can be replaced.
- Configure preferred hotbar slot behavior.
- Prevent unnecessary inventory movements.

**HUD**
- Show/hide required block.
- Show/hide currently selected slot.
- Show/hide item availability.
- Configure HUD visibility.

**Keybinds**
- Customize all mod keybinds through Minecraft's Controls menu.

### GUI Requirements

- Clean and organized configuration screen.
- Settings grouped into logical categories.
- Clear descriptions for every setting.
- Changes apply immediately whenever possible.
- Settings save automatically and persist after restarting Minecraft.
- Include sensible default values.
- Handle missing optional dependencies gracefully.
- Ensure full compatibility with ModMenu and Minecraft 26.2.
Kodari AI
KodariNov 8 at 12:12 am 5
  1. Härte die Erkennung und Auswahl gegen Litematicas echte Platzierungsdaten und vermeide unnötige Slotwechsel.

  2. Ergänze eine ModMenu-Konfigurationsseite mit persistenten YACL-Einstellungen für die angeforderten Optionen.

  1. Kernlogik korrigiert: Item-Matching ist exakt; Blöcke ohne Item werden übersprungen, und ein Inventartausch bleibt ausstehend, bis der Client den tatsächlichen Inventarzustand bestätigt. Die geerbte Litematica-Schematic-Welt wird an der Fadenkreuz-Weltposition abgefragt.

  2. Ergänze jetzt ModMenu/YACL-Konfiguration und speichere die Optionen dauerhaft. upstream Litematica stellt im geprüften Branch nur eine 1.21.1-API bereit; eine echte 26.2-Laufzeitprüfung ist ohne installierte Litematica-Version bzw. Minecraft-Client nicht möglich.

Die Zuverlässigkeitslogik und die ModMenu-Konfiguration sind ergänzt.

  • Auswahl: Exakter Item-Abgleich ist Standard. Blöcke ohne Item, Luftziele und bereits fertige Positionen lösen keine Auswahl aus. Der ausgewählte passende Slot bleibt unverändert; Inventartausch wird nur einmal angefordert und erst nach einer bestätigten Inventaränderung weiterverarbeitet. Es gibt weiterhin kein automatisches Platzieren oder Abbauen.

  • Konfiguration: YACL-Einstellungen sind über ModMenu in die Bereiche Allgemein, Auswahl/Abgleich, Inventar und HUD gegliedert. Sie werden automatisch gespeichert. Keybinds bleiben im Minecraft-Menü Steuerung anpassbar. YACL und ModMenu sind über manifest.kod eingebunden; ModMenu bleibt optional.

  • Kompatibilitätsgrenze: Ein tatsächlicher In-Game-Test war hier nicht möglich. Das Projekt nennt keine installierte Litematica-Version; die geprüfte Upstream-API stammt aus dem 1.21.1-Branch, nicht aus einer 26.2-Version. Die Integration fragt deren virtuelle Schematic-Welt an der Weltposition des Fadenkreuzes ab und fällt bei fehlender oder inkompatibler API sicher aus. Eine Laufzeitkompatibilität mit deiner konkreten Litematica-Installation kann ich daher nicht bestätigen; dafür brauche ich deren genaue Version bzw. Build-ID.

F

It switches but only after you place either you track when the player tries to place and switch before or do somethings else

Kodari AI
KodariNov 8 at 10:38 am 2
  1. Move selection ahead of placement by checking the actual placement cell, then add a pre-use safety check so a click can’t place with the stale slot.

  2. Verify the 26.2 callback and placement-position APIs, plus the project’s mixin wiring before changing anything.

Fixed the target position in LitematicaSmartSwitchClient.java: while you aim, Smart Switch now checks the cell where the block would be placed—using the hit cell if it’s replaceable, otherwise the adjacent cell on the hit face. Previously it checked the supporting block, which could make the switch happen only after placement changed what the crosshair hit.

I didn’t add a last-moment click callback: in 26.2, the selected-slot packet is sent before that callback runs, so switching there could send the placement with the old slot. I couldn’t verify this in-game with your installed Litematica build.

F

Geht muss aber viel viel schneller wechseln vermeide unnötige tick berechnung

Kodari AI
KodariNov 8 at 10:52 am 1

Ich stelle die Zielprüfung auf den HUD-Render-Callback um, damit ein neuer Zielblock nicht bis zum nächsten Tick warten muss. Bei unverändertem Ziel und bereits passendem Slot überspringe ich die teure Schematic-Abfrage; erfolglose Inventarsuchen werden kurz zwischengespeichert.

Die Auswahl läuft jetzt bereits beim nächsten HUD-Render statt erst am Tickende. Bei unverändertem Ziel und bereits passendem Slot werden Schematic-Abfrage und Inventarprüfung übersprungen; erfolglose Vollinventarsuchen werden für 100 ms zwischengespeichert. Das Aktualisieren der Schematic-Daten pro Frame ist standardmäßig deaktiviert und kann in den Einstellungen eingeschaltet werden.

Ein In-Game-Test mit deiner Litematica-Installation war hier nicht möglich.

F

Mach version 26.1.2 ohne irgendwas zu änder nur version ändern

Kodari AI
KodariYesterday at 12:56 pm 2

Dieses Projekt ist ein Fabric-Mod für Minecraft 26.2. Kodari bietet Fabric für 26.1.2 nicht an; nahe Optionen sind Fabric 26.2 und 1.21.11 sowie NeoForge 26.1.2.

F

wieso geht nd 26.1.2

Kodari AI
KodariYesterday at 1:01 pm 3

Kodari unterstützt Fabric-Projekte für 26.1.2 derzeit nicht – deshalb lässt sich dieses Projekt nicht auf diese Version umstellen. NeoForge 26.1.2 ist verfügbar, aber ein Wechsel des Modloaders wäre mehr als eine reine Versionsänderung.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
manifest.kod
settings.gradle
Code
9 766
src/client/java/com/kodari/litematicasmartswitch/LitematicaSmartSwitchClient.java
package com.kodari.litematicasmartswitch;

import java.lang.reflect.Method;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keymapping.v1.KeyMappingHelper;
import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.ContainerInput;
import net.minecraft.world.inventory.InventoryMenu;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;

public final class LitematicaSmartSwitchClient implements ClientModInitializer {
	private static final String MOD_ID = "litematica_smartswitch";
	private static final KeyMapping.Category KEY_CATEGORY = KeyMapping.Category.register(
			Identifier.fromNamespaceAndPath(MOD_ID, "controls"));
	private static final KeyMapping TOGGLE_KEY = registerKey("key.litematica_smartswitch.toggle", 71);
	private static final KeyMapping INVENTORY_KEY = registerKey("key.litematica_smartswitch.inventory", 72);
	private static final KeyMapping HUD_KEY = registerKey("key.litematica_smartswitch.hud", 74);
	private static final KeyMapping DEBUG_KEY = registerKey("key.litematica_smartswitch.debug", 75);
	private static final KeyMapping LOGIC_KEY = registerKey("key.litematica_smartswitch.logic", 76);

	private static Probe probe;
	private static BlockState neededState;
	private static PendingSwap pendingSwap;
	private static String availability = "Waiting";
	private static int selectedSlotForHud = -1;
	private static String status = "Waiting for Litematica";
	private static BlockPos lastInventorySearchPosition;
	private static Item lastInventorySearchItem;
	private static long nextInventorySearchAtNanos;

	@Override
	public void onInitializeClient() {
		SmartSwitchConfig.load(Minecraft.getInstance().gameDirectory.toPath());
		ClientTickEvents.END_CLIENT_TICK.register(LitematicaSmartSwitchClient::tick);
		HudElementRegistry.addLast(Identifier.fromNamespaceAndPath(MOD_ID, "status"),
				(graphics, deltaTracker) -> renderHud(graphics));
	}

	private static KeyMapping registerKey(String translationKey, int keyCode) {
		return KeyMappingHelper.registerKeyMapping(new KeyMapping(translationKey, keyCode, KEY_CATEGORY));
	}

	private static void tick(Minecraft client) {
		if (TOGGLE_KEY.consumeClick()) {
			SmartSwitchConfig.set("enabled", !SmartSwitchConfig.enabled);
			status = SmartSwitchConfig.enabled ? "Enabled" : "Disabled";
		}
		if (INVENTORY_KEY.consumeClick()) {
			SmartSwitchConfig.set("inventorySearch", !SmartSwitchConfig.inventorySearch);
		}
		if (HUD_KEY.consumeClick()) {
			SmartSwitchConfig.set("hudEnabled", !SmartSwitchConfig.hudEnabled);
		}
		if (DEBUG_KEY.consumeClick()) {
			SmartSwitchConfig.set("debugEnabled", !SmartSwitchConfig.debugEnabled);
		}
		if (LOGIC_KEY.consumeClick()) {
			SmartSwitchConfig.set("firstSlotSelection", !SmartSwitchConfig.firstSlotSelection);
		}
	}

	private static void updateSelection(Minecraft client) {
		if (!SmartSwitchConfig.enabled) {
			probe = null;
			neededState = null;
			availability = "Smart Switch disabled";
			return;
		}
		if (client.player == null || client.level == null || client.gameMode == null) {
			probe = null;
			neededState = null;
			pendingSwap = null;
			availability = "Waiting for a world";
			status = "Waiting for a world";
			return;
		}
		selectedSlotForHud = client.player.getInventory().getSelectedSlot() + 1;
		if (isSwapPending(client)) {
			status = "Waiting for inventory swap";
			availability = "Inventory swap pending";
			return;
		}
		if (!(client.hitResult instanceof BlockHitResult hit) || hit.getType() != HitResult.Type.BLOCK) {
			probe = null;
			neededState = null;
			availability = "No block targeted";
			status = LitematicaAccess.status();
			return;
		}

		BlockPos position = placementPosition(client, hit);
		Inventory inventory = client.player.getInventory();
		int selectedSlot = inventory.getSelectedSlot();
		selectedSlotForHud = selectedSlot + 1;
		BlockState actual = client.level.getBlockState(position);
		if (!SmartSwitchConfig.refreshSchematicEveryTick && probe != null
				&& probe.position().equals(position) && probe.actual().equals(actual) && neededState != null
				&& matches(inventory.getItem(selectedSlot), neededState.getBlock().asItem(), neededState.getBlock())) {
			return;
		}

		BlockState required = LitematicaAccess.getBlockState(position, SmartSwitchConfig.refreshSchematicEveryTick);
		if (required == null) {
			probe = null;
			neededState = null;
			availability = "Schematic data unavailable";
			status = LitematicaAccess.status();
			return;
		}

		probe = new Probe(position, required, actual);
		if (required.isAir()) {
			neededState = SmartSwitchConfig.ignoreAirBlocks ? null : required;
			availability = "Air never selects an item";
			status = SmartSwitchConfig.ignoreAirBlocks ? "Schematic air ignored" : "Schematic air target";
			return;
		}
		boolean completed = SmartSwitchConfig.blockStateMatching
				? required.equals(actual) : required.getBlock() == actual.getBlock();
		if (SmartSwitchConfig.ignoreCompletedBlocks && completed) {
			neededState = null;
			availability = "Already complete";
			status = "Already matches the schematic";
			return;
		}

		Item requiredItem = required.getBlock().asItem();
		if (requiredItem == Items.AIR) {
			pendingSwap = null;
			neededState = null;
			availability = "No block item exists";
			status = "Need " + blockName(required) + " — block has no matching item";
			return;
		}

		neededState = required;
		if (matches(inventory.getItem(selectedSlot), requiredItem, required.getBlock())) {
			availability = "Available in selected hotbar slot";
			status = "Matching item already selected";
			return;
		}

		int hotbarSlot = findHotbarSlot(inventory, requiredItem, required.getBlock(), selectedSlot);
		if (hotbarSlot >= 0) {
			availability = "Available in hotbar";
			if (SmartSwitchConfig.automaticHotbarSwitching && hotbarSlot != selectedSlot) {
				inventory.setSelectedSlot(hotbarSlot);
				selectedSlotForHud = hotbarSlot + 1;
			}
			status = SmartSwitchConfig.automaticHotbarSwitching
					? "Matching hotbar slot selected" : "Matching item found in hotbar";
			return;
		}

		availability = "Not in hotbar";
		if (!SmartSwitchConfig.inventorySearch) {
			status = "Item not in hotbar; inventory search is off";
			return;
		}
		if (!SmartSwitchConfig.fullInventoryScan) {
			status = "Full inventory scan is off";
			return;
		}
		if (position.equals(lastInventorySearchPosition) && requiredItem == lastInventorySearchItem
				&& System.nanoTime() < nextInventorySearchAtNanos) {
			availability = "Not found in inventory";
			status = "Required item not found";
			return;
		}

		int inventorySlot = findInventorySlot(inventory, requiredItem, required.getBlock());
		if (inventorySlot < 0) {
			lastInventorySearchPosition = position.immutable();
			lastInventorySearchItem = requiredItem;
			nextInventorySearchAtNanos = System.nanoTime() + 100_000_000L;
			availability = "Not found in inventory";
			status = "Required item not found";
			return;
		}
		availability = "Available in main inventory";
		if (!SmartSwitchConfig.automaticInventorySwap) {
			status = "Item found in inventory; automatic swap is off";
			return;
		}
		if (client.player.containerMenu != client.player.inventoryMenu) {
			status = "Close other container to swap inventory item";