From 4a497e5c48dedbe614986f3308849473f46684bd Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Sat, 27 Jul 2024 22:55:46 +0100 Subject: [PATCH] feat: unified creative tab --- .../dev/ftb/mods/ftbquests/FTBQuests.java | 4 +-- .../ftbquests/client/FTBQuestsClient.java | 5 ++-- .../ftb/mods/ftbquests/registry/ModItems.java | 29 +++++++------------ fabric/build.gradle | 1 + gradle.properties | 2 +- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/common/src/main/java/dev/ftb/mods/ftbquests/FTBQuests.java b/common/src/main/java/dev/ftb/mods/ftbquests/FTBQuests.java index 5eed85d4..02be2a81 100644 --- a/common/src/main/java/dev/ftb/mods/ftbquests/FTBQuests.java +++ b/common/src/main/java/dev/ftb/mods/ftbquests/FTBQuests.java @@ -37,13 +37,13 @@ public class FTBQuests { public FTBQuests() { FTBQuestsAPI._init(FTBQuestsAPIImpl.INSTANCE); + PROXY = EnvExecutor.getEnvSpecific(() -> FTBQClientProxy::new, () -> FTBQServerProxy::new); + TaskTypes.init(); RewardTypes.init(); FTBQuestsNetHandler.init(); FTBQuestsEventHandler.INSTANCE.init(); - PROXY = EnvExecutor.getEnvSpecific(() -> FTBQClientProxy::new, () -> FTBQServerProxy::new); - ReloadListenerRegistry.register(PackType.SERVER_DATA, new TagReloadListener()); EnvExecutor.runInEnv(Env.CLIENT, () -> FTBQuestsClient::init); diff --git a/common/src/main/java/dev/ftb/mods/ftbquests/client/FTBQuestsClient.java b/common/src/main/java/dev/ftb/mods/ftbquests/client/FTBQuestsClient.java index f984df83..f0e3785c 100644 --- a/common/src/main/java/dev/ftb/mods/ftbquests/client/FTBQuestsClient.java +++ b/common/src/main/java/dev/ftb/mods/ftbquests/client/FTBQuestsClient.java @@ -6,6 +6,7 @@ import dev.architectury.registry.ReloadListenerRegistry; import dev.architectury.registry.client.keymappings.KeyMappingRegistry; import dev.architectury.registry.client.rendering.RenderTypeRegistry; +import dev.ftb.mods.ftblibrary.FTBLibrary; import dev.ftb.mods.ftblibrary.config.ImageResourceConfig; import dev.ftb.mods.ftblibrary.config.ui.EditConfigScreen; import dev.ftb.mods.ftblibrary.ui.Widget; @@ -157,7 +158,7 @@ public static void rebuildCreativeTabs() { player.canUseGameMasterBlocks(), player.level().registryAccess() ); - ModItems.CREATIVE_TAB.get().buildContents(params); + FTBLibrary.getCreativeModeTab().get().buildContents(params); CreativeModeTabs.searchTab().buildContents(params); } } @@ -173,4 +174,4 @@ public static Optional creativeTabDisplay public static void copyToClipboard(QuestObjectBase qo) { Widget.setClipboardString(qo.getCodeString()); } -} \ No newline at end of file +} diff --git a/common/src/main/java/dev/ftb/mods/ftbquests/registry/ModItems.java b/common/src/main/java/dev/ftb/mods/ftbquests/registry/ModItems.java index a4913de9..5565fdcc 100644 --- a/common/src/main/java/dev/ftb/mods/ftbquests/registry/ModItems.java +++ b/common/src/main/java/dev/ftb/mods/ftbquests/registry/ModItems.java @@ -2,22 +2,21 @@ import dev.architectury.registry.CreativeTabRegistry; import dev.architectury.registry.registries.DeferredRegister; -import dev.architectury.registry.registries.RegistrarManager; import dev.architectury.registry.registries.RegistrySupplier; +import dev.ftb.mods.ftblibrary.FTBLibrary; import dev.ftb.mods.ftbquests.FTBQuests; import dev.ftb.mods.ftbquests.api.FTBQuestsAPI; import dev.ftb.mods.ftbquests.item.*; import dev.ftb.mods.ftbquests.item.ScreenBlockItem.ScreenSize; import net.minecraft.core.registries.Registries; -import net.minecraft.network.chat.Component; import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; import java.util.List; import java.util.function.Supplier; +import java.util.stream.Stream; public class ModItems { public static final DeferredRegister ITEMS = DeferredRegister.create(FTBQuestsAPI.MOD_ID, Registries.ITEM); @@ -66,25 +65,17 @@ private static RegistrySupplier blockItemFor(String id, Supplier CREATIVE_TAB = RegistrarManager.get(FTBQuestsAPI.MOD_ID) - .get(Registries.CREATIVE_MODE_TAB) - .register(FTBQuestsAPI.rl("default"), ModItems::buildDefaultTab); + CreativeTabRegistry.appendStack(FTBLibrary.getCreativeModeTab(), BASE_ITEMS.stream().map(item -> () -> new ItemStack(item.get()))); - public static Item.Properties defaultProps() { - return new Item.Properties(); + Stream> lootCreates = FTBQuests.PROXY.getKnownLootCrates() + .stream() + .map(crate -> crate::createStack); + + CreativeTabRegistry.appendStack(FTBLibrary.getCreativeModeTab(), lootCreates); } - private static CreativeModeTab buildDefaultTab() { - return CreativeTabRegistry.create(builder -> builder.title(Component.translatable("ftbquests")) - .icon(() -> new ItemStack(BOOK.get())) - .displayItems((params, output) -> { - // base items, always present - output.acceptAll(BASE_ITEMS.stream().map(item -> new ItemStack(item.get())).toList()); - // dynamically add loot crates based on current reward tables - FTBQuests.PROXY.getKnownLootCrates().forEach(crate -> output.accept(crate.createStack())); - }) - ); + public static Item.Properties defaultProps() { + return new Item.Properties(); } } diff --git a/fabric/build.gradle b/fabric/build.gradle index 6ab52f01..eea54bc3 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -30,6 +30,7 @@ dependencies { } modApi("dev.ftb.mods:ftb-library-fabric:${rootProject.ftb_library_version}") { transitive false } + modApi("dev.ftb.mods:ftb-teams-fabric:${rootProject.ftb_teams_version}") { transitive false } common(project(path: ":common", configuration: "namedElements")) { transitive false } diff --git a/gradle.properties b/gradle.properties index 62f8ec1e..7c6e669c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,7 +23,7 @@ fabric_loader_version=0.15.11 fabric_api_version=0.100.1+1.21 architectury_api_version=13.0.2 -ftb_library_version=2100.1.2 +ftb_library_version=2100.1.4 ftb_teams_version=2100.1.0 # Optional deps