Skip to content

Commit

Permalink
Pass the Holder<Enchantment> to Item.canApplyAtEnchantingTable. Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
LexManos committed Nov 21, 2024
1 parent 7053754 commit 5efb8d3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
List<EnchantmentInstance> list = Lists.newArrayList();
boolean flag = p_44819_.is(Items.BOOK);
- p_342857_.filter(p_341799_ -> p_341799_.value().isPrimaryItem(p_44819_) || flag).forEach(p_341708_ -> {
+ p_342857_.filter(p_341799_ -> p_44819_.canApplyAtEnchantingTable(p_341799_.value()) || flag).forEach(p_341708_ -> {
+ p_342857_.filter(p_341799_ -> p_44819_.canApplyAtEnchantingTable(p_341799_) || flag).forEach(p_341708_ -> {
Enchantment enchantment = p_341708_.value();

for (int i = enchantment.getMaxLevel(); i >= enchantment.getMinLevel(); i--) {
21 changes: 21 additions & 0 deletions src/main/java/net/minecraftforge/common/extensions/IForgeItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.InteractionResult;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.network.chat.Component;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.level.Level;
Expand Down Expand Up @@ -333,11 +334,31 @@ default boolean canPerformAction(ItemStack stack, ToolAction toolAction) {
* @param stack the item stack to be enchanted
* @param enchantment the enchantment to be applied
* @return true if the enchantment can be applied to this item
*
* @deprecated Use {@link IForgeItemStack#canApplyAtEnchantingTable(Holder)}
*/
@Deprecated(forRemoval = true, since = "1.21.3")
default boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
return enchantment.isPrimaryItem(stack);
}

/**
* Checks whether an item can be enchanted with a certain enchantment. This
* applies specifically to enchanting an item in the enchanting table and is
* called when retrieving the list of possible enchantments for an item.
* Enchantments may additionally (or exclusively) be doing their own checks in
* {@link Enchantment#canApplyAtEnchantingTable(ItemStack)};
* check the individual implementation for reference. By default this will check
* if the enchantment type is valid for this item type.
*
* @param stack the item stack to be enchanted
* @param enchantment the enchantment to be applied
* @return true if the enchantment can be applied to this item
*/
default boolean canApplyAtEnchantingTable(ItemStack stack, Holder<Enchantment> enchantment) {
return canApplyAtEnchantingTable(stack, enchantment.value());
}

/**
* Determine if the player switching between these two item stacks
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import net.minecraft.stats.Stats;
import net.minecraft.world.InteractionResult;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.ToolAction;
Expand Down Expand Up @@ -123,11 +124,31 @@ default boolean shouldCauseBlockBreakReset(ItemStack newStack) {
*
* @param enchantment the enchantment to be applied
* @return true if the enchantment can be applied to this item
*
* @deprecated Use {@link #canApplyAtEnchantingTable(Holder)}
*/
@Deprecated(forRemoval = true, since = "1.21.3")
default boolean canApplyAtEnchantingTable(Enchantment enchantment) {
return self().getItem().canApplyAtEnchantingTable(self(), enchantment);
}

/**
* Checks whether an item can be enchanted with a certain enchantment. This
* applies specifically to enchanting an item in the enchanting table and is
* called when retrieving the list of possible enchantments for an item.
* Enchantments may additionally (or exclusively) be doing their own checks in
* {@link Enchantment#canApplyAtEnchantingTable(ItemStack)};
* check the individual implementation for reference. By default this will check
* if the enchantment type is valid for this item type.
*
* @param enchantment the enchantment to be applied
* @return true if the enchantment can be applied to this item
*/
default boolean canApplyAtEnchantingTable(Holder<Enchantment> enchantment) {
return self().getItem().canApplyAtEnchantingTable(self(), enchantment);
}


/**
* Override this to set a non-default armor slot for an ItemStack, but <em>do
* not use this to get the armor slot of said stack; for that, use
Expand Down

0 comments on commit 5efb8d3

Please sign in to comment.