Create the new Fabric mod PoliceStateSim strictly for Minecraft 1.20.4 and Fabric API for 1.20.4, not 1.21 or Forge/NeoForge. Implement Part 1 feature code:

  • On first player joining a newly created world, generate once a neat enclosed two-room stone/quartz Government Complex approximately 12 blocks from world spawn, with desk and invulnerable named villager 'MFC Official', courthouse judge desk and invulnerable named villager 'Judge', and attached small obsidian/iron-bar prison cell containing a stone-filled mine pit. Persist generation and protect all complex blocks against player breaking.
  • Register State Ruble currency item with custom green banknote texture, and four temporary stamped-document textured license items: Logging License (Лицензия лесоруба), Hunting License (Охотничий билет), Mining License (Лицензия шахтера), Weapon License (Лицензия на оружие). Each individual license lasts 300 seconds of time in a player's inventory, ticking once per second, represented by durability; expiry removes it, plays paper sound and sends red 'Your license has expired!'.
  • Right-clicking MFC Official opens a clean 1.20.4 client Screen with buttons: Claim Starter Capital (once per player, persistently gives 50 State Rubles); Sell 16 Cobblestone or Dirt -> +5 State Rubles (check and remove items); four purchase buttons for respective licenses, each 15 rubles. Server must validate all actions, funds, inventory, and once-only state; synchronize screen interaction appropriately.
  • Enforce laws on server: cancel breaking log blocks without a valid logging license; cancel attacking cows, pigs, sheep or chickens without a valid hunting license; cancel breaking coal, iron, copper, gold, diamond, redstone or emerald ore blocks without a valid mining license (including deepslate variants); cancel attacking any entity while holding a sword, axe or bow without a valid weapon license. On violation add scoreboard tag 'wanted' and send bold red '[POLICE] CRIME DETECTED! You are now WANTED!'. Ensure all events and checks are server-authoritative and licenses expire properly. Include all required assets, registrations and Fabric metadata; use 1.20.4 APIs.
Kodari AI
KodariToday at 11:17 am 20
PoliceStateSim
Fabric mod for Minecraft 1.20.4 that generates a protected Government Complex at world spawn with invulnerable MFC Official and Judge villagers, plus a prison cell. Implements a State Ruble currency with custom texture and four timed license items (Logging, Hunting, Mining, Weapon) that expire after 300 seconds via durability. Right-clicking the MFC Official opens a client screen for claiming starter capital, selling resources, and purchasing licenses. Server-side enforcement cancels illegal block breaking and entity attacks, marking offenders as 'wanted' with scoreboard tags and crime alerts.

I’ll build the complex, server-side laws and transactions, timed licenses, and the official’s client screen for Fabric 1.20.4.

Implemented PoliceStateSim for Fabric 1.20.4.

In survival, visit the MFC Official near world spawn to claim 50 State Rubles once per player. Sell 16 cobblestone or dirt for 5 rubles, and buy each license for 15 rubles. Licenses last 300 seconds while in a player’s inventory.

The prison’s mine pit is protected along with the rest of the complex, so its stone cannot be broken. The projectile law also applies to crossbow arrows and tridents.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
22 393
src/main/java/com/policestatesim/PoliceStateSim.java
package com.policestatesim;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.player.AttackEntityCallback;
import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents;
import net.fabricmc.fabric.api.event.player.UseEntityCallback;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.AxeItem;
import net.minecraft.item.BowItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.item.SwordItem;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;

public final class PoliceStateSim implements ModInitializer {
    public static final String ID = "policestatesim";
    public static final Identifier OPEN = id("open_official"), ACTION = id("official_action");
    public static final Item RUBLE = register("state_ruble", new Item(new Item.Settings()));
    public static final Item LOGGING = register("logging_license", new LicenseItem());
    public static final Item HUNTING = register("hunting_license", new LicenseItem());
    public static final Item MINING = register("mining_license", new LicenseItem());
    public static final Item WEAPON = register("weapon_license", new LicenseItem());
    private static final Item[] LICENSES = { LOGGING, HUNTING, MINING, WEAPON };

    public static Identifier id(String path) { return new Identifier(ID, path); }
    private static Item register(String name, Item item) { return Registry.register(Registries.ITEM, id(name), item); }

