From 8adb648b8d07de30c9666aa0dc77879bbf21b945 Mon Sep 17 00:00:00 2001 From: LexManos Date: Sat, 10 Dec 2022 15:03:23 -0800 Subject: [PATCH] Redesign CreativeTab collection event to be a lot more straight forward. (#9198) --- src/main/java/com/example/examplemod/ExampleMod.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/examplemod/ExampleMod.java b/src/main/java/com/example/examplemod/ExampleMod.java index e4013ff..44199e6 100644 --- a/src/main/java/com/example/examplemod/ExampleMod.java +++ b/src/main/java/com/example/examplemod/ExampleMod.java @@ -58,8 +58,7 @@ public class ExampleMod MinecraftForge.EVENT_BUS.register(this); // Register the item to a creative tab - modEventBus.addListener((CreativeModeTabEvent.BuildContents event) -> event.registerSimple(CreativeModeTabs.BUILDING_BLOCKS, - EXAMPLE_BLOCK_ITEM.get())); + modEventBus.addListener(this::addCreative); } private void commonSetup(final FMLCommonSetupEvent event) @@ -69,6 +68,12 @@ public class ExampleMod LOGGER.info("DIRT BLOCK >> {}", ForgeRegistries.BLOCKS.getKey(Blocks.DIRT)); } + private void addCreative(CreativeModeTabEvent.BuildContents event) + { + if (event.getTab() == CreativeModeTabs.BUILDING_BLOCKS) + event.accept(EXAMPLE_BLOCK_ITEM); + } + // You can use SubscribeEvent and let the Event Bus discover methods to call @SubscribeEvent public void onServerStarting(ServerStartingEvent event)