Custom Compostable 26.2
Learn how to create your own compostable items.
Compostable items are those that convert to bone meal when they are placed in a composter. Let's see how we can create our own custom compostable.
Creating the Item
Let's create a compostable item called "Bone Marrow". We start by creating an item as usual:
java
public static final ResourceKey<Item> BONE_MARROW = create("bone_marrow");1
java
public static final Item BONE_MARROW = register(
ModItemIds.BONE_MARROW,
Item::new,
new Item.Properties()
);1
2
3
4
5
2
3
4
5
To make it compostable, we will add it to the CompostableRegistry.INSTANCE registry from the Fabric Registry API:
java
// Add the bone marrow to the composting registry with a 100% chance of increasing the composter's level.
CompostableRegistry.INSTANCE.add(ModItems.BONE_MARROW, 1.0f);1
2
2
As usual, don't forget to add a texture, translation, creative tab, yada yada. Here's an example texture:
Here's how it looks like when used in the composter:



