Skip to content

Instantly share code, notes, and snippets.

@TelepathicGrunt
Last active July 15, 2025 22:43
Show Gist options
  • Save TelepathicGrunt/ea0a99aa7fcd1f74dbb64297e3702fb5 to your computer and use it in GitHub Desktop.
Save TelepathicGrunt/ea0a99aa7fcd1f74dbb64297e3702fb5 to your computer and use it in GitHub Desktop.
Non-deferred NeoForge
@Mod(Mod.MODID)
public class Mod {
public static final String MODID = "mod";
public Mod(IEventBus modEventBus, ModContainer modContainer) {
modEventBus.addListener(ModItems::ModRegisterEvent);
}
}
public class ModItems {
public static Item ITEM_A;
public static Item ITEM_B;
private static void ModRegisterEvent(RegisterEvent registerEvent) {
ITEM_A = RegisterItem(registerEvent, "item_a", (key) -> new Item(new Item.Properties().setId(key)));
ITEM_B = RegisterItem(registerEvent, "item_b", (key) -> new Item(new Item.Properties().setId(key)));
}
private static void RegisterItem(RegisterEvent registerEvent, String itemName, Function<ResourceKey<Item>, Item> itemSupplier) {
ResourceKey<Item> itemResourceKey = ResourceKey.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(MODID, itemName));
registerEvent.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