Skip to content

Instantly share code, notes, and snippets.

@TelepathicGrunt
Last active July 15, 2025 22:43
Show Gist options
  • Save TelepathicGrunt/4d3164b4c55ab18f2c86df96e2802da2 to your computer and use it in GitHub Desktop.
Save TelepathicGrunt/4d3164b4c55ab18f2c86df96e2802da2 to your computer and use it in GitHub Desktop.
Fabric non-classload register
public class Mod implements ModInitializer {
public static final String MODID = "mod";
@Override
public void onInitialize() {
ModItems.registerItems();
}
}
public class ModItems {
public static Item ITEM_A;
public static Item ITEM_B;
public static void registerItems() {
ITEM_A = RegisterItem("item_a", (key) -> new Item(new Item.Properties().setId(key)));
ITEM_B = RegisterItem("item_b", (key) -> new Item(new Item.Properties().setId(key)));
}
private static Item RegisterItem(String itemName, Function<ResourceKey<Item>, Item> itemSupplier) {
ResourceKey<Item> itemResourceKey = ResourceKey.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(MODID, itemName));
return Registry.register(Registries.ITEM, itemResourceKey.location(), itemSupplier.apply(itemResourceKey));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment