📄
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.
Create the Fabric 1.21.4 mod foundation and register the cannons, ammunition, and projectile.
Implement firing, ammo selection, recoil, durability-based reloading, projectile damage, and explosion behavior.
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.
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();
}
}