manuel vanegas
📎 1 file 4,243 chars
📄
pasted-code-1794865104042.txt
txt 167 lines
▶
Minecraft Mod Development: Crafter Slot Filter

Create a fully functional Minecraft Fabric mod called Crafter Slot Filter, compatible with Minecraft Java Edition 1.21.11.

1. Main objective

I want to assign one specific item to each individual slot of a Minecraft Crafter (3x3 crafting grid).

Each slot must have an independent item filter. Once an item is assigned to a slot, that slot must ONLY accept that specific item and reject all other items.

This must work with both manual inventory interactions and automated item transportation.

2. Individual slot filtering

Each of the 9 Crafter slots must have its own independent filter.

I must be able to assign a specific item to each slot.

Each slot can accept only its assigned item.

Slots without a filter must work normally.

I must be able to configure all 9 slots independently.

Example configuration:

Slot 1: Iron Ingot ONLY.

Slot 2: Stick ONLY.

Slot 3: Diamond ONLY.

Slot 4: Gold Ingot ONLY.

Slot 5: Redstone ONLY.

Slots 6–9: Unrestricted.

3. Item restrictions

The filtering system must prevent incorrect items from entering filtered slots.

It must work with:

Normal hoppers.

Hopper minecarts.

Manual player inventory interaction.

Other automated inventory transportation systems.

Any compatible modded item insertion system.

For example, if Slot 1 is configured for Iron Ingots, a hopper attempting to insert a Diamond into Slot 1 must be rejected.

The correct item must still enter normally.

Important: Filtering must be enforced server-side, not just visually on the client, to prevent bypassing restrictions in multiplayer.

4. Configuration GUI

Create an easy-to-use configuration interface for every Crafter.

The interface must allow me to:

Select an item from my inventory.

Assign that item to any of the 9 slots.

See which item is assigned to each slot.

Remove an individual filter.

Reset all filters.

Configure each Crafter independently.

The interface should be simple, intuitive and visually clear.

5. Saving configurations

Each Crafter must save its own individual configuration.

Configurations must persist after:

Closing Minecraft.

Restarting the server.

Unloading and reloading chunks.

Breaking and replacing chunks must not accidentally transfer configurations to unrelated Crafters.

Different Crafters must have completely independent filter configurations.

6. Normal Crafter functionality

The Crafter must continue functioning normally.

Redstone activation must work.

Normal crafting recipes must work.

Valid items must be consumed normally.

Item filters must not interfere with crafting mechanics.

The filters must remain active after crafting.

7. Technical requirements

Minecraft Java Edition 1.21.11.

Fabric Loader.

Compatible with multiplayer.

Compatible with dedicated servers.

Compatible with Exaroton hosting.

Server-side item validation.

Client-side configuration interface.

Proper synchronization between server and clients.

Avoid conflicts with vanilla inventory mechanics.

8. Required deliverables — VERY IMPORTANT

I do not want just an explanation, concept, tutorial or example code.

I need a COMPLETE, FUNCTIONAL AND COMPILED MOD.

Please deliver:

The compiled .jar file, ready to install.

Complete source code.

All required dependencies.

A Gradle build configuration.

Installation instructions for Exaroton.

Installation instructions for Minecraft clients.

Clear instructions explaining whether the mod must be installed on the server, the clients, or both.

A basic testing guide to verify that all 9 filters work correctly.

Before delivering the mod, compile it and test that it builds successfully for Minecraft 1.21.11 with Fabric.

If there are technical limitations, explain them instead of delivering a nonfunctional implementation.

9. Final and most important requirement

This mod is NOT simply a Crafter slot enable/disable tool.

I specifically need a WHITELIST ITEM FILTER FOR EACH INDIVIDUAL CRAFTER SLOT.

Every slot must be able to accept one specific item type and reject every other item, including items inserted through hoppers and automated transportation.

The final result must be a working Minecraft Fabric 1.21.11 mod, delivered as a downloadable .jar file.
Kodari AI
KodariMon at 9:43 pm 6
CrafterSlotFilter
A Fabric mod for Minecraft 1.21.11 that adds per-slot item whitelist filters to the Crafter block. Each of the 9 slots can be independently configured to accept only a specific item type, enforced server-side to prevent bypassing. Features a client-side configuration GUI for assigning items from inventory, removing filters, and resetting all slots. Configurations persist per-block across restarts and chunk reloads. Compatible with hoppers, hopper minecarts, and automated transportation systems while maintaining full vanilla crafting functionality.
  • Store nine item-type filters on each Crafter and enforce them on the server.

  • Add filter controls to the Crafter screen and synchronize changes with the server.

  • Include installation and testing instructions, with compatibility limits noted.

