Skip to content

Commit

Permalink
Fix creative tab search not working
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Sep 4, 2024
1 parent d05376b commit f5574f0
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.item.CreativeModeTab;
Expand All @@ -30,6 +32,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public final class ItemStackListFactory {
private static final Logger LOGGER = LogManager.getLogger();
Expand Down Expand Up @@ -62,7 +65,22 @@ public static List<ItemStack> create(StackHelper stackHelper) {
}
RegistryAccess registryAccess = level.registryAccess();

CreativeModeTabs.tryRebuildTabContents(features, hasOperatorItemsTabPermissions, registryAccess);
// hack:
// The creative menu search will call CreativeModeTabs.tryRebuildTabContents and not run
// if the CreativeModeTabs.CACHED_PARAMETERS exactly match its parameters.
// Using a "different" RegistryAccess here ensures the parameters don't match.
RegistryAccess jeiRegistryAccess = new RegistryAccess() {
@Override
public <E> Optional<Registry<E>> registry(ResourceKey<? extends Registry<? extends E>> resourceKey) {
return registryAccess.registry(resourceKey);
}

@Override
public Stream<RegistryEntry<?>> registries() {
return registryAccess.registries();
}
};
CreativeModeTabs.tryRebuildTabContents(features, hasOperatorItemsTabPermissions, jeiRegistryAccess);

for (CreativeModeTab itemGroup : CreativeModeTabs.allTabs()) {
if (itemGroup.getType() != CreativeModeTab.Type.CATEGORY) {
Expand Down

0 comments on commit f5574f0

Please sign in to comment.