mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 16:27:47 +00:00
Fix custom creative tabs with search listing all items instead of just their own.
This commit is contained in:
4 files changed
+39
-18
No files matched your search
+1
-1
@@ -176,7 +176,7 @@
|
||||
boolean flag = this.hoveredSlot != null && this.hoveredSlot instanceof CreativeModeInventoryScreen.CustomCreativeSlot;
|
||||
boolean flag1 = selectedTab.getType() == CreativeModeTab.Type.CATEGORY;
|
||||
- boolean flag2 = selectedTab.getType() == CreativeModeTab.Type.SEARCH;
|
||||
+ boolean flag2 =selectedTab.hasSearchBar();
|
||||
+ boolean flag2 = selectedTab.hasSearchBar();
|
||||
TooltipFlag.Default tooltipflag$default = this.minecraft.options.advancedItemTooltips ? TooltipFlag.Default.ADVANCED : TooltipFlag.Default.NORMAL;
|
||||
TooltipFlag tooltipflag = flag ? tooltipflag$default.asCreative() : tooltipflag$default;
|
||||
List<Component> list = p_281769_.getTooltipLines(Item.TooltipContext.of(this.minecraft.level), this.minecraft.player, tooltipflag);
|
||||
|
||||
@@ -11,21 +11,23 @@
|
||||
private CompletableFuture<SearchTree<RecipeCollection>> recipeSearch = CompletableFuture.completedFuture(SearchTree.empty());
|
||||
private final Map<SessionSearchTrees.Key, Runnable> reloaders = new IdentityHashMap<>();
|
||||
|
||||
@@ -82,44 +_,50 @@
|
||||
@@ -82,44 +_,52 @@
|
||||
}
|
||||
|
||||
public void updateCreativeTags(List<ItemStack> p_344581_) {
|
||||
+ for (var name : net.minecraftforge.client.CreativeModeTabSearchRegistry.getTagSearchKeys().values())
|
||||
+ for (var entry : net.minecraftforge.client.CreativeModeTabSearchRegistry.getTagSearchKeys().entrySet())
|
||||
this.register(
|
||||
- CREATIVE_TAGS,
|
||||
+ name,
|
||||
+ entry.getValue(),
|
||||
() -> {
|
||||
- CompletableFuture<?> completablefuture = this.creativeByTagSearch;
|
||||
- this.creativeByTagSearch = CompletableFuture.supplyAsync(
|
||||
+ CompletableFuture<?> completablefuture = this.creativeSearch.getOrDefault(name, EMPTY);
|
||||
+ this.creativeSearch.put(name, CompletableFuture.supplyAsync(
|
||||
() -> new IdSearchTree<>(p_342206_ -> p_342206_.getTags().map(TagKey::location), p_344581_), Util.backgroundExecutor()
|
||||
- () -> new IdSearchTree<>(p_342206_ -> p_342206_.getTags().map(TagKey::location), p_344581_), Util.backgroundExecutor()
|
||||
- );
|
||||
+ var items = entry.getKey() == net.minecraft.world.item.CreativeModeTabs.searchTab() ? p_344581_ : List.copyOf(entry.getKey().getDisplayItems());
|
||||
+ CompletableFuture<?> completablefuture = this.creativeSearch.getOrDefault(entry.getValue(), EMPTY);
|
||||
+ this.creativeSearch.put(entry.getValue(), CompletableFuture.supplyAsync(
|
||||
+ () -> new IdSearchTree<>(p_342206_ -> p_342206_.getTags().map(TagKey::location), items), Util.backgroundExecutor()
|
||||
+ ));
|
||||
completablefuture.cancel(true);
|
||||
}
|
||||
@@ -38,21 +40,23 @@
|
||||
}
|
||||
|
||||
public void updateCreativeTooltips(HolderLookup.Provider p_343364_, List<ItemStack> p_342500_) {
|
||||
+ for (var name : net.minecraftforge.client.CreativeModeTabSearchRegistry.getNameSearchKeys().values())
|
||||
+ for (var entry : net.minecraftforge.client.CreativeModeTabSearchRegistry.getNameSearchKeys().entrySet())
|
||||
this.register(
|
||||
- CREATIVE_NAMES,
|
||||
+ name,
|
||||
+ entry.getValue(),
|
||||
() -> {
|
||||
+ var items = entry.getKey() == net.minecraft.world.item.CreativeModeTabs.searchTab() ? p_342500_ : List.copyOf(entry.getKey().getDisplayItems());
|
||||
Item.TooltipContext item$tooltipcontext = Item.TooltipContext.of(p_343364_);
|
||||
TooltipFlag tooltipflag = TooltipFlag.Default.NORMAL.asCreative();
|
||||
- CompletableFuture<?> completablefuture = this.creativeByNameSearch;
|
||||
- this.creativeByNameSearch = CompletableFuture.supplyAsync(
|
||||
+ CompletableFuture<?> completablefuture = this.creativeSearch.getOrDefault(name, EMPTY);
|
||||
+ this.creativeSearch.put(name, CompletableFuture.supplyAsync(
|
||||
+ CompletableFuture<?> completablefuture = this.creativeSearch.getOrDefault(entry.getValue(), EMPTY);
|
||||
+ this.creativeSearch.put(entry.getValue(), CompletableFuture.supplyAsync(
|
||||
() -> new FullTextSearchTree<>(
|
||||
p_345254_ -> getTooltipLines(Stream.of(p_345254_), item$tooltipcontext, tooltipflag),
|
||||
p_344415_ -> p_344415_.getItemHolder().unwrapKey().map(ResourceKey::location).stream(),
|
||||
p_342500_
|
||||
- p_342500_
|
||||
+ items
|
||||
),
|
||||
Util.backgroundExecutor()
|
||||
- );
|
||||
|
||||
@@ -118,8 +118,8 @@
|
||||
+ */
|
||||
+ public CreativeModeTab.Builder withSearchBar() {
|
||||
+ this.hasSearchBar = true;
|
||||
+ if (this.backgroundTexture == null)
|
||||
+ return this.backgroundTexture(createTextureLocation("item_seach"));
|
||||
+ if (this.backgroundTexture == CreativeModeTab.DEFAULT_BACKGROUND)
|
||||
+ return this.backgroundTexture(createTextureLocation("item_search"));
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
|
||||
@@ -16,6 +16,7 @@ import net.minecraft.world.item.CreativeModeTabs;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.item.DyeItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
@@ -32,6 +33,8 @@ public class CreativeModeTabTest {
|
||||
|
||||
private static final ResourceKey<CreativeModeTab> LOGS = ResourceKey.create(Registries.CREATIVE_MODE_TAB, ResourceLocation.fromNamespaceAndPath(MOD_ID, "logs"));
|
||||
private static final ResourceKey<CreativeModeTab> STONE = ResourceKey.create(Registries.CREATIVE_MODE_TAB, ResourceLocation.fromNamespaceAndPath(MOD_ID, "stone"));
|
||||
private static final ResourceKey<CreativeModeTab> COLORS = ResourceKey.create(Registries.CREATIVE_MODE_TAB, ResourceLocation.fromNamespaceAndPath(MOD_ID, "colors"));
|
||||
private static final ResourceKey<CreativeModeTab> SEARCH = ResourceKey.create(Registries.CREATIVE_MODE_TAB, ResourceLocation.fromNamespaceAndPath(MOD_ID, "search"));
|
||||
|
||||
public CreativeModeTabTest() {
|
||||
if (!ENABLED)
|
||||
@@ -58,7 +61,8 @@ public class CreativeModeTabTest {
|
||||
})
|
||||
.build());
|
||||
|
||||
helper.register(STONE, CreativeModeTab.builder().icon(() -> new ItemStack(Blocks.STONE))
|
||||
helper.register(STONE, CreativeModeTab.builder()
|
||||
.icon(() -> new ItemStack(Blocks.STONE))
|
||||
.title(Component.literal("Stone"))
|
||||
.withLabelColor(0x0000FF)
|
||||
.displayItems((params, output) -> {
|
||||
@@ -67,16 +71,29 @@ public class CreativeModeTabTest {
|
||||
output.accept(new ItemStack(Blocks.DIORITE));
|
||||
output.accept(new ItemStack(Blocks.ANDESITE));
|
||||
})
|
||||
.withTabsAfter(CreativeModeTabs.BUILDING_BLOCKS)
|
||||
.withTabsBefore(LOGS)
|
||||
.build());
|
||||
|
||||
helper.register(ResourceLocation.fromNamespaceAndPath(MOD_ID, "colors"), CreativeModeTab.builder().title(Component.literal("Colors"))
|
||||
helper.register(COLORS, CreativeModeTab.builder()
|
||||
.title(Component.literal("Colors"))
|
||||
.displayItems((params, output) -> {
|
||||
for (DyeColor color : DyeColor.values())
|
||||
output.accept(DyeItem.byColor(color));
|
||||
})
|
||||
.withTabFactory(CreativeModeColorTab::new)
|
||||
.withTabsBefore(CreativeModeTabs.COLORED_BLOCKS)
|
||||
.withTabsBefore(STONE)
|
||||
.build()
|
||||
);
|
||||
|
||||
helper.register(SEARCH, CreativeModeTab.builder()
|
||||
.title(Component.literal("Search"))
|
||||
.icon(() -> new ItemStack(Items.BOOKSHELF))
|
||||
.displayItems((params, output) -> {
|
||||
for (DyeColor color : DyeColor.values())
|
||||
output.accept(DyeItem.byColor(color));
|
||||
})
|
||||
.withTabsBefore(COLORS)
|
||||
.withSearchBar()
|
||||
.build()
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user