User Tools

Site Tools


Chunk Stories's Items system

(wip specification, do not make anything with this)

To enable content creators to create intricate gamemodes Chunk Stories offers a extensible items system. Items are defined in .items files, using the usual NamedWithProperties file format syntax.

.items files format

The structure of those files is laid out as :

item 1 dull_item
    #Width of this item in the inventory
    width: 2
    max-stack-size: 50 #Default 100

item 3 unsafe_grenade
    customClass: me.example.mod.ItemRustyGrenade
    #You can declare custom properties using the NWP mechanics
    maxSafety: 0.4

item 484 old_grenade ...

end and

The Item system revolves around three classes : The Item class, The ItemType class and the ItemPile class. The ItemType class is the 'definition' of the item, it's a static/final field your Items objects are initialized in. It does not contain the information of one item, instead it relies on the Item class to store it's data. The ItemPile serves only to stack and store the Item objects in the actual game. You are only allowed to mess with the Item class. Code is provided with the API provided with the game.

A typical example would be this grenade class:

/** An unsafe grenade found in military surplus */
class ItemRustyGrenade extends Item {

    //To be extra clear: this variable exists per-item instance and isn't global
    float changeToBlowUser;

    //Item is initialized with ItemType
    public ItemRustyGrenade(ItemType type)
        changeToBlowUser = Math.random() * Float.parseFloat(type.resolveProperty("maxSafety", 1.0));
        itemRenderer = new RustyItemRenderer(this);

    //ItemPile is the itemPile selected by the user when he tries to interact with it
    public boolean handleInteraction(Entity user, ItemPile itemPile, Input input, Controller controller)
            return false;
        if(Math.random() < chanceToBlowUser)
            // If he's unlucky he gets blowns to smithereens
            user.getWorld().createExplosion(user.getLocation(), 15f);
            user.sendMessage("Lucky boy");
            // Throw the grenade as normal
        //This item handled the interaction, it should not trigger anything else
        return true;
items.txt · Last modified: 2017/02/14 17:24 by gobrosse