Skip to content

API Reference

Quick reference for the public static methods of ModularAmmoAPI, grouped by function.

Binding & Queries

Method signatureParametersReturnsDescription
bindGun(ResourceLocation gunId, ResourceLocation ammoTypeId)gunId — gun id (modularshoot:guns registry); ammoTypeId — ammo type id (modularshootammo:ammo_types registry)voidJava API binding of gun→ammo. Java bindings take priority over data packs and survive /reload; already-issued guns of that id are affected immediately
getAmmoTypeIdForGun(RegistryAccess ra, ResourceLocation gunId)ra — runtime registry view; gunId — gun idOptional<ResourceLocation>Queries the bound ammo type id (Java first, data pack fallback); empty when unbound
getAmmoType(RegistryAccess ra, ResourceLocation ammoTypeId)ra — runtime registry view; ammoTypeId — ammo type registry idOptional<AmmoType>Queries an ammo type definition by id

Trait Checks

Traits are final merged values (gun base + plugin contributions, merged via the framework's TraitMergeService); undeclared traits return false.

Method signatureParametersReturnsDescription
isUsesAmmo(ItemStack gun, RegistryAccess ra)gun — gun item; ra — runtime registry viewbooleanWhether the gun has the ammo system enabled (uses_ammo trait)
isInfiniteAmmo(ItemStack gun, RegistryAccess ra)Same as abovebooleanWhether the gun is exempt from ammo deduction (infinite_ammo trait, HUD shows ∞)

Registry Keys

The data pack dynamic registries are declared in ModularAmmoRegistries (registered on the mod bus via DataPackRegistryEvent.NewRegistry, support /reload, sync to clients):

ConstantRegistry IDEntry typePurpose
AMMO_TYPES_KEYmodularshootammo:ammo_typesAmmoTypeAmmo type definitions (name, color, item, reserve cap, per-shot cost, reload sound)
GUN_AMMO_BINDINGS_KEYmodularshootammo:gun_ammo_bindingsGunAmmoBindingGun→ammo binding table

Data Types

AmmoType (record)

FieldTypeDescription
name()StringDisplay name, supports the lang: prefix
color()intIdentifier color ARGB (a "#RRGGBB" string in JSON)
item()ResourceLocationAmmo item id
reserveLimit()Integer (nullable)Reserve cap; null when undeclared
perShotCost()intAmmo consumed per shot, default 1
reloadSound()ResourceLocation (nullable)Reload sound override; null when undeclared

GunAmmoBinding (record)

FieldTypeDescription
ammoType()ResourceLocationThe bound ammo type id

Usage Example

java
// Code binding: bind an assault rifle to rifle_ammo
ModularAmmoAPI.bindGun(
        ResourceLocation.fromNamespaceAndPath("mymod", "assault_rifle"),
        ResourceLocation.fromNamespaceAndPath("modularshootammo", "rifle_ammo"));

// Query the held gun's ammo info
ItemStack gun = player.getMainHandItem();
RegistryAccess ra = player.registryAccess();
if (ModularAmmoAPI.isUsesAmmo(gun, ra)) {
    Optional<AmmoType> type = ModularAmmoAPI.getAmmoTypeIdForGun(ra, ModularShootAPI.getGunId(gun))
            .flatMap(id -> ModularAmmoAPI.getAmmoType(ra, id));
    type.ifPresent(t -> System.out.println("ammo item: " + t.item()));
}

Released under the MIT License