Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify tabs and make them more like the forge version of create #1302

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 6 additions & 29 deletions src/main/java/com/simibubi/create/AllCreativeModeTabs.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ public class AllCreativeModeTabs {
() -> FabricItemGroup.builder()
.title(Components.translatable("itemGroup.create.base"))
.icon(() -> AllBlocks.COGWHEEL.asStack())
.displayItems(new RegistrateDisplayItemsGenerator(true, Tabs.BASE))
.displayItems(new RegistrateDisplayItemsGenerator(true, () -> AllCreativeModeTabs.BASE_CREATIVE_TAB))
.build());

public static final TabInfo PALETTES_CREATIVE_TAB = register("palettes",
() -> FabricItemGroup.builder()
.title(Components.translatable("itemGroup.create.palettes"))
.icon(() -> AllPaletteBlocks.ORNATE_IRON_WINDOW.asStack())
.displayItems(new RegistrateDisplayItemsGenerator(false, Tabs.PALETTES))
.displayItems(new RegistrateDisplayItemsGenerator(false, () -> AllCreativeModeTabs.PALETTES_CREATIVE_TAB))
.build());

private static TabInfo register(String name, Supplier<CreativeModeTab> supplier) {
Expand All @@ -81,29 +81,6 @@ public static void register() {
// fabric: just load the class
}

public static ResourceKey<CreativeModeTab> getBaseTabKey() {
return BASE_CREATIVE_TAB.key();
}

public static ResourceKey<CreativeModeTab> getPalettesTabKey() {
return PALETTES_CREATIVE_TAB.key();
}

public enum Tabs {
BASE(AllCreativeModeTabs::getBaseTabKey),
PALETTES(AllCreativeModeTabs::getPalettesTabKey);

private final Supplier<ResourceKey<CreativeModeTab>> keySupplier;

Tabs(Supplier<ResourceKey<CreativeModeTab>> keySupplier) {
this.keySupplier = keySupplier;
}

public ResourceKey<CreativeModeTab> getKey() {
return keySupplier.get();
}
}

private static class RegistrateDisplayItemsGenerator implements DisplayItemsGenerator {
private static final Predicate<Item> IS_ITEM_3D_PREDICATE;

Expand Down Expand Up @@ -131,9 +108,9 @@ private static Predicate<Item> makeClient3dItemPredicate() {
}

private final boolean addItems;
private final Tabs tabFilter;
private final Supplier<TabInfo> tabFilter;

public RegistrateDisplayItemsGenerator(boolean addItems, Tabs tabFilter) {
public RegistrateDisplayItemsGenerator(boolean addItems, Supplier<TabInfo> tabFilter) {
this.addItems = addItems;
this.tabFilter = tabFilter;
}
Expand Down Expand Up @@ -307,7 +284,7 @@ public void accept(ItemDisplayParameters parameters, Output output) {
private List<Item> collectBlocks(Predicate<Item> exclusionPredicate) {
List<Item> items = new ReferenceArrayList<>();
for (RegistryEntry<Block> entry : Create.REGISTRATE.getAll(Registries.BLOCK)) {
if (!CreateRegistrate.isInCreativeTab(entry, tabFilter.getKey()))
if (!CreateRegistrate.isInCreativeTab(entry, tabFilter.get().key()))
continue;
Item item = entry.get()
.asItem();
Expand All @@ -323,7 +300,7 @@ private List<Item> collectBlocks(Predicate<Item> exclusionPredicate) {
private List<Item> collectItems(Predicate<Item> exclusionPredicate) {
List<Item> items = new ReferenceArrayList<>();
for (RegistryEntry<Item> entry : Create.REGISTRATE.getAll(Registries.ITEM)) {
if (!CreateRegistrate.isInCreativeTab(entry, tabFilter.getKey()))
if (!CreateRegistrate.isInCreativeTab(entry, tabFilter.get().key()))
continue;
Item item = entry.get();
if (item instanceof BlockItem)
Expand Down
Loading