ofir
📎 1 file 4,948 chars
📄
pasted-code-1791114831533.txt
txt 35 lines
▶
You are a senior Minecraft Fabric mod developer. Build a new client-side mod from scratch for Minecraft 26.3 exactly (Fabric, unobfuscated game, Mojang names, Java 25). Never target another Minecraft version or silently fall back to one. If Loader, Loom or Fabric API builds for 26.3 do not exist, stop and report it. Verify every vanilla class, method and field against the real 26.3 sources; never guess APIs from memory.

PRODUCT
"Hold My Items" (id: holdmyitems, license: Creative Commons Zero). A scriptable first-person animation framework: resource packs ship Lua scripts that control how hands and held items move, how parts of an item model animate, plus custom particles, sounds and keybinds. Vanilla behavior is kept when no script applies. Nothing may crash a dedicated server.

SETUP
Gradle 9.x, Loom plugin id net.fabricmc.fabric-loom (non-remapping, no mappings), Java 25. fabric.mod.json: depends minecraft "26.3", java ">=25", fabric-api (not "fabric"), main + client entrypoints. Mixin config holdmyitems.mixins.json, package com.holdmylua.source.mixin, JAVA_25, defaultRequire 1. Embed LuaJ via Jar-in-Jar. Output: holdmyitems-+26.3.jar from ./gradlew build.

SCRIPT LOADING
Register a Fabric resource reload listener (holdmyitems:lua_animation_loader). Scan active packs for assets//holdmyitems/ (namespaces minecraft, holdmyitems): hand_pose.lua, hand_relative_pose.lua, item_pose.lua, item_model.lua, plus additive *_addon.lua variants of each that run after the base script.
Preprocess: (1) turn "global. = ;" into a header "local  = registry:getOrDefault('', )" and a footer "registry:put('', )" so values persist between frames; (2) replace ${name} with respackopts values if that mod is present; (3) compile once per reload and cache.
Wrap every script call: on error log "[HoldMyItems] Lua runtime error: ", show a rate-limited "HMI Lua Runtime error!" notice, disable only that script until reload, never crash.

LUA ENVIRONMENT
Restricted LuaJ globals: no io, os, luajava, debug, package, require, dofile, loadfile. Java is reachable only through wrapper classes whose methods carry a custom @Safe annotation; the bridge refuses everything else.
Variables: context (player, item, matrices as a PoseStack wrapper, bl = left-side arm, equipProgress, swingSpeed, itemSwingSpeed, useDuration, usingItem, translateItem, renderAsBlock, deltaTime), data (player, item, mainHand, bl, deltaTime), animator, registry, debugger, particleManager.
Helpers (colon syntax): I (getUseAction returning "eat", "drink", "bow", "crossbow", "spear", "brush", "block" or "none"; isOf, getName), P (isUsingItem, getActiveHand, getSpeed, getYSpeed, isOnGround), M (clamp, lerp, pow, PID), C (camera offsets), S (sounds), Easings, Items/Tags (Items:get("minecraft:water_bucket")), Component, Texture, KeyBindManager (Lua keybinds in Controls).

MODEL ANIMATION
animator:moveX/Y/Z(first, last, amount); animator:rotateX/Y/Z(first, last, degrees, pivotX, pivotY, pivotZ), pivots in 0..1 model space; animator:scale(first, last, sx, sy, sz, px, py, pz). Indices follow the "elements" order of the item's JSON model. Poses accumulate per frame, apply in order, then clear. Carry them through the 26.3 item render state and apply when quads are submitted. Unscripted items cost nothing.

PARTICLES
Own lightweight system with pooling: position, velocity, size, rotation, color, opacity, lifetime, texture. Lifecycle SPAWN, KEYFRAME, SCALE, OPACITY with Lua callbacks. Render types ADDITIVE, TRANSLUCENT, TRANSLUCENT_LIT, CUTOUT_LIT via 26.3's RenderPipeline API. Spaces: HAND, ITEM, SCREEN.

HOOKS
Prefer Fabric events; otherwise client-only mixins. Needed: wrap first-person hand/item rendering for scripted items (equip progress, swing, use animations for eat, drink, bow, crossbow, spear, brush, block; per-hand state; vanilla fallback); item rendering with item_pose, animator and a "render as block" path; frame and tick updates; camera access and offsets; swing count and previous-frame entity values; useDuration and isUsingItem exposed to item properties; transient ItemStack fields via an accessor; sandbox enforcement. Every mixin target must be verified in 26.3 and fail loudly if missing.

EXTRAS
Custom sounds via sounds.json. A Fabric HUD element draws debugger text and SCREEN particles. Iris optional via reflection (IrisApi.isShaderPackInUse): use shader-safe pipelines when active.

