diff --git a/patches/minecraft/net/minecraft/world/item/EnchantedBookItem.java.patch b/patches/minecraft/net/minecraft/world/item/EnchantedBookItem.java.patch new file mode 100644 index 0000000000..3b1d33c534 --- /dev/null +++ b/patches/minecraft/net/minecraft/world/item/EnchantedBookItem.java.patch @@ -0,0 +1,20 @@ +--- a/net/minecraft/world/item/EnchantedBookItem.java ++++ b/net/minecraft/world/item/EnchantedBookItem.java +@@ -72,7 +_,7 @@ + public void m_6787_(CreativeModeTab p_41151_, NonNullList p_41152_) { + if (p_41151_ == CreativeModeTab.f_40754_) { + for(Enchantment enchantment : Registry.f_122825_) { +- if (enchantment.f_44672_ != null) { ++ if (enchantment.allowedInCreativeTab(this, p_41151_)) { + for(int i = enchantment.m_44702_(); i <= enchantment.m_6586_(); ++i) { + p_41152_.add(m_41161_(new EnchantmentInstance(enchantment, i))); + } +@@ -80,7 +_,7 @@ + } + } else if (p_41151_.m_40795_().length != 0) { + for(Enchantment enchantment1 : Registry.f_122825_) { +- if (p_41151_.m_40776_(enchantment1.f_44672_)) { ++ if (enchantment1.allowedInCreativeTab(this, p_41151_)) { + p_41152_.add(m_41161_(new EnchantmentInstance(enchantment1, enchantment1.m_6586_()))); + } + } diff --git a/patches/minecraft/net/minecraft/world/item/PotionItem.java.patch b/patches/minecraft/net/minecraft/world/item/PotionItem.java.patch new file mode 100644 index 0000000000..4793da9538 --- /dev/null +++ b/patches/minecraft/net/minecraft/world/item/PotionItem.java.patch @@ -0,0 +1,18 @@ +--- a/net/minecraft/world/item/PotionItem.java ++++ b/net/minecraft/world/item/PotionItem.java +@@ -127,12 +_,12 @@ + } + + public boolean m_5812_(ItemStack p_42999_) { +- return super.m_5812_(p_42999_) || !PotionUtils.m_43547_(p_42999_).isEmpty(); ++ return super.m_5812_(p_42999_) || PotionUtils.m_43579_(p_42999_).isFoil(p_42999_); + } + + public void m_6787_(CreativeModeTab p_42981_, NonNullList p_42982_) { +- if (this.m_220152_(p_42981_)) { +- for(Potion potion : Registry.f_122828_) { ++ for(Potion potion : Registry.f_122828_) { ++ if (potion.allowedInCreativeTab(this, p_42981_, this.m_220152_(p_42981_))) { + if (potion != Potions.f_43598_) { + p_42982_.add(PotionUtils.m_43549_(new ItemStack(this), potion)); + } diff --git a/patches/minecraft/net/minecraft/world/item/TippedArrowItem.java.patch b/patches/minecraft/net/minecraft/world/item/TippedArrowItem.java.patch new file mode 100644 index 0000000000..7f789fa142 --- /dev/null +++ b/patches/minecraft/net/minecraft/world/item/TippedArrowItem.java.patch @@ -0,0 +1,13 @@ +--- a/net/minecraft/world/item/TippedArrowItem.java ++++ b/net/minecraft/world/item/TippedArrowItem.java +@@ -20,8 +_,8 @@ + } + + public void m_6787_(CreativeModeTab p_43356_, NonNullList p_43357_) { +- if (this.m_220152_(p_43356_)) { +- for(Potion potion : Registry.f_122828_) { ++ for (Potion potion : Registry.f_122828_) { ++ if (potion.allowedInCreativeTab(this, p_43356_, this.m_220152_(p_43356_))) { + if (!potion.m_43488_().isEmpty()) { + p_43357_.add(PotionUtils.m_43549_(new ItemStack(this), potion)); + } diff --git a/patches/minecraft/net/minecraft/world/item/alchemy/Potion.java.patch b/patches/minecraft/net/minecraft/world/item/alchemy/Potion.java.patch new file mode 100644 index 0000000000..6c7f064845 --- /dev/null +++ b/patches/minecraft/net/minecraft/world/item/alchemy/Potion.java.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/world/item/alchemy/Potion.java ++++ b/net/minecraft/world/item/alchemy/Potion.java +@@ -7,7 +_,7 @@ + import net.minecraft.resources.ResourceLocation; + import net.minecraft.world.effect.MobEffectInstance; + +-public class Potion { ++public class Potion implements net.minecraftforge.common.extensions.IForgePotion { + @Nullable + private final String f_43481_; + private final ImmutableList f_43482_; diff --git a/src/main/java/net/minecraftforge/common/extensions/IForgeEnchantment.java b/src/main/java/net/minecraftforge/common/extensions/IForgeEnchantment.java index d1abf0b202..eba456911d 100644 --- a/src/main/java/net/minecraftforge/common/extensions/IForgeEnchantment.java +++ b/src/main/java/net/minecraftforge/common/extensions/IForgeEnchantment.java @@ -6,6 +6,8 @@ package net.minecraftforge.common.extensions; import net.minecraft.world.entity.MobType; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.enchantment.Enchantment; @@ -28,4 +30,26 @@ public interface IForgeEnchantment { return self().getDamageBonus(level, mobType); } + + /** + * Determines what creative tabs this enchantment's variant of an enchanted book or similar item should appear in. + * @param book The item being added to the creative tab + * @param tab The creative tab that items are being added to + * @return whether the given Item's variant for this enchantment should appear in the respective creative tab + */ + default boolean allowedInCreativeTab(Item book, CreativeModeTab tab) + { + if (!self().isAllowedOnBooks()) + { + return false; + } + else if (tab == CreativeModeTab.TAB_SEARCH) + { + return self().category != null; + } + else + { + return tab.hasEnchantmentCategory(self().category); + } + } } diff --git a/src/main/java/net/minecraftforge/common/extensions/IForgePotion.java b/src/main/java/net/minecraftforge/common/extensions/IForgePotion.java new file mode 100644 index 0000000000..cf5e0de2ed --- /dev/null +++ b/src/main/java/net/minecraftforge/common/extensions/IForgePotion.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) Forge Development LLC and contributors + * SPDX-License-Identifier: LGPL-2.1-only + */ + +package net.minecraftforge.common.extensions; + +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.alchemy.Potion; +import net.minecraft.world.item.alchemy.PotionUtils; + +public interface IForgePotion +{ + private Potion self() + { + return (Potion) this; + } + + /** + * Determines what creative tabs this potion's variant of a potion-related item (e.g. bottles, tipped arrows) should appear in. + * @param item The item being added to a creative tab + * @param tab The creative tab that items are being added to + * @param isDefaultTab whether the tab is the default tab for this item (e.g. Brewing for bottles, Combat for tipped arrows) + * @return whether the given Item's variant for this enchantment should appear in the respective creative tab + */ + default boolean allowedInCreativeTab(Item item, CreativeModeTab tab, boolean isDefaultTab) + { + return isDefaultTab; + } + + /** + * Determines whether the potion bottle item should be enchanted. + * Not called for tipped arrows or if the item is already enchanted. + * @param stack The potion bottle + * @return whether the item should appear enchanted. + */ + default boolean isFoil(ItemStack stack) + { + return !PotionUtils.getMobEffects(stack).isEmpty(); + } +}