Implemented the Crafter filters and configuration controls. Installation and testing instructions are in README.md.

The mod must be installed on both the server and clients. Hoppers and automation that respect inventory insertion checks are supported; mods that directly mutate inventory stacks can bypass filters.

The build and in-game tests have not been verified, so I can’t yet claim a ready-to-install JAR. To get one in Kodari:

  1. Click Compile in the top bar, or on phone tap ⋮ → Compile Project.

  2. Click Compile in the window.

  3. If it succeeds, click Download. If it fails, use Auto-fix or Fix.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
manifest.kod
README.md
settings.gradle
Code
14 361
src/client/java/dev/kodari/crafterfilter/client/CrafterFilterClient.java
package dev.kodari.crafterfilter.client;

import dev.kodari.crafterfilter.FilterRequest;
import dev.kodari.crafterfilter.FilterSnapshot;
import io.wispforest.owo.ui.component.LabelComponent;
import io.wispforest.owo.ui.component.UIComponents;
import io.wispforest.owo.ui.container.FlowLayout;
import io.wispforest.owo.ui.container.UIContainers;
import io.wispforest.owo.ui.core.Insets;
import io.wispforest.owo.ui.core.Sizing;
import io.wispforest.owo.ui.core.Surface;
import io.wispforest.owo.ui.core.VerticalAlignment;
import io.wispforest.owo.ui.layers.Layers;
import java.util.Map;
import java.util.WeakHashMap;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ingame.CrafterScreen;
import net.minecraft.item.Item;
import net.minecraft.registry.Registries;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

public class CrafterFilterClient implements ClientModInitializer {
    private static final Map<CrafterScreen, LabelComponent[]> LABELS = new WeakHashMap<>();
    private int ticks;

    @Override
    public void onInitializeClient() {
        Layers.add(UIContainers::verticalFlow, instance -> {
            instance.aggressivePositioning = true;
            CrafterScreen screen = instance.screen;
            FlowLayout panel = UIContainers.verticalFlow(Sizing.fixed(165), Sizing.content());
            panel.padding(Insets.of(5));
            panel.gap(2);
            panel.surface(Surface.DARK_PANEL);
            panel.child(UIComponents.label(Text.literal("Slot filters")));
            LabelComponent[] labels = new LabelComponent[9];
            for (int i = 0; i < 9; i++) {
                int slot = i;
                FlowLayout row = UIContainers.horizontalFlow(Sizing.fill(100), Sizing.content());
                row.gap(3);
                row.verticalAlignment(VerticalAlignment.CENTER);
                row.child(UIComponents.button(Text.literal("" + (i + 1)), button -> send(screen, slot)).horizontalSizing(Sizing.fixed(20)));
                labels[i] = UIComponents.label(Text.literal("Loading..."));
                labels[i].maxWidth(130);
                row.child(labels[i]);
                panel.child(row);
            }
            panel.child(UIComponents.button(Text.literal("Reset all"), button -> send(screen, 9)));
            LABELS.put(screen, labels);
            instance.adapter.rootComponent.child(panel);
            instance.alignComponentToHandledScreenCoordinates(panel, 180, 0);
            send(screen, 10);
        }, CrafterScreen.class);

        ClientPlayNetworking.registerGlobalReceiver(FilterSnapshot.ID, (snapshot, context) -> {
            if (!(context.client().currentScreen instanceof CrafterScreen screen)
                    || screen.getScreenHandler().syncId != snapshot.syncId()) return;
            LabelComponent[] labels = LABELS.get(screen);
            if (labels == null) return;
            for (int i = 0; i < 9; i++) {
                String id = snapshot.filters().get(i);
                Identifier identifier = Identifier.tryParse(id);
                Item item = identifier == null ? null : Registries.ITEM.get(identifier);
                Text name = id.isEmpty() ? Text.literal("Any item")
                        : item == null ? Text.literal(id) : item.getName();
                if (!labels[i].text().getString().equals(name.getString())) labels[i].text(name);
            }
        });
        ClientTickEvents.END_CLIENT_TICK.register(client -> {
            if (++this.ticks % 20 == 0 && client.currentScreen instanceof CrafterScreen screen) send(screen, 10);
        });
    }

    private static void send(CrafterScreen screen, int action) {
        if (MinecraftClient.getInstance().player != null && ClientPlayNetworking.canSend(FilterRequest.ID)) {
            ClientPlayNetworking.send(new FilterRequest(screen.getScreenHandler().syncId, action));
        }
    }
}