Moved ForgeHooksClient.onCreativeModeTabBuildContents to ForgeHooks to fix #9662

This commit is contained in:
RealMangoRage authored and GitHub committed 2023-07-19 11:18:45 -07:00
1 parent 2745531f08
commit 881725c7d5
3 files changed
+32 -20

No files matched your search

@@ -146,6 +146,7 @@ import net.minecraftforge.client.gui.overlay.GuiOverlayManager;
import net.minecraftforge.client.model.data.ModelData;
import net.minecraftforge.client.textures.ForgeTextureMetadata;
import net.minecraftforge.client.textures.TextureAtlasSpriteLoaderManager;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.ForgeI18n;
import net.minecraftforge.common.ForgeMod;
import net.minecraftforge.common.MinecraftForge;
@@ -1201,27 +1202,13 @@ public class ForgeHooksClient
return new ResourceLocation(loc.getNamespace(), normalised);
}
// Use ForgeHooks.onCreativeModeTabBuildContents()
// since calling this will crash if called on server
@Deprecated(forRemoval = true, since = "1.20.1")
public static void onCreativeModeTabBuildContents(CreativeModeTab tab, ResourceKey<CreativeModeTab> tabKey, CreativeModeTab.DisplayItemsGenerator originalGenerator, CreativeModeTab.ItemDisplayParameters params, CreativeModeTab.Output output)
{
final var entries = new MutableHashedLinkedMap<ItemStack, CreativeModeTab.TabVisibility>(ItemStackLinkedSet.TYPE_AND_TAG,
(key, left, right) -> {
//throw new IllegalStateException("Accidentally adding the same item stack twice " + key.getDisplayName().getString() + " to a Creative Mode Tab: " + tab.getDisplayName().getString());
// Vanilla adds enchanting books twice in both visibilities.
// This is just code cleanliness for them. For us lets just increase the visibility and merge the entries.
return CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS;
}
);
originalGenerator.accept(params, (stack, vis) -> {
if (stack.getCount() != 1)
throw new IllegalArgumentException("The stack count must be 1");
entries.put(stack, vis);
});
ModLoader.get().postEvent(new BuildCreativeModeTabContentsEvent(tab, tabKey, params, entries));
for (var entry : entries)
output.accept(entry.getKey(), entry.getValue());
// Bounce to ForgeHooks.onCreativeModeBuildContents(...)
ForgeHooks.onCreativeModeTabBuildContents(tab, tabKey, originalGenerator, params, output);
}
// Make sure the below method is only ever called once (by forge).
@@ -134,7 +134,9 @@ import net.minecraftforge.common.util.BlockSnapshot;
import net.minecraftforge.common.util.BrainBuilder;
import net.minecraftforge.common.util.Lazy;
import net.minecraftforge.common.util.MavenVersionStringHelper;
import net.minecraftforge.common.util.MutableHashedLinkedMap;
import net.minecraftforge.event.AnvilUpdateEvent;
import net.minecraftforge.event.BuildCreativeModeTabContentsEvent;
import net.minecraftforge.event.DifficultyChangeEvent;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.GrindstoneEvent;
@@ -1604,4 +1606,27 @@ public class ForgeHooks
entity.stopRiding();
}
}
public static void onCreativeModeTabBuildContents(CreativeModeTab tab, ResourceKey<CreativeModeTab> tabKey, CreativeModeTab.DisplayItemsGenerator originalGenerator, CreativeModeTab.ItemDisplayParameters params, CreativeModeTab.Output output)
{
final var entries = new MutableHashedLinkedMap<ItemStack, CreativeModeTab.TabVisibility>(ItemStackLinkedSet.TYPE_AND_TAG,
(key, left, right) -> {
//throw new IllegalStateException("Accidentally adding the same item stack twice " + key.getDisplayName().getString() + " to a Creative Mode Tab: " + tab.getDisplayName().getString());
// Vanilla adds enchanting books twice in both visibilities.
// This is just code cleanliness for them. For us lets just increase the visibility and merge the entries.
return CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS;
}
);
originalGenerator.accept(params, (stack, vis) -> {
if (stack.getCount() != 1)
throw new IllegalArgumentException("The stack count must be 1");
entries.put(stack, vis);
});
ModLoader.get().postEvent(new BuildCreativeModeTabContentsEvent(tab, tabKey, params, entries));
for (var entry : entries)
output.accept(entry.getKey(), entry.getValue());
}
}