From 16d7de6c23752011253ca7a636519c07d3008105 Mon Sep 17 00:00:00 2001 From: Sara Freimer Date: Mon, 1 Jul 2024 11:00:50 -0500 Subject: [PATCH] Add an Item Ability to determine if an item can remove wolf armor (#1062) (#1203) --- .../world/entity/animal/Wolf.java.patch | 9 ++++ .../husbandry/remove_wolf_armor.json | 42 +++++++++++++++++++ .../neoforge/common/ItemAbilities.java | 7 +++- .../internal/NeoForgeAdvancementProvider.java | 1 + 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/generated/resources/data/minecraft/advancement/husbandry/remove_wolf_armor.json diff --git a/patches/net/minecraft/world/entity/animal/Wolf.java.patch b/patches/net/minecraft/world/entity/animal/Wolf.java.patch index 2223bf9754..5a316c46eb 100644 --- a/patches/net/minecraft/world/entity/animal/Wolf.java.patch +++ b/patches/net/minecraft/world/entity/animal/Wolf.java.patch @@ -14,6 +14,15 @@ return InteractionResult.sidedSuccess(this.level().isClientSide()); } else { if (item instanceof DyeItem dyeitem && this.isOwnedBy(p_30412_)) { +@@ -440,7 +_,7 @@ + this.setBodyArmorItem(itemstack.copyWithCount(1)); + itemstack.consume(1, p_30412_); + return InteractionResult.SUCCESS; +- } else if (itemstack.is(Items.SHEARS) ++ } else if (itemstack.canPerformAction(net.neoforged.neoforge.common.ItemAbilities.SHEARS_REMOVE_ARMOR) + && this.isOwnedBy(p_30412_) + && this.hasArmor() + && (!EnchantmentHelper.has(this.getBodyArmorItem(), EnchantmentEffectComponents.PREVENT_ARMOR_CHANGE) || p_30412_.isCreative())) { @@ -488,7 +_,7 @@ } diff --git a/src/generated/resources/data/minecraft/advancement/husbandry/remove_wolf_armor.json b/src/generated/resources/data/minecraft/advancement/husbandry/remove_wolf_armor.json new file mode 100644 index 0000000000..dd3b7d3c34 --- /dev/null +++ b/src/generated/resources/data/minecraft/advancement/husbandry/remove_wolf_armor.json @@ -0,0 +1,42 @@ +{ + "parent": "minecraft:husbandry/tame_an_animal", + "criteria": { + "remove_wolf_armor": { + "conditions": { + "entity": [ + { + "condition": "minecraft:entity_properties", + "entity": "this", + "predicate": { + "type": "minecraft:wolf" + } + } + ], + "item": { + "predicates": { + "neoforge:item_ability": "shears_remove_armor" + } + } + }, + "trigger": "minecraft:player_interacted_with_entity" + } + }, + "display": { + "description": { + "translate": "advancements.husbandry.remove_wolf_armor.description" + }, + "icon": { + "count": 1, + "id": "minecraft:shears" + }, + "title": { + "translate": "advancements.husbandry.remove_wolf_armor.title" + } + }, + "requirements": [ + [ + "remove_wolf_armor" + ] + ], + "sends_telemetry_event": true +} \ No newline at end of file diff --git a/src/main/java/net/neoforged/neoforge/common/ItemAbilities.java b/src/main/java/net/neoforged/neoforge/common/ItemAbilities.java index f1069d9f0f..d74df363e8 100644 --- a/src/main/java/net/neoforged/neoforge/common/ItemAbilities.java +++ b/src/main/java/net/neoforged/neoforge/common/ItemAbilities.java @@ -76,6 +76,11 @@ public class ItemAbilities { */ public static final ItemAbility SHEARS_HARVEST = ItemAbility.get("shears_harvest"); + /** + * This action is exposed by shears and corresponds to a harvest action that is triggered with a right click on armored wolves. + */ + public static final ItemAbility SHEARS_REMOVE_ARMOR = ItemAbility.get("shears_remove_armor"); + /** * This action is exposed by shears and corresponds to a carve action that is triggered with a right click on a block that supports such behaviour. * Example: Right click with shears o a pumpkin to carve it @@ -121,7 +126,7 @@ public class ItemAbilities { public static final Set DEFAULT_SHOVEL_ACTIONS = of(SHOVEL_DIG, SHOVEL_FLATTEN); public static final Set DEFAULT_PICKAXE_ACTIONS = of(PICKAXE_DIG); public static final Set DEFAULT_SWORD_ACTIONS = of(SWORD_DIG, SWORD_SWEEP); - public static final Set DEFAULT_SHEARS_ACTIONS = of(SHEARS_DIG, SHEARS_HARVEST, SHEARS_CARVE, SHEARS_DISARM); + public static final Set DEFAULT_SHEARS_ACTIONS = of(SHEARS_DIG, SHEARS_HARVEST, SHEARS_REMOVE_ARMOR, SHEARS_CARVE, SHEARS_DISARM); public static final Set DEFAULT_SHIELD_ACTIONS = of(SHIELD_BLOCK); public static final Set DEFAULT_FISHING_ROD_ACTIONS = of(FISHING_ROD_CAST); public static final Set DEFAULT_TRIDENT_ACTIONS = of(TRIDENT_THROW); diff --git a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeAdvancementProvider.java b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeAdvancementProvider.java index 675fb1281a..dc41bff69e 100644 --- a/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeAdvancementProvider.java +++ b/src/main/java/net/neoforged/neoforge/common/data/internal/NeoForgeAdvancementProvider.java @@ -61,6 +61,7 @@ public NeoForgeAdvancementProvider(PackOutput output, CompletableFuture getVanillaAdvancementProviders(PackOutput output, CompletableFuture registries) { List, HolderLookup.Provider, Criterion>> criteriaReplacers = new ArrayList<>(); criteriaReplacers.add(replaceMatchToolCriteria(ItemAbilities.AXE_WAX_OFF, getPrivateValue(VanillaHusbandryAdvancements.class, null, "WAX_SCRAPING_TOOLS"))); + criteriaReplacers.add(replaceInteractCriteria(ItemPredicate.Builder.item().withSubPredicate(ItemAbilityPredicate.TYPE, new ItemAbilityPredicate(ItemAbilities.SHEARS_REMOVE_ARMOR)).build(), Items.SHEARS)); criteriaReplacers.add(replaceInteractCriteria(ItemPredicate.Builder.item().withSubPredicate(PiglinCurrencyItemPredicate.TYPE, PiglinCurrencyItemPredicate.INSTANCE).build(), PiglinAi.BARTERING_ITEM)); criteriaReplacers.add(replaceWearingPredicate(EntityPredicate.Builder.entity().subPredicate(PiglinNeutralArmorEntityPredicate.INSTANCE).build(), predicate -> { if (predicate.head().filter(item -> predicateMatches(item, Items.GOLDEN_HELMET)).isPresent()) {