Skip to content

Spartan Weaponry Unofficial API Reference

This document provides the API development guide for the Spartan Weaponry Unofficial mod. Developers can use this API to register new Spartan weapons for materials added by other mods.

First, you need to add Spartan Weaponry Unofficial as a dependency in your build.gradle.

repositories {
maven {
url "https://cursemaven.com"
content {
includeGroup "curse.maven"
}
}
}
dependencies {
// Replace xxxxx with the specific Project ID and File ID
// Example: implementation fg.deobf("curse.maven:spartan-weaponry-unofficial-12345:67890")
// Note: Mod ID uses underscores spartan_weaponry_unofficial
implementation fg.deobf("curse.maven:spartan-weaponry-unofficial-xxxxx:yyyyy")
}

The main API entry point is the org.xiyu.spartanweaponryunofficial.api.SpartanWeaponryAPI class.

⚠️ Important Change: Starting from version 1.0.2, the Mod ID has been changed to spartan_weaponry_unofficial.
💡 Note: The Java package name remains spartanweaponryunofficial (without underscores), while the Mod ID and resource paths use spartan_weaponry_unofficial (with underscores).

You can use predefined materials or create custom ones.

import org.xiyu.spartanweaponryunofficial.api.WeaponMaterial;
// Predefined materials: WOOL, STONE, IRON, GOLD, DIAMOND, NETHERITE, etc.
WeaponMaterial material = WeaponMaterial.IRON;
import org.xiyu.spartanweaponryunofficial.api.WeaponMaterial;
import org.xiyu.spartanweaponryunofficial.api.SpartanWeaponryAPI;
import net.minecraft.world.item.Tiers;
// Create using Vanilla Tier
WeaponMaterial myMaterial = new WeaponMaterial(
"my_material", // Material name (used for registry name, e.g., dagger_my_material)
"mydepmod", // Your mod ID
Tiers.DIAMOND, // Base Tier properties
ModItemTags.MY_INGOT, // Repair item Tag
ModWeaponTraitTags.MY_TRAIT // Trait Tag (Optional)
);

It is recommended to use NeoForge/Forge’s DeferredRegister to register items.

import net.minecraft.world.item.Item;
import net.neoforged.neoforge.registries.DeferredRegister;
import net.neoforged.neoforge.registries.DeferredHolder;
import org.xiyu.spartanweaponryunofficial.api.SpartanWeaponryAPI;
public class MyModItems {
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(Registries.ITEM, "mymodid");
// Register a Longsword
public static final DeferredHolder<Item, Item> MY_LONGSWORD = ITEMS.register("longsword_my_material", () ->
SpartanWeaponryAPI.createLongsword(MyModMaterials.MY_MATERIAL)
);
// Register a Warhammer
public static final DeferredHolder<Item, Item> MY_WARHAMMER = ITEMS.register("warhammer_my_material", () ->
SpartanWeaponryAPI.createWarhammer(MyModMaterials.MY_MATERIAL)
);
}

To ensure compatibility, it is recommended to check the API version in your mod constructor:

public MyMod() {
// Ensure API version is at least 12
SpartanWeaponryAPI.assertAPIVersion("mymodid", 12);
}

All methods are located in the SpartanWeaponryAPI class and require a WeaponMaterial parameter.