    @Override public void onInitialize() {
        Registry.register(Registries.ITEM_GROUP, id("items"), FabricItemGroup.builder()
            .displayName(Text.translatable("itemGroup.policestatesim.items"))
            .icon(() -> new ItemStack(RUBLE)).entries((context, entries) -> {
                entries.add(RUBLE); for (Item license : LICENSES) entries.add(license);
            }).build());

        ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
            var world = server.getOverworld();
            Complex.generate(world, StateData.get(world));
        });
        PlayerBlockBreakEvents.BEFORE.register((world, player, pos, state, blockEntity) -> {
            if (world == world.getServer().getOverworld() && Complex.protectedPos(StateData.get(world.getServer().getOverworld()), pos)) {
                player.sendMessage(Text.literal("The Government Complex is protected.").formatted(Formatting.RED), false);
                return false;
            }
            if ((state.isIn(BlockTags.LOGS) && !has(player, LOGGING)) || (ore(state) && !has(player, MINING))) {
                crime(player); return false;
            }
            return true;
        });
        AttackEntityCallback.EVENT.register((player, world, hand, target, hit) -> {
            if (world.isClient) return ActionResult.PASS;
            Item held = player.getStackInHand(hand).getItem();
            if ((isHunted(target) && !has(player, HUNTING)) ||
                ((held instanceof SwordItem || held instanceof AxeItem || held instanceof BowItem) && !has(player, WEAPON))) {
                crime(player); return ActionResult.FAIL;
            }
            return ActionResult.PASS;
        });
        UseEntityCallback.EVENT.register((player, world, hand, target, hit) -> {
            if (!target.getCommandTags().contains("policestatesim_official")) return ActionResult.PASS;
            if (world.isClient) return ActionResult.PASS;
            if (player instanceof ServerPlayerEntity serverPlayer) {
                PacketByteBuf buf = PacketByteBufs.create(); buf.writeInt(target.getId());
                ServerPlayNetworking.send(serverPlayer, OPEN, buf);
            }
            return ActionResult.SUCCESS;
        });
        ServerPlayNetworking.registerGlobalReceiver(ACTION, (server, player, handler, buf, responseSender) -> {
            int officialId = buf.readInt(); int action = buf.readInt();
            server.execute(() -> transact(player, officialId, action));
        });
    }
    public static boolean isHunted(Entity entity) {
        EntityType<?> type = entity.getType();
        return type == EntityType.COW || type == EntityType.PIG || type == EntityType.SHEEP || type == EntityType.CHICKEN;
    }
    public static boolean has(PlayerEntity player, Item item) {
        PlayerInventory inventory = player.getInventory();
        for (int i = 0; i < inventory.size(); i++) {
            ItemStack stack = inventory.getStack(i);
            if (stack.isOf(item) && stack.getDamage() < 300) return true;
        }
        return false;
    }
    public static void crime(PlayerEntity player) {
        player.addCommandTag("wanted");
        player.sendMessage(Text.literal("[POLICE] CRIME DETECTED! You are now WANTED!").formatted(Formatting.RED, Formatting.BOLD), false);
    }
    private static boolean ore(BlockState state) {
        return state.isIn(BlockTags.COAL_ORES) || state.isIn(BlockTags.IRON_ORES) || state.isIn(BlockTags.COPPER_ORES)
            || state.isIn(BlockTags.GOLD_ORES) || state.isIn(BlockTags.DIAMOND_ORES)
            || state.isIn(BlockTags.REDSTONE_ORES) || state.isIn(BlockTags.EMERALD_ORES);
    }
    private static int count(PlayerInventory inv, Item item) {
        int count = 0;
        for (int i = 0; i < 36; i++) if (inv.getStack(i).isOf(item)) count += inv.getStack(i).getCount();
        return count;
    }
    private static void take(PlayerInventory inv, Item item, int amount) {
        for (int i = 0; i < 36 && amount > 0; i++) {
            ItemStack stack = inv.getStack(i);
            if (stack.isOf(item)) { int n = Math.min(amount, stack.getCount()); stack.decrement(n); amount -= n; }
        }
    }
    private static boolean room(PlayerInventory inv, Item item, int amount) {
        for (int i = 0; i < 36; i++) {
            ItemStack stack = inv.getStack(i);
            if (stack.isEmpty()) amount -= item.getMaxCount();
            else if (stack.isOf(item) && item == RUBLE) amount -= stack.getMaxCount() - stack.getCount();
            if (amount <= 0) return true;
        }
        return false;
    }
    private static void transact(ServerPlayerEntity player, int entityId, int action) {
        Entity official = player.getServerWorld().getEntityById(entityId);
        StateData data = StateData.get(player.getServer().getOverworld());
        if (official == null || !official.getCommandTags().contains("policestatesim_official") ||
            player.getServerWorld() != player.getServer().getOverworld() ||
            !Complex.protectedPos(data, official.getBlockPos()) || player.squaredDistanceTo(official) > 64.0) return;
        PlayerInventory inv = player.getInventory();
        if (action == 0) {
            if (data.claimed(player.getUuid())) { message(player, "Starter capital already claimed."); return; }
            if (!room(inv, RUBLE, 50)) { message(player, "Not enough inventory space."); return; }
            inv.insertStack(new ItemStack(RUBLE, 50)); data.claim(player.getUuid());
            message(player, "Claimed 50 State Rubles.");
        } else if (action == 1 || action == 2) {
            Item sold = action == 1 ? Items.COBBLESTONE : Items.DIRT;
            if (count(inv, sold) < 16) { message(player, "You need 16 of the selected block."); return; }
            if (!room(inv, RUBLE, 5)) { message(player, "Not enough inventory space."); return; }
            take(inv, sold, 16); inv.insertStack(new ItemStack(RUBLE, 5)); message(player, "Sold 16 blocks for 5 State Rubles.");
        } else if (action >= 3 && action <= 6) {
            if (count(inv, RUBLE) < 15) { message(player, "You need 15 State Rubles."); return; }
            Item license = LICENSES[action - 3];
            if (!room(inv, license, 1)) { message(player, "Not enough inventory space."); return; }
            take(inv, RUBLE, 15); inv.insertStack(new ItemStack(license)); message(player, "License purchased for 15 State Rubles.");
        }
    }
    private static void message(PlayerEntity player, String message) { player.sendMessage(Text.literal(message), false); }
}