EXAMPLE PACK
Embed optional pack "pack_test": minecraft:select item definitions (2D in gui/fixed/ground, split 3D in hand) for boats and buckets, plus scripts showing easing, camera-turn sway, walk/fall jiggle via persistent globals and an inspect spin on a custom key.

DELIVER
Full source tree, Gradle files, mod json, mixin config, example pack, a README of the Lua API, and the built .jar. List every 26.3 API decision and anything unverified.
Kodari AI
KodariOct 4 at 12:32 pm 5
HoldMyItems
A client-side Fabric mod for Minecraft 26.3 that enables scriptable first-person animation through Lua. Resource packs can ship Lua scripts controlling hand and held-item movement, item model part animation, custom particles, sounds, and keybinds. Features include persistent global variables between frames, restricted Lua environment with safe Java wrappers, pose accumulation for model animation, pooled particle system with render pipelines, and vanilla fallback when no script applies. Includes example pack demonstrating easing, camera sway, walk jiggle, and inspect spin.
  1. Bootstrap the 26.3 Fabric client mod and Jar-in-Jar Lua runtime.

  2. Add resource-pack script discovery, preprocessing, sandboxed execution, and reload-time compilation.

  3. Wire client frame/tick integration and safe vanilla fallback; add the example pack and API README.

Created the Hold My Items Minecraft 26.3 Fabric project with Java 25, client-only rendering code, Fabric metadata, a client mixin, LuaJ Jar-in-Jar configuration, an embedded example pack, and a Lua API README.

The initial implementation covers resource reload and script compilation, restricted Lua globals, persistent global.* values, first-person item transforms, per-script error disabling, an error notice, and a debug overlay. It is not the complete requested framework: the README lists the current limits, including per-element model animation, particles, sounds, Lua-defined keybinds, camera hooks, full use-action overrides, respackopts integration, and example item-selection JSON.

26.3 API decisions used: the Fabric ResourceLoader with PackType.CLIENT_RESOURCES and ResourceManagerReloadListener; the first-person FirstPersonHandsAndItemsRenderer.submitArmWithItem path, injecting before the general ItemStackRenderState.submit call (ordinal 1); Fabric’s ClientTickEvents, KeyMappingHelper, and HudElementRegistry; GuiGraphicsExtractor.text; and BuiltInRegistries.ITEM.getKey for item namespaces. The embedded pack uses pack_format: 97 (26.3 format 97.1; legacy integer field 97). The available 26.3 sources had no minecraft:select item-definition examples, so that JSON was left out rather than guessed.

The project is configured to produce holdmyitems-1.0.0+26.3.jar, but a built jar is not attached here, and I have not verified a complete build. To generate and download it in Kodari:

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

  2. Click Compile in the window.

  3. When it succeeds, click Download on the build or Download holdmyitems.jar in chat.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
README.md
settings.gradle
Code
17 671
src/client/java/com/holdmylua/source/client/HoldMyItemsClient.java
package com.holdmylua.source.client;

import com.holdmylua.source.HoldMyItems;
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.fabricmc.fabric.api.resource.v1.ResourceLoader;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.resources.Identifier;
import net.minecraft.server.packs.PackType;
import com.mojang.blaze3d.platform.InputConstants;

public final class HoldMyItemsClient implements ClientModInitializer {
	private static final KeyMapping.Category CATEGORY = KeyMapping.Category.register(Identifier.fromNamespaceAndPath(HoldMyItems.MOD_ID, "controls"));
	private static final KeyMapping DEBUG_KEY = new KeyMapping("key.holdmyitems.debug", InputConstants.Type.KEYBOARD, 72, CATEGORY);
	private static boolean debugOverlay;

	@Override
	public void onInitializeClient() {
		KeyMappingHelper.registerKeyMapping(DEBUG_KEY);
		ResourceLoader.get(PackType.CLIENT_RESOURCES).registerReloadListener(
			Identifier.fromNamespaceAndPath(HoldMyItems.MOD_ID, "lua_animation_loader"), LuaAnimationLoader.INSTANCE);
		ClientTickEvents.END_CLIENT_TICK.register(client -> {
			while (DEBUG_KEY.consumeClick()) {
				debugOverlay = !debugOverlay;
			}
		});
		HudElementRegistry.addLast(Identifier.fromNamespaceAndPath(HoldMyItems.MOD_ID, "debug_overlay"), HoldMyItemsClient::renderHud);
	}

	private static void renderHud(GuiGraphicsExtractor graphics, DeltaTracker deltaTracker) {
		String notice = LuaScript.noticeText();
		if (notice != null) {
			graphics.text(Minecraft.getInstance().font, notice, 8, 8, 0xFFFF5555, true);
		}
		if (debugOverlay) {
			graphics.text(Minecraft.getInstance().font, "Hold My Items: " + LuaAnimationLoader.scriptCount() + " Lua scripts", 8, 20, 0xFFFFFFFF, true);
		}
	}
}