Method NameDescriptionRegistry Name FormatLocalization Key Format
createDaggerDagger{material}_daggeritem.spartan_weaponry_unofficial.{material}_dagger
createParryingDaggerParrying Dagger{material}_parrying_daggeritem.spartan_weaponry_unofficial.{material}_parrying_dagger
createLongswordLongsword{material}_longsworditem.spartan_weaponry_unofficial.{material}_longsword
createKatanaKatana{material}_katanaitem.spartan_weaponry_unofficial.{material}_katana
createSaberSaber{material}_saberitem.spartan_weaponry_unofficial.{material}_saber
createRapierRapier{material}_rapieritem.spartan_weaponry_unofficial.{material}_rapier
createGreatswordGreatsword{material}_greatsworditem.spartan_weaponry_unofficial.{material}_greatsword
createBattleHammerBattle Hammer{material}_battle_hammeritem.spartan_weaponry_unofficial.{material}_battle_hammer
createWarhammerWarhammer{material}_warhammeritem.spartan_weaponry_unofficial.{material}_warhammer
createSpearSpear{material}_spearitem.spartan_weaponry_unofficial.{material}_spear
createHalberdHalberd{material}_halberditem.spartan_weaponry_unofficial.{material}_halberd
createPikePike{material}_pikeitem.spartan_weaponry_unofficial.{material}_pike
createLanceLance{material}_lanceitem.spartan_weaponry_unofficial.{material}_lance
createLongbowStrengthened Longbowlongbow_{material}_strengtheneditem.spartan_weaponry_unofficial.longbow_{material}_strengthened
createHeavyCrossbowStrengthened Heavy Crossbowheavy_crossbow_{material}_strengtheneditem.spartan_weaponry_unofficial.heavy_crossbow_{material}_strengthened
createThrowingKnifeThrowing Knife{material}_throwing_knifeitem.spartan_weaponry_unofficial.{material}_throwing_knife
createTomahawkTomahawk{material}_tomahawkitem.spartan_weaponry_unofficial.{material}_tomahawk
createJavelinJavelin{material}_javelinitem.spartan_weaponry_unofficial.{material}_javelin
createBoomerangBoomerang{material}_boomerangitem.spartan_weaponry_unofficial.{material}_boomerang
createMaceMace{material}_maceitem.spartan_weaponry_unofficial.{material}_mace
createQuarterstaffQuarterstaff{material}_quarterstaffitem.spartan_weaponry_unofficial.{material}_quarterstaff
createGlaiveGlaive{material}_glaiveitem.spartan_weaponry_unofficial.{material}_glaive

Melee and throwing weapons use the {material}_{weapon} format:

// Melee weapon registration example
public static final DeferredHolder<Item, Item> IRON_LONGSWORD = ITEMS.register(
"iron_longsword", // {material}_{weapon} format
() -> SpartanWeaponryAPI.createLongsword(MyModMaterials.IRON)
);
// Throwing weapon registration example
public static final DeferredHolder<Item, Item> DIAMOND_THROWING_KNIFE = ITEMS.register(
"diamond_throwing_knife", // {material}_{weapon} format
() -> SpartanWeaponryAPI.createThrowingKnife(MyModMaterials.DIAMOND)
);
// Localization key format
// "item.spartan_weaponry_unofficial.iron_longsword": "Iron Longsword"
// "item.spartan_weaponry_unofficial.diamond_throwing_knife": "Diamond Throwing Knife"

Starting from version 1.0.3, longbows and heavy crossbows created via the extension API use a special format {weapontype}_{material}_strengthened:

// Longbow registration example
public static final DeferredHolder<Item, Item> DIAMOND_LONGBOW = ITEMS.register(
"longbow_diamond_strengthened", // Note format: longbow_{material}_strengthened
() -> SpartanWeaponryAPI.createLongbow(WeaponMaterial.DIAMOND)
);
// Heavy crossbow registration example
public static final DeferredHolder<Item, Item> IRON_HEAVY_CROSSBOW = ITEMS.register(
"heavy_crossbow_iron_strengthened", // Format: heavy_crossbow_{material}_strengthened
() -> SpartanWeaponryAPI.createHeavyCrossbow(WeaponMaterial.IRON)
);
// Localization key format
// "item.spartan_weaponry_unofficial.longbow_diamond_strengthened": "Diamond-Strengthened Longbow"
// "item.spartan_weaponry_unofficial.heavy_crossbow_iron_strengthened": "Iron-Strengthened Heavy Crossbow"

Texture file naming: Strengthened weapon texture files do not include the _strengthened suffix:

  • Registry name: longbow_diamond_strengthened
  • Texture path: textures/item/diamond_longbow_standby.png (no strengthened)
  • Texture path: textures/item/iron_heavy_crossbow_standby.png (no strengthened)

Traits are usually automatically assigned via Tags, but you can also specify them when defining WeaponMaterial. Common traits include:

  • WeaponTraits.REACH: Increases attack range (reach)
  • WeaponTraits.SWEEP_DAMAGE: Increases sweep damage (sweep_damage)
  • WeaponTraits.TWO_HANDED: Two-handed weapon, offhand restricted (two_handed)
  • WeaponTraits.ARMOUR_PIERCING: Pierces a percentage of armor (armour_piercing)
  • WeaponTraits.THROWN: Throwable (thrown)

Create a JSON file under data/spartan_weaponry_unofficial/tags/weapon_traits/:

{
"replace": false,
"values": [
"mymodid:longsword_my_material"
]
}