-
-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix 1.21 issues relating to gameplay-enchantment support (#1089)
- Loading branch information
1 parent
52526da
commit c9c4d98
Showing
16 changed files
with
290 additions
and
125 deletions.
There are no files selected for viewing
23 changes: 14 additions & 9 deletions
23
patches/net/minecraft/advancements/critereon/ItemEnchantmentsPredicate.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
--- a/net/minecraft/advancements/critereon/ItemEnchantmentsPredicate.java | ||
+++ b/net/minecraft/advancements/critereon/ItemEnchantmentsPredicate.java | ||
@@ -48,6 +_,11 @@ | ||
super(p_333967_); | ||
@@ -52,6 +_,16 @@ | ||
public DataComponentType<ItemEnchantments> componentType() { | ||
return DataComponents.ENCHANTMENTS; | ||
} | ||
|
||
+ @Override // Neo: use getAllEnchantments for enchantments | ||
+ | ||
+ // Neo: use IItemExtension#getAllEnchantments for enchantments when testing this predicate. | ||
+ @Override | ||
+ public boolean matches(ItemStack p_333958_) { | ||
+ return matches(p_333958_, p_333958_.getAllEnchantments()); | ||
+ var lookup = net.neoforged.neoforge.common.CommonHooks.resolveLookup(net.minecraft.core.registries.Registries.ENCHANTMENT); | ||
+ if (lookup != null) { | ||
+ return matches(p_333958_, p_333958_.getAllEnchantments(lookup)); | ||
+ } | ||
+ return super.matches(p_333958_); | ||
+ } | ||
+ | ||
@Override | ||
public DataComponentType<ItemEnchantments> componentType() { | ||
return DataComponents.ENCHANTMENTS; | ||
} | ||
|
||
public static class StoredEnchantments extends ItemEnchantmentsPredicate { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
--- a/net/minecraft/world/item/ArrowItem.java | ||
+++ b/net/minecraft/world/item/ArrowItem.java | ||
@@ -24,4 +_,10 @@ | ||
@@ -24,4 +_,18 @@ | ||
arrow.pickup = AbstractArrow.Pickup.ALLOWED; | ||
return arrow; | ||
} | ||
+ | ||
+ public boolean isInfinite(ItemStack stack, ItemStack bow, net.minecraft.world.entity.LivingEntity livingEntity) { | ||
+ // TODO 1.21 - probably needs to decide based on tags/other datapack logic | ||
+ int enchant = net.minecraft.world.item.enchantment.EnchantmentHelper.getItemEnchantmentLevel(livingEntity.registryAccess().registryOrThrow(net.minecraft.core.registries.Registries.ENCHANTMENT).getHolderOrThrow(net.minecraft.world.item.enchantment.Enchantments.INFINITY), bow); | ||
+ return enchant > 0 && this.getClass() == net.minecraft.world.item.ArrowItem.class; | ||
+ /** | ||
+ * Called to determine if this arrow will be infinite when fired. If an arrow is infinite, then the arrow will never be consumed (regardless of enchantments). | ||
+ * <p> | ||
+ * Only called on the logical server. | ||
+ * | ||
+ * @param ammo The ammo stack (containing this item) | ||
+ * @param bow The bow stack | ||
+ * @param livingEntity The entity who is firing the bow | ||
+ * @return True if the arrow is infinite | ||
+ */ | ||
+ public boolean isInfinite(ItemStack ammo, ItemStack bow, net.minecraft.world.entity.LivingEntity livingEntity) { | ||
+ return false; | ||
+ } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 15 additions & 15 deletions
30
patches/net/minecraft/world/item/enchantment/Enchantment.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
--- a/net/minecraft/world/item/enchantment/Enchantment.java | ||
+++ b/net/minecraft/world/item/enchantment/Enchantment.java | ||
@@ -504,6 +_,26 @@ | ||
return new Enchantment.Builder(p_345873_); | ||
@@ -132,6 +_,10 @@ | ||
return this.definition.slots().stream().anyMatch(p_345027_ -> p_345027_.test(p_345146_)); | ||
} | ||
|
||
+ // TODO 1.21: Make IEnchantmentExtension additions data-driven along with these methods: | ||
+ /** | ||
+ * @deprecated Neo: Use {@link ItemStack#isPrimaryItemFor(Holder)} | ||
+ */ | ||
+ @Deprecated | ||
public boolean isPrimaryItem(ItemStack p_336088_) { | ||
return this.isSupportedItem(p_336088_) && (this.definition.primaryItems.isEmpty() || p_336088_.is(this.definition.primaryItems.get())); | ||
} | ||
@@ -503,6 +_,15 @@ | ||
public static Enchantment.Builder enchantment(Enchantment.EnchantmentDefinition p_345873_) { | ||
return new Enchantment.Builder(p_345873_); | ||
} | ||
+ | ||
+// /** | ||
+// * This applies specifically to applying at the enchanting table. The other method {@link #canEnchant(ItemStack)} | ||
+// * applies for <i>all possible</i> enchantments. | ||
+// * @param stack | ||
+// * @return | ||
+// */ | ||
+// public boolean canApplyAtEnchantingTable(ItemStack stack) { | ||
+// return stack.canApplyAtEnchantingTable(this); | ||
+// } | ||
+// | ||
+// TODO: Reimplement. Not sure if we want to patch EnchantmentDefinition or hack this in as an EnchantmentEffectComponent. | ||
+// /** | ||
+// * Is this enchantment allowed to be enchanted on books via Enchantment Table | ||
+// * @return false to disable the vanilla feature | ||
+// */ | ||
+// public boolean isAllowedOnBooks() { | ||
+// return true; | ||
+// } | ||
+ | ||
public static class Builder { | ||
private final Enchantment.EnchantmentDefinition definition; | ||
private HolderSet<Enchantment> exclusiveSet = HolderSet.direct(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.