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