No Spam
📎 1 file 2,077 chars
📄
pasted-code-1792968295481.txt
txt 15 lines
▶
​Platform: Fabric (Minecraft 1.21.1)
Mod Name: Handheld Cannons
​Overview:
Create a fully functioning Minecraft mod that introduces two handheld ranged weapons (cannons) along with tiered craftable ammunition and a custom reloading/durability economy.
​1. Custom Items & Cannons:
​Copper Hand Cannon: Crafted using 2x Copper Ingots, 1x Flint and Steel, and 1x Oak Log. Max durability (shots) is set to 500. When firing, it plays a crisp explosion sound (ENTITY_GENERIC_EXPLODE, pitch 1.4F) and applies a moderate player recoil.
​Iron Hand Cannon: Crafted using 2x Iron Ingots, 1x Flint and Steel, and 1x Stripped Oak Log. Max durability (shots) is set to 750. When firing, it plays a deep, bass-heavy boom sound (ENTITY_GENERIC_EXPLODE, volume 1.2F, pitch 0.55F) and applies a heavier player recoil, shooting faster with more velocity.
​2. Tiered Ammunition System:
Add three custom ammunition item variants that feature tooltips showing their damage tiers:
​Stone Ammo (Low Tier - Gray Tooltip): Crafted from a block of cobblestone, yielding 50 ammo. Deals 6.0 damage on direct hit with a small explosion power of 1.8F.
​Copper Ammo (Medium Tier - Gold Tooltip): Crafted from copper ingots, yielding 75 ammo. Deals 10.0 damage on direct hit with an explosion power of 2.6F.
​Iron Ammo (High Tier - Red Tooltip): Crafted from iron ingots, yielding 100 ammo. Deals 16.0 (Copper Cannon) to 18.0 (Iron Cannon) damage with a large explosion power of 3.5F to 4.0F.
​3. Mechanics & Economy:
​Reloading: When a cannon reaches maximum durability usage (out of charges), right-clicking while holding 1x Gunpowder and at least 1 ammunition item in the inventory consumes 1 Gunpowder and 1 highest-tier available ammo item (Iron -> Copper -> Stone), completely resetting the cannon's durability back to 0 (fully refilled).
​Entity & Rendering: Include a custom flying projectile entity for the cannonballs that triggers an explosion and deletes itself upon hitting any block or entity. Register a client flying item renderer so the ammunition item is visible while flying through the air.
Kodari AI
KodariOct 25 at 11:04 pm 16
HandheldCannons
A Fabric mod for Minecraft 1.21.1 introducing two handheld ranged weapons: Copper and Iron Hand Cannons with distinct crafting recipes, durability (500/750 shots), unique firing sounds and recoil. Includes three tiered ammunition types (Stone, Copper, Iron) with color-coded tooltips, damage values, and explosion powers. Features a reloading economy consuming Gunpowder and highest-tier ammo to restore durability, plus a custom flying projectile entity with client-side item rendering.
  1. Create the Fabric 1.21.4 mod foundation and register the cannons, ammunition, and projectile.

  2. Implement firing, ammo selection, recoil, durability-based reloading, projectile damage, and explosion behavior.

  3. Add the client renderer, textures, item assets, recipes, and names.

Implemented Handheld Cannons for Fabric/Minecraft 1.21.4; the attached spec says 1.21.1, but this project targets the mounted 1.21.4 Yarn source.

  • Copper cannon: 500 shots; iron cannon: 750. Both fire the highest-tier ammo in the inventory. Each shot consumes one round; reloading at empty costs one gunpowder and one highest-tier ammo, then refills the cannon.

  • Ammo recipes: 1 cobblestone → 50 stone ammo; 1 copper ingot → 75 copper ammo; 1 iron ingot → 100 iron ammo.

  • Cannon recipes use the requested ingots, flint and steel, and oak/stripped oak log. Ammo tiers have colored damage tooltips.

  • Added the flying cannonball entity, impact damage and explosions, firing sounds and recoil, a client flying-item renderer, and Combat-tab entries.

  • Generated textures for both cannons and stone ammo. Copper and iron ammo currently use vanilla ingot icons because texture-generation credits ran out.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
30 554
src/main/java/com/kodari/handheldcannons/HandheldCannons.java
package com.kodari.handheldcannons;

import com.kodari.handheldcannons.entity.ModEntities;
import com.kodari.handheldcannons.item.ModItems;
import net.fabricmc.api.ModInitializer;

public final class HandheldCannons implements ModInitializer {
    public static final String MOD_ID = "handheldcannons";

    @Override
    public void onInitialize() {
        ModItems.initialize();
        ModEntities.initialize();
    }
}