📄
pasted-code-1792819575547.txt
txt
54 lines
▶
You are an expert Minecraft Fabric mod developer. Build me a complete, working Fabric mod for Minecraft Java Edition 1.21.11 (Fabric ONLY, no Forge, NeoForge, Quilt, or Bukkit/Spigot plugins) called "Railgun Rod". Write the full source code for every file so I can build and run it right away.
PROJECT SETUP
- Minecraft 1.21.11, Java 21, Fabric Loader, Fabric API, and Fabric Loom (use the correct versions for 1.21.11).
- Use Mojang official mappings (or Yarn if that is what works for 1.21.11) and tell me which one you chose. Keep class and method names consistent with that mapping.
- Do NOT guess version numbers. Give me the gradle.properties values and tell me where to confirm the latest correct ones (fabricmc.net/develop). If you are unsure of any API, class, or method name in 1.21.11, mark it clearly with a comment "VERIFY" instead of inventing it.
- Mod id: railgun_rod. Package: com.example.railgunrod.
- Make it SERVER-SIDE ONLY (a "main" entrypoint with no client code needed), so it works on a dedicated server and in singleplayer, and players with a vanilla client can join. If something truly needs the client, tell me why and keep it minimal.
THE ITEM
- A custom "Railgun Rod" fishing rod item with 1 durability (max damage 1), not stackable, with a custom name and enchantment glint.
- Register it properly with item components for 1.21.11 (registry key, Item.Settings/Properties, and a creative tab entry).
- Because the mod should stay server-side, identify it either as a normal fishing rod with a custom_data marker/custom_model_data, or as a real registered item. Explain the trade-off (a registered item needs the mod on the client) and let me choose with a config option.
- Give me a /give command or a custom command (/railgun give) to get it.
- The rod must be destroyed after one shot. Do not depend on vanilla durability rules, because reeling in with nothing hooked may not use durability. Remove or break the item yourself and play the break sound.
HOW IT MUST WORK
1. Detect reel-in: Hook into the moment the player reels in the fishing bobber (for example a Mixin on FishingBobberEntity/FishingHook retrieve method at HEAD, or another reliable event). It must trigger on REEL-IN only, never on casting, and only when the rod is the Railgun Rod.
2. Position: Use the bobber's X and Z at the moment of reeling in (where the bobber dropped or landed), not the player's position. If the bobber is in a world with no loaded chunk, do nothing safely.
3. Sky limit: Go up to the world's build height limit for that dimension (use the world's height/top Y value from the level, not a hardcoded 319).
4. Arrows: Spawn 100 arrows at that sky position, all moving straight down at a very high speed like a railgun beam. Set the velocity directly on the entity (a mod is not limited by the command spawn speed cap). Make sure fast arrows do not tunnel through blocks and entities, and explain how you handled that. Make arrow speed, damage, crit, pierce level, fire, and pickup rules configurable. Add a toggle for a tight beam or a small random spread.
5. TNT charge: At the same sky position, spawn 150 TNT with fuse 0 so they explode immediately, with no ticking or flashing animation. For best performance, give me two modes in the config: (a) spawn PrimedTnt entities with fuse 0, and (b) call the world explosion directly without spawning entities. Recommend which one is better and explain why.
6. Set the explosion power, whether it breaks blocks (and which block-break rule: none, mob griefing, or destroy), and whether it damages the shooter or other players.
7. Once per reel-in, with a cooldown option, and safe for many players at once.
8. Fire only on the server thread. Do not freeze the server: add an option to spread the 100 arrows and 150 TNT across several ticks (a small scheduler queue) so they do not all spawn in one tick, and let me set the batch size.
CONFIGURATION AND COMMANDS
- A JSON config file in the config folder with every value above (arrow count, TNT count, speed, damage, pierce, spread, explosion power, block damage, shooter safety, cooldown, batching).
- A reload command and a /railgun give command with permission level checks (operators only by default).
- Optional effects: particles, a charge-up sound, and a thunder or explosion sound when it fires.
SAFETY AND PERFORMANCE
- Warn me honestly about the lag and chunk-loading cost of 100 arrows plus 150 TNT.
- Use a safe cap setting so a server owner can limit the counts.
- Make sure it does not crash if the bobber is in the void, in another dimension, or in unloaded chunks.
FILES I NEED (write each in full with its exact path)
- build.gradle, gradle.properties, settings.gradle
- fabric.mod.json
- The main mod initializer class
- The item registration class and the Railgun logic class
- The Mixin class and railgun_rod.mixins.json (with the correct compatibility level and target)
- The config class and the command registration class
- The scheduler/queue class if you use batching
- Any lang files or data files (item model, recipe if you add one)
ALSO GIVE ME
- Step-by-step instructions to build the mod (./gradlew build), where the jar ends up, and how to install it in a Fabric 1.21.11 server or client with Fabric API.
- A test plan (how to confirm the reel-in detection works, that it does not fire when casting, and that the rod breaks).
- A list of every assumption and every spot where a class or method name might differ in 1.21.11.
BEFORE ANSWERING
- Go over all the code for compile errors, wrong imports, and wrong method names, and fix them.
- If you cannot guarantee something compiles, say so and mark it, instead of pretending.
Use a vanilla fishing rod with a server-side marker so vanilla clients can join; keep the item implementation free of custom registry entries.
Verify the 1.21.11 Yarn signatures for reel-in interception, item marking, spawning, explosions, commands, and server-tick batching.
Create the complete Fabric project, config, command, mixin, and setup/test instructions.
Railgun Rod is implemented as a Fabric 1.21.11 mod using Yarn mappings. The default mode marks a vanilla fishing rod, so the server does not add a custom item registry entry and vanilla clients can join.
How it works
The mixin hooks
FishingBobberEntity.use()—the reel-in method, not casting. It uses the bobber’s position, skips unloaded chunks and out-of-height bobbers, and spawns the volley at the dimension’s top build Y.The marked rod is removed after a successful shot, and the mixin suppresses vanilla durability wear for that reel. It has a one-point max-damage component and cannot stack.
Arrows are fired downward with configurable speed and pierce. Vanilla’s projectile tick raycasts along the arrow’s swept movement path for blocks and entities, helping prevent tunneling at high speed.
directis the default TNT mode: it avoids spawning primed entities, but still runs one explosion per configured TNT count.primed_tntspawns fuse-zero entities that detonate on their next server tick. Direct mode is preferable when avoiding entity tracking and visual effects matters.Batching is enabled by default at 25 actions per server tick. Even with batching, 100 arrows and 150 explosions can cause substantial lag and terrain damage. The config’s
maxPayloadsPerShotcaps their combined count./railgun giveand/railgun reloadrequire operator-level permission. The rod is an admin item; no survival recipe is included.
Item mode and config
The first server start creates config/railgun_rod.json. Set itemMode to:
marker(default): a named, glinting vanilla fishing rod with a server-side marker. Vanilla clients can join; it uses the vanilla rod icon and is not in their creative tabs.registered: a separate custom item with its own texture and a Tools & Utilities creative-tab entry. Restart after changing this setting. Clients also need the mod because the item is registered.
The config includes counts and cap, arrow speed/damage/crit/pierce/fire/pickup/spread, TNT mode and explosion power, block-damage and player-damage rules, cooldown, batching, particles, and sounds. The recommended direct mode still runs many explosions; use smaller counts and batching on busy servers.
Versions
The project is set to Minecraft 1.21.11, Yarn 1.21.11+build.5, Loader 0.19.2, Fabric API 0.141.4+1.21.11, Java 21, and Fabric Loom 1.14 (1.14-SNAPSHOT in the Gradle plugin declaration). Check Fabric’s developer page at fabricmc.net/develop for current toolchain guidance.
Build, install, and test
In Kodari, click Compile in the desktop top bar, or on phone tap ⋮ → Compile Project.
Click Compile in the build window.
On success, click Download on the build or the Download button in chat. If it fails, use Auto-fix or Fix.
Install the downloaded mod and Fabric API in the server’s mods folder. In singleplayer, install the mod on the client as well. The default marker mode allows vanilla clients to join the dedicated server.
Test by starting the server, running /railgun give, casting normally to confirm casting does not fire, then reeling in to confirm the shot and rod removal. Try a small count with batching enabled, verify cooldown behavior, and check the explosion rules. The mounted 1.21.11 Yarn/Fabric signatures were checked; Kodari Compile is the build verification step.
package com.example.railgunrod;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class RailgunRodMod implements ModInitializer {
public static final String MOD_ID = "railgun_rod";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
@Override
public void onInitialize() {
RailgunConfig.reload(true);
RailgunItems.initialize();
CommandRegistrationCallback.EVENT.register(RailgunCommands::register);
ServerTickEvents.END_SERVER_TICK.register(RailgunScheduler::tick);
ServerLifecycleEvents.SERVER_STOPPING.register(server -> {
RailgunScheduler.clear(server);
RailgunLogic.clear();
});
}
}