Path: blob/1.21.x/patches/minecraft/net/minecraft/world/item/CreativeModeTab.java.patch
7504 views
--- a/net/minecraft/world/item/CreativeModeTab.java1+++ b/net/minecraft/world/item/CreativeModeTab.java2@@ -28,6 +_,12 @@3private Set<ItemStack> displayItemsSearchTab = ItemStackLinkedSet.createTypeAndComponentsSet();4private final Supplier<ItemStack> iconGenerator;5private final CreativeModeTab.DisplayItemsGenerator displayItemsGenerator;6+ private final boolean hasSearchBar;7+ private final int searchBarWidth;8+ private final int labelColor;9+ private final int slotColor;10+ public final java.util.List<net.minecraft.resources.ResourceLocation> tabsBefore;11+ public final java.util.List<net.minecraft.resources.ResourceLocation> tabsAfter;1213CreativeModeTab(14CreativeModeTab.Row p_260217_,15@@ -35,7 +_,8 @@16CreativeModeTab.Type p_260176_,17Component p_260100_,18Supplier<ItemStack> p_259543_,19- CreativeModeTab.DisplayItemsGenerator p_259085_20+ CreativeModeTab.DisplayItemsGenerator p_259085_,21+ Builder builder22) {23this.row = p_260217_;24this.column = p_259557_;25@@ -43,12 +_,27 @@26this.iconGenerator = p_259543_;27this.displayItemsGenerator = p_259085_;28this.type = p_260176_;29+ this.hasSearchBar = builder.hasSearchBar;30+ this.searchBarWidth = builder.searchBarWidth;31+ this.labelColor = builder.labelColor;32+ this.slotColor = builder.slotColor;33+ this.tabsBefore = java.util.List.copyOf(builder.tabsBefore);34+ this.tabsAfter = java.util.List.copyOf(builder.tabsAfter);35+ }36+37+ protected CreativeModeTab(CreativeModeTab.Builder builder) {38+ this(builder.row, builder.column, builder.type, builder.displayName, builder.iconGenerator, builder.displayItemsGenerator, builder);39+ }40+41+ public static CreativeModeTab.Builder builder() {42+ return new CreativeModeTab.Builder(Row.TOP, 0);43}4445public static ResourceLocation createTextureLocation(String p_343491_) {46return ResourceLocation.withDefaultNamespace("textures/gui/container/creative_inventory/tab_" + p_343491_ + ".png");47}4849+ /** @deprecated Forge: use {@link #builder()} **/50public static CreativeModeTab.Builder builder(CreativeModeTab.Row p_259342_, int p_260312_) {51return new CreativeModeTab.Builder(p_259342_, p_260312_);52}53@@ -106,7 +_,7 @@54ResourceKey<CreativeModeTab> resourcekey = BuiltInRegistries.CREATIVE_MODE_TAB55.getResourceKey(this)56.orElseThrow(() -> new IllegalStateException("Unregistered creative tab: " + this));57- this.displayItemsGenerator.accept(p_270156_, creativemodetab$itemdisplaybuilder);58+ net.minecraftforge.common.ForgeHooks.onCreativeModeTabBuildContents(this, resourcekey, this.displayItemsGenerator, p_270156_, creativemodetab$itemdisplaybuilder);59this.displayItems = creativemodetab$itemdisplaybuilder.tabContents;60this.displayItemsSearchTab = creativemodetab$itemdisplaybuilder.searchTabContents;61}62@@ -123,6 +_,22 @@63return this.displayItemsSearchTab.contains(p_259317_);64}6566+ public boolean hasSearchBar() {67+ return this.hasSearchBar;68+ }69+70+ public int getSearchBarWidth() {71+ return searchBarWidth;72+ }73+74+ public int getLabelColor() {75+ return labelColor;76+ }77+78+ public int getSlotColor() {79+ return slotColor;80+ }81+82public static class Builder {83private static final CreativeModeTab.DisplayItemsGenerator EMPTY_GENERATOR = (p_270422_, p_259433_) -> {};84private final CreativeModeTab.Row row;85@@ -135,6 +_,14 @@86private boolean alignedRight = false;87private CreativeModeTab.Type type = CreativeModeTab.Type.CATEGORY;88private ResourceLocation backgroundTexture = CreativeModeTab.DEFAULT_BACKGROUND;89+ private boolean hasSearchBar = false;90+ private int searchBarWidth = 89;91+ private int labelColor = 0xff404040;92+ private int slotColor = -2130706433;93+ private java.util.function.Function<CreativeModeTab.Builder, CreativeModeTab> tabFactory =94+ builder -> new CreativeModeTab(builder.row, builder.column, builder.type, builder.displayName, builder.iconGenerator, builder.displayItemsGenerator, builder);95+ private final java.util.List<net.minecraft.resources.ResourceLocation> tabsBefore = new java.util.ArrayList<>();96+ private final java.util.List<net.minecraft.resources.ResourceLocation> tabsAfter = new java.util.ArrayList<>();9798public Builder(CreativeModeTab.Row p_259171_, int p_259661_) {99this.row = p_259171_;100@@ -173,6 +_,9 @@101102protected CreativeModeTab.Builder type(CreativeModeTab.Type p_259283_) {103this.type = p_259283_;104+ if (p_259283_ == Type.SEARCH) {105+ return this.withSearchBar();106+ }107return this;108}109110@@ -181,13 +_,78 @@111return this;112}113114+ /**115+ * Gives this tab a search bar.116+ * <p>Note that, if using a custom {@link #withBackgroundLocation(net.minecraft.resources.ResourceLocation) background image}, you will need to make sure that your image contains the input box and the scroll bar.</p>117+ */118+ public CreativeModeTab.Builder withSearchBar() {119+ this.hasSearchBar = true;120+ if (this.backgroundTexture == CreativeModeTab.DEFAULT_BACKGROUND)121+ return this.backgroundTexture(createTextureLocation("item_search"));122+ return this;123+ }124+125+ /**126+ * Gives this tab a search bar, with a specific width.127+ * @param searchBarWidth the width of the search bar128+ */129+ public CreativeModeTab.Builder withSearchBar(int searchBarWidth) {130+ this.searchBarWidth = searchBarWidth;131+ return withSearchBar();132+ }133+134+ /**135+ * Sets the color of the tab label.136+ */137+ public CreativeModeTab.Builder withLabelColor(int labelColor) {138+ this.labelColor = labelColor;139+ return this;140+ }141+142+ /**143+ * Sets the color of tab's slots.144+ */145+ public CreativeModeTab.Builder withSlotColor(int slotColor) {146+ this.slotColor = slotColor;147+ return this;148+ }149+150+ public CreativeModeTab.Builder withTabFactory(java.util.function.Function<CreativeModeTab.Builder, CreativeModeTab> tabFactory) {151+ this.tabFactory = tabFactory;152+ return this;153+ }154+155+ /** Define tabs that should come <i>before</i> this tab. This tab will be placed <strong>after</strong> the {@code tabs}. **/156+ public CreativeModeTab.Builder withTabsBefore(net.minecraft.resources.ResourceLocation... tabs) {157+ this.tabsBefore.addAll(java.util.List.of(tabs));158+ return this;159+ }160+161+ /** Define tabs that should come <i>after</i> this tab. This tab will be placed <strong>before</strong> the {@code tabs}.**/162+ public CreativeModeTab.Builder withTabsAfter(net.minecraft.resources.ResourceLocation... tabs) {163+ this.tabsAfter.addAll(java.util.List.of(tabs));164+ return this;165+ }166+167+ /** Define tabs that should come <i>before</i> this tab. This tab will be placed <strong>after</strong> the {@code tabs}. **/168+ @SafeVarargs169+ public final CreativeModeTab.Builder withTabsBefore(net.minecraft.resources.ResourceKey<CreativeModeTab>... tabs) {170+ java.util.stream.Stream.of(tabs).map(net.minecraft.resources.ResourceKey::location).forEach(this.tabsBefore::add);171+ return this;172+ }173+174+ /** Define tabs that should come <i>after</i> this tab. This tab will be placed <strong>before</strong> the {@code tabs}.**/175+ @SafeVarargs176+ public final CreativeModeTab.Builder withTabsAfter(net.minecraft.resources.ResourceKey<CreativeModeTab>... tabs) {177+ java.util.stream.Stream.of(tabs).map(net.minecraft.resources.ResourceKey::location).forEach(this.tabsAfter::add);178+ return this;179+ }180+181public CreativeModeTab build() {182if ((this.type == CreativeModeTab.Type.HOTBAR || this.type == CreativeModeTab.Type.INVENTORY) && this.displayItemsGenerator != EMPTY_GENERATOR) {183throw new IllegalStateException("Special tabs can't have display items");184} else {185- CreativeModeTab creativemodetab = new CreativeModeTab(186- this.row, this.column, this.type, this.displayName, this.iconGenerator, this.displayItemsGenerator187- );188+ CreativeModeTab creativemodetab = this.tabFactory.apply(this);189creativemodetab.alignedRight = this.alignedRight;190creativemodetab.showTitle = this.showTitle;191creativemodetab.canScroll = this.canScroll;192193194