diff --git a/Common/src/main/java/dev/upcraft/sparkweave/api/item/CreativeTabHelper.java b/Common/src/main/java/dev/upcraft/sparkweave/api/item/CreativeTabHelper.java index 8395843..d99b16e 100644 --- a/Common/src/main/java/dev/upcraft/sparkweave/api/item/CreativeTabHelper.java +++ b/Common/src/main/java/dev/upcraft/sparkweave/api/item/CreativeTabHelper.java @@ -3,16 +3,40 @@ import dev.upcraft.sparkweave.api.platform.Services; import dev.upcraft.sparkweave.api.platform.services.SparkweaveHelperService; import dev.upcraft.sparkweave.api.registry.RegistryHandler; +import dev.upcraft.sparkweave.api.registry.item.CreativeTabFiller; +import net.minecraft.util.RandomSource; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.level.ItemLike; public class CreativeTabHelper { private static final SparkweaveHelperService HELPER = Services.getService(SparkweaveHelperService.class); + private static final RandomSource RANDOM_SOURCE = RandomSource.create(); - public static void addRegistryEntries(CreativeModeTab.Output collector, RegistryHandler itemProvider) { - itemProvider.stream().forEach(supplier -> collector.accept(supplier.get())); - } + public static void addRegistryEntries(CreativeModeTab.ItemDisplayParameters displayParameters, CreativeModeTab.Output collector, RegistryHandler itemProvider) { + itemProvider.stream().forEach(supplier -> { + + var registryObject = supplier.get(); + + if (registryObject instanceof CreativeTabFiller filler) { + filler.addItemsToTab(displayParameters, collector, RANDOM_SOURCE); + } else { + collector.accept(registryObject); + } + }); + } + + public static RandomSource getRandom() { + return RANDOM_SOURCE; + } + + /** + * @deprecated Use {@link #addRegistryEntries(CreativeModeTab.ItemDisplayParameters, CreativeModeTab.Output, RegistryHandler)} instead + */ + @Deprecated(since = "0.105.0", forRemoval = true) + public static void addRegistryEntries(CreativeModeTab.Output collector, RegistryHandler itemProvider) { + itemProvider.stream().forEach(supplier -> collector.accept(supplier.get())); + } public static CreativeModeTab.Builder newBuilder() { return HELPER.newCreativeTabBuilder(); diff --git a/Common/src/main/java/dev/upcraft/sparkweave/api/registry/item/CreativeTabFiller.java b/Common/src/main/java/dev/upcraft/sparkweave/api/registry/item/CreativeTabFiller.java new file mode 100644 index 0000000..3ad6bd9 --- /dev/null +++ b/Common/src/main/java/dev/upcraft/sparkweave/api/registry/item/CreativeTabFiller.java @@ -0,0 +1,9 @@ +package dev.upcraft.sparkweave.api.registry.item; + +import net.minecraft.util.RandomSource; +import net.minecraft.world.item.CreativeModeTab; + +public interface CreativeTabFiller { + + void addItemsToTab(CreativeModeTab.ItemDisplayParameters displayParameters, CreativeModeTab.Output collector, RandomSource random); +} diff --git a/Common/src/testmod/java/dev/upcraft/sparkweave/testmod/init/TestCreativeTabs.java b/Common/src/testmod/java/dev/upcraft/sparkweave/testmod/init/TestCreativeTabs.java index 484efae..f60f85e 100644 --- a/Common/src/testmod/java/dev/upcraft/sparkweave/testmod/init/TestCreativeTabs.java +++ b/Common/src/testmod/java/dev/upcraft/sparkweave/testmod/init/TestCreativeTabs.java @@ -15,7 +15,7 @@ public class TestCreativeTabs { public static final RegistrySupplier ITEMS = TABS.register("items", () -> CreativeTabHelper.newBuilder() .title(Component.translatable("itemGroup.sparkweave_testmod.items")) .icon(() -> TestItems.TEST_ITEM.get().getDefaultInstance()) - .displayItems((itemDisplayParameters, output) -> CreativeTabHelper.addRegistryEntries(output, TestItems.ITEMS)) + .displayItems((itemDisplayParameters, output) -> CreativeTabHelper.addRegistryEntries(itemDisplayParameters, output, TestItems.ITEMS)) .build() ); }