Items

Nickruig

New Member
How can I change the starter items in your inventory when you join a world?

and

How can I add items?

#Nickruig
 

Immortius

Lead Software Architect
Contributor
Architecture
GUI
1. If you're just doing this for your own benefit, alter PlayerFactory.
2. If you want something you can give to other people, create a module with a component system that intercepts the OnPlayerSpawnedEvent and alters the player's inventory.
 

Josharias

Conjurer of Grimoires
Contributor
World
SpecOps
This is a little late, but would be useful for anyone else starting out modding.

If doing Immortius suggestion #2, this code should get you most of the way there:

Code:
@RegisterSystem
public class PlayerStartingInventorySystem implements ComponentSystem {
 
    @In
    BlockManager blockManager;
    @In
    InventoryManager inventoryManager;
    @In
    EntityManager entityManager;
 
    @ReceiveEvent
    public void OnPlayerSpawnedEvent(OnPlayerSpawnedEvent event, EntityRef player) {
        BlockItemFactory blockItemFactory = new BlockItemFactory(entityManager);
 
        inventoryManager.giveItem(player, entityManager.create("modName:itemName"));
        inventoryManager.giveItem(player, blockItemFactory.newInstance(blockManager.getBlockFamily("modName:blockName"), 99));
    }
 
    @Override
    public void initialise() {
    }
 
    @Override
    public void shutdown() {
    }
}
 
Top