Skip to content

A module that adds everything needed for items within a game. Inspired by games like Minecraft and Minetest.

License

Notifications You must be signed in to change notification settings

catmeow72/godot-inventories

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

WARNING

This module is ALPHA quality! It relies on the latest Godot 4.0 beta and is completely untested on the stable version of Godot!

Here be dragons!

Godot Inventories module

A Godot 4.0 module that adds everything needed for items to the engine.

Allows custom behavior for items and slots using virtual methods.

Features

  • Items
  • Slots
  • Script-driven item behavior
  • Crafting recipes
  • Loot tables

Limitations so far.

Items always use a single texture atlas in PNG format in a predefined location - This will be changed! Item scripts must be instantiated before registration

How to use this module in a project

First of all, this is a Godot module that must be built as part of the engine.

Once you are running a build of the engine with this module, you can follow these steps

  1. Create the texture for each item.
  2. Write item scripts extending ItemData. They can be in any language, as long as they can be instantiated before registering!
  3. Register the items before any items are loaded.
  • Use the ItemRegistry.register(StringName id, ItemData data) static function to register the items.
  • Make sure to instantiate the scripts with the .new() function!
  1. Add an inventory instance somewhere in the project that can be used by inventory slots.
  • Make sure to set the size property or the inventory will not work!
  1. Add a container to hold the inventory slots and create those slots, hopefully by a script.
  • The slot_id and inventory properties need to be set.
  1. Once you start adding slots, add a SlotHelper node
  • This should be in a CanvasLayer node with a higher priority than the slots themselves so that the slot tooltip (when hovering over a slot) and any items being moved show above the slots at all times.
  1. Create a node that will use the item(s) associated with it.
  2. If you want crafting recipes, create crafting recipe resources and register them with the static CraftingRecipe.register(CraftingRecipe recipe) function.
  3. Loot tables can be used like normal resources. Just call the get_output() function on the LootTable resource to get the output of the resource.

Items

  • Null items should be considered empty.
    • Item.is_empty_or_null(Item item) takes the possibility of a null item into account when checking, so this function should be preferred over Item.is_empty().
    • Empty items should be handled as if they are null.
  • Item IDs are represented by the Item.id property.
  • Item counts are represented by the Item.count property.
  • Do not register items with the ID of empty. This ID is reserved for empty items.
  • To clone an item, use the Item.clone() method.

Crafting recipes

  • Craftable recipes can be queried using the CraftingRecipes.all_craftable(Inventory inventory) and CraftingRecipes.all_registered() static functions.
  • If a crafting recipe has been crafted by cloning the output directly without using the CraftingRecipe.craft(Inventory inventory) function, use the CraftingRecipe.take_inputs(Inventory inventory) function to take the inputs of the crafting recipe.

About

A module that adds everything needed for items within a game. Inspired by games like Minecraft and Minetest.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages