Skip to content

Commit

Permalink
Merge pull request #747 from FTBTeam/feature/unified-creative-tab
Browse files Browse the repository at this point in the history
feat: unified creative tab
  • Loading branch information
desht authored Jul 31, 2024
2 parents 88198b9 + 4a497e5 commit 0120b1a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 24 deletions.
4 changes: 2 additions & 2 deletions common/src/main/java/dev/ftb/mods/ftbquests/FTBQuests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -173,4 +174,4 @@ public static Optional<CreativeModeTab.ItemDisplayParameters> creativeTabDisplay
public static void copyToClipboard(QuestObjectBase qo) {
Widget.setClipboardString(qo.getCodeString());
}
}
}
29 changes: 10 additions & 19 deletions common/src/main/java/dev/ftb/mods/ftbquests/registry/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item> ITEMS = DeferredRegister.create(FTBQuestsAPI.MOD_ID, Registries.ITEM);
Expand Down Expand Up @@ -66,25 +65,17 @@ private static RegistrySupplier<Item> blockItemFor(String id, Supplier<BlockItem

public static void register() {
ITEMS.register();
}

public static final RegistrySupplier<CreativeModeTab> 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<Supplier<ItemStack>> 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();
}
}
1 change: 1 addition & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0120b1a

Please sign in to comment.