diff --git a/patches/minecraft/net/minecraft/world/item/ShearsItem.java.patch b/patches/minecraft/net/minecraft/world/item/ShearsItem.java.patch index f14e328ed3..bd6897c0ea 100644 --- a/patches/minecraft/net/minecraft/world/item/ShearsItem.java.patch +++ b/patches/minecraft/net/minecraft/world/item/ShearsItem.java.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/item/ShearsItem.java +++ b/net/minecraft/world/item/ShearsItem.java -@@ -38,4 +_,25 @@ +@@ -38,4 +_,30 @@ return 15.0F; } } @@ -24,5 +24,10 @@ + return net.minecraft.world.InteractionResult.SUCCESS; + } + return net.minecraft.world.InteractionResult.PASS; ++ } ++ ++ @Override ++ public boolean canPerformAction(ItemStack stack, net.minecraftforge.common.ToolAction toolAction) { ++ return net.minecraftforge.common.ToolActions.DEFAULT_SHEARS_ACTIONS.contains(toolAction); + } } diff --git a/patches/minecraft/net/minecraft/world/item/enchantment/DiggingEnchantment.java.patch b/patches/minecraft/net/minecraft/world/item/enchantment/DiggingEnchantment.java.patch new file mode 100644 index 0000000000..489259e45d --- /dev/null +++ b/patches/minecraft/net/minecraft/world/item/enchantment/DiggingEnchantment.java.patch @@ -0,0 +1,10 @@ +--- a/net/minecraft/world/item/enchantment/DiggingEnchantment.java ++++ b/net/minecraft/world/item/enchantment/DiggingEnchantment.java +@@ -22,6 +_,6 @@ + } + + public boolean m_6081_(ItemStack p_44668_) { +- return p_44668_.m_150930_(Items.f_42574_) ? true : super.m_6081_(p_44668_); ++ return p_44668_.m_41720_() instanceof net.minecraft.world.item.ShearsItem ? true : super.m_6081_(p_44668_); + } + } diff --git a/patches/minecraft/net/minecraft/world/level/block/BeehiveBlock.java.patch b/patches/minecraft/net/minecraft/world/level/block/BeehiveBlock.java.patch index 0e949b86be..7ac3261ded 100644 --- a/patches/minecraft/net/minecraft/world/level/block/BeehiveBlock.java.patch +++ b/patches/minecraft/net/minecraft/world/level/block/BeehiveBlock.java.patch @@ -18,3 +18,12 @@ int i = list1.size(); for(Bee bee : list) { +@@ -112,7 +_,7 @@ + boolean flag = false; + if (i >= 5) { + Item item = itemstack.m_41720_(); +- if (itemstack.m_150930_(Items.f_42574_)) { ++ if (itemstack.canPerformAction(net.minecraftforge.common.ToolActions.SHEARS_HARVEST)) { + p_49625_.m_6263_(p_49627_, p_49627_.m_20185_(), p_49627_.m_20186_(), p_49627_.m_20189_(), SoundEvents.f_11697_, SoundSource.NEUTRAL, 1.0F, 1.0F); + m_49600_(p_49625_, p_49626_); + itemstack.m_41622_(1, p_49627_, (p_49571_) -> { diff --git a/patches/minecraft/net/minecraft/world/level/block/PumpkinBlock.java.patch b/patches/minecraft/net/minecraft/world/level/block/PumpkinBlock.java.patch new file mode 100644 index 0000000000..63418c6e6b --- /dev/null +++ b/patches/minecraft/net/minecraft/world/level/block/PumpkinBlock.java.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/world/level/block/PumpkinBlock.java ++++ b/net/minecraft/world/level/block/PumpkinBlock.java +@@ -24,7 +_,7 @@ + + public InteractionResult m_6227_(BlockState p_55289_, Level p_55290_, BlockPos p_55291_, Player p_55292_, InteractionHand p_55293_, BlockHitResult p_55294_) { + ItemStack itemstack = p_55292_.m_21120_(p_55293_); +- if (itemstack.m_150930_(Items.f_42574_)) { ++ if (itemstack.canPerformAction(net.minecraftforge.common.ToolActions.SHEARS_CARVE)) { + if (!p_55290_.f_46443_) { + Direction direction = p_55294_.m_82434_(); + Direction direction1 = direction.m_122434_() == Direction.Axis.Y ? p_55292_.m_6350_().m_122424_() : direction; diff --git a/patches/minecraft/net/minecraft/world/level/block/TripWireBlock.java.patch b/patches/minecraft/net/minecraft/world/level/block/TripWireBlock.java.patch new file mode 100644 index 0000000000..f7abce6664 --- /dev/null +++ b/patches/minecraft/net/minecraft/world/level/block/TripWireBlock.java.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/world/level/block/TripWireBlock.java ++++ b/net/minecraft/world/level/block/TripWireBlock.java +@@ -69,7 +_,7 @@ + } + + public void m_5707_(Level p_57615_, BlockPos p_57616_, BlockState p_57617_, Player p_57618_) { +- if (!p_57615_.f_46443_ && !p_57618_.m_21205_().m_41619_() && p_57618_.m_21205_().m_150930_(Items.f_42574_)) { ++ if (!p_57615_.f_46443_ && !p_57618_.m_21205_().m_41619_() && p_57618_.m_21205_().canPerformAction(net.minecraftforge.common.ToolActions.SHEARS_DISARM)) { + p_57615_.m_7731_(p_57616_, p_57617_.m_61124_(f_57592_, Boolean.valueOf(true)), 4); + p_57615_.m_142346_(p_57618_, GameEvent.f_157781_, p_57616_); + } diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/acacia_leaves.json b/src/generated/resources/data/minecraft/loot_tables/blocks/acacia_leaves.json index de2b04da59..1f21719ca8 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/acacia_leaves.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/acacia_leaves.json @@ -15,10 +15,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", @@ -104,10 +102,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/azalea_leaves.json b/src/generated/resources/data/minecraft/loot_tables/blocks/azalea_leaves.json index 93f279b86d..ff85bcb0c1 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/azalea_leaves.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/azalea_leaves.json @@ -15,10 +15,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", @@ -104,10 +102,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/birch_leaves.json b/src/generated/resources/data/minecraft/loot_tables/blocks/birch_leaves.json index 0493f6f418..7f5a40ddfa 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/birch_leaves.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/birch_leaves.json @@ -15,10 +15,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", @@ -104,10 +102,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/cobweb.json b/src/generated/resources/data/minecraft/loot_tables/blocks/cobweb.json index dd9d38acef..307bc17d00 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/cobweb.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/cobweb.json @@ -15,10 +15,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/dark_oak_leaves.json b/src/generated/resources/data/minecraft/loot_tables/blocks/dark_oak_leaves.json index 23402d820a..eb2d4e9619 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/dark_oak_leaves.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/dark_oak_leaves.json @@ -15,10 +15,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", @@ -104,10 +102,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", @@ -160,10 +156,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/dead_bush.json b/src/generated/resources/data/minecraft/loot_tables/blocks/dead_bush.json index 1de7671d13..feffd6709a 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/dead_bush.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/dead_bush.json @@ -12,10 +12,8 @@ "type": "minecraft:item", "conditions": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" } ], "name": "minecraft:dead_bush" diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/fern.json b/src/generated/resources/data/minecraft/loot_tables/blocks/fern.json index 1526f46377..38c7bec57f 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/fern.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/fern.json @@ -12,10 +12,8 @@ "type": "minecraft:item", "conditions": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" } ], "name": "minecraft:fern" diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/flowering_azalea_leaves.json b/src/generated/resources/data/minecraft/loot_tables/blocks/flowering_azalea_leaves.json index 11f34be9e7..ebe23a780d 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/flowering_azalea_leaves.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/flowering_azalea_leaves.json @@ -15,10 +15,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", @@ -104,10 +102,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/grass.json b/src/generated/resources/data/minecraft/loot_tables/blocks/grass.json index ebdc7d44eb..ad3f12719e 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/grass.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/grass.json @@ -12,10 +12,8 @@ "type": "minecraft:item", "conditions": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" } ], "name": "minecraft:grass" diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/hanging_roots.json b/src/generated/resources/data/minecraft/loot_tables/blocks/hanging_roots.json index b12616a055..0f0983b346 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/hanging_roots.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/hanging_roots.json @@ -12,10 +12,8 @@ ], "conditions": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" } ], "functions": [] diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/jungle_leaves.json b/src/generated/resources/data/minecraft/loot_tables/blocks/jungle_leaves.json index c9328141f2..8cda8be7d6 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/jungle_leaves.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/jungle_leaves.json @@ -15,10 +15,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", @@ -105,10 +103,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/large_fern.json b/src/generated/resources/data/minecraft/loot_tables/blocks/large_fern.json index 1f5fa417f7..c9250aafce 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/large_fern.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/large_fern.json @@ -12,10 +12,8 @@ "type": "minecraft:item", "conditions": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" } ], "functions": [ @@ -79,10 +77,8 @@ "type": "minecraft:item", "conditions": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" } ], "functions": [ diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/nether_sprouts.json b/src/generated/resources/data/minecraft/loot_tables/blocks/nether_sprouts.json index 661dccdd71..fa2a63122e 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/nether_sprouts.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/nether_sprouts.json @@ -12,10 +12,8 @@ ], "conditions": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" } ], "functions": [] diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/oak_leaves.json b/src/generated/resources/data/minecraft/loot_tables/blocks/oak_leaves.json index f9741d69ea..ccb89a161d 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/oak_leaves.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/oak_leaves.json @@ -15,10 +15,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", @@ -104,10 +102,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", @@ -160,10 +156,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/seagrass.json b/src/generated/resources/data/minecraft/loot_tables/blocks/seagrass.json index 6d6a050c1f..f996cf799c 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/seagrass.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/seagrass.json @@ -12,10 +12,8 @@ ], "conditions": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" } ], "functions": [] diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/small_dripleaf.json b/src/generated/resources/data/minecraft/loot_tables/blocks/small_dripleaf.json index e83528f069..4a9484e262 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/small_dripleaf.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/small_dripleaf.json @@ -12,10 +12,8 @@ ], "conditions": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" } ], "functions": [] diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/spruce_leaves.json b/src/generated/resources/data/minecraft/loot_tables/blocks/spruce_leaves.json index 2b6a30f244..a94bb541a6 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/spruce_leaves.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/spruce_leaves.json @@ -15,10 +15,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", @@ -104,10 +102,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/tall_grass.json b/src/generated/resources/data/minecraft/loot_tables/blocks/tall_grass.json index da92fe7642..48c510fb7a 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/tall_grass.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/tall_grass.json @@ -12,10 +12,8 @@ "type": "minecraft:item", "conditions": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" } ], "functions": [ @@ -79,10 +77,8 @@ "type": "minecraft:item", "conditions": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" } ], "functions": [ diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/tall_seagrass.json b/src/generated/resources/data/minecraft/loot_tables/blocks/tall_seagrass.json index 8be352f97f..d856068a48 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/tall_seagrass.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/tall_seagrass.json @@ -19,10 +19,8 @@ ], "conditions": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" } ], "functions": [] diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/twisting_vines.json b/src/generated/resources/data/minecraft/loot_tables/blocks/twisting_vines.json index efc2afa398..803b81969c 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/twisting_vines.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/twisting_vines.json @@ -15,10 +15,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/vine.json b/src/generated/resources/data/minecraft/loot_tables/blocks/vine.json index cd7b91ecbe..690089222e 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/vine.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/vine.json @@ -12,10 +12,8 @@ ], "conditions": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" } ], "functions": [] diff --git a/src/generated/resources/data/minecraft/loot_tables/blocks/weeping_vines.json b/src/generated/resources/data/minecraft/loot_tables/blocks/weeping_vines.json index be3bcbc428..45b91fb90a 100644 --- a/src/generated/resources/data/minecraft/loot_tables/blocks/weeping_vines.json +++ b/src/generated/resources/data/minecraft/loot_tables/blocks/weeping_vines.json @@ -15,10 +15,8 @@ "condition": "minecraft:alternative", "terms": [ { - "condition": "minecraft:match_tool", - "predicate": { - "tag": "forge:shears" - } + "condition": "forge:can_tool_perform_action", + "action": "shears_dig" }, { "condition": "minecraft:match_tool", diff --git a/src/main/java/net/minecraftforge/common/ForgeMod.java b/src/main/java/net/minecraftforge/common/ForgeMod.java index 80ad5ced44..ee7b396c28 100644 --- a/src/main/java/net/minecraftforge/common/ForgeMod.java +++ b/src/main/java/net/minecraftforge/common/ForgeMod.java @@ -36,6 +36,7 @@ import net.minecraftforge.client.ForgeHooksClient; import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent; import net.minecraftforge.common.data.ExistingFileHelper; import net.minecraftforge.common.data.ForgeFluidTagsProvider; +import net.minecraftforge.common.loot.CanToolPerformAction; import net.minecraftforge.common.loot.GlobalLootModifierSerializer; import net.minecraftforge.common.loot.LootTableIdCondition; import net.minecraftforge.eventbus.api.IEventBus; @@ -314,5 +315,6 @@ public class ForgeMod implements WorldPersistenceHooks.WorldPersistenceHook { // Ignore the event itself: this is done only not to statically initialize our custom LootConditionType Registry.register(Registry.LOOT_CONDITION_TYPE, new ResourceLocation("forge:loot_table_id"), LootTableIdCondition.LOOT_TABLE_ID); + Registry.register(Registry.LOOT_CONDITION_TYPE, new ResourceLocation("forge:can_tool_perform_action"), CanToolPerformAction.LOOT_CONDITION_TYPE); } } diff --git a/src/main/java/net/minecraftforge/common/ToolActions.java b/src/main/java/net/minecraftforge/common/ToolActions.java index 30c5d2ed83..31d58fafd4 100644 --- a/src/main/java/net/minecraftforge/common/ToolActions.java +++ b/src/main/java/net/minecraftforge/common/ToolActions.java @@ -54,6 +54,11 @@ public class ToolActions */ public static final ToolAction SWORD_DIG = ToolAction.get("sword_dig"); + /** + * Exposed by shears to allow querying tool behaviours + */ + public static final ToolAction SHEARS_DIG = ToolAction.get("shears_dig"); + /** * Passed onto {@link IForgeBlock#getToolModifiedState} when an axe wants to strip a log */ @@ -80,7 +85,25 @@ public class ToolActions * @see {@link IForgeItem#getSweepHitBox} */ public static final ToolAction SWORD_SWEEP = ToolAction.get("sword_sweep"); - + + /** + * This action is exposed by shears and corresponds to a harvest action that is triggered with a right click on a block that supports such behaviour. + * Example: Right click with shears on a beehive with honey level 5 to harvest it + */ + public static final ToolAction SHEARS_HARVEST = ToolAction.get("shears_harvest"); + + /** + * 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 + */ + public static final ToolAction SHEARS_CARVE = ToolAction.get("shears_carve"); + + /** + * This action is exposed by shears and corresponds to a disarm action that is triggered by breaking a block that supports such behaviour. + * Example: Breaking a trip wire with shears to disarm it. + */ + public static final ToolAction SHEARS_DISARM = ToolAction.get("shears_disarm"); + ///** // * Passed onto {@link IForgeBlock#getToolModifiedState} when a hoe wants to turn dirt into soil // */ @@ -88,9 +111,14 @@ public class ToolActions // Default actions supported by each tool type - public static final Set DEFAULT_AXE_ACTIONS = Stream.of(AXE_DIG, AXE_STRIP, AXE_SCRAPE, AXE_WAX_OFF).collect(Collectors.toCollection(Sets::newIdentityHashSet)); - public static final Set DEFAULT_HOE_ACTIONS = Stream.of(HOE_DIG /* TODO: , HOE_TILL */).collect(Collectors.toCollection(Sets::newIdentityHashSet)); - public static final Set DEFAULT_SHOVEL_ACTIONS = Stream.of(SHOVEL_DIG, SHOVEL_FLATTEN).collect(Collectors.toCollection(Sets::newIdentityHashSet)); - public static final Set DEFAULT_PICKAXE_ACTIONS = Stream.of(PICKAXE_DIG).collect(Collectors.toCollection(Sets::newIdentityHashSet)); - public static final Set DEFAULT_SWORD_ACTIONS = Stream.of(SWORD_DIG, SWORD_SWEEP).collect(Collectors.toCollection(Sets::newIdentityHashSet)); + public static final Set DEFAULT_AXE_ACTIONS = of(AXE_DIG, AXE_STRIP, AXE_SCRAPE, AXE_WAX_OFF); + public static final Set DEFAULT_HOE_ACTIONS = of(HOE_DIG /* TODO: , HOE_TILL */); + 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); + + private static Set of(ToolAction... actions) { + return Stream.of(actions).collect(Collectors.toCollection(Sets::newIdentityHashSet)); + } } diff --git a/src/main/java/net/minecraftforge/common/data/ForgeLootTableProvider.java b/src/main/java/net/minecraftforge/common/data/ForgeLootTableProvider.java index 5ebd566738..c369f11692 100644 --- a/src/main/java/net/minecraftforge/common/data/ForgeLootTableProvider.java +++ b/src/main/java/net/minecraftforge/common/data/ForgeLootTableProvider.java @@ -25,13 +25,14 @@ import net.minecraft.data.DataGenerator; import net.minecraft.data.loot.LootTableProvider; import net.minecraft.world.item.Item; import net.minecraft.world.item.Items; -import net.minecraft.tags.Tag; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.storage.loot.predicates.AlternativeLootItemCondition; import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; import net.minecraft.world.level.storage.loot.predicates.InvertedLootItemCondition; import net.minecraft.world.level.storage.loot.predicates.MatchTool; -import net.minecraftforge.common.Tags; +import net.minecraftforge.common.ToolAction; +import net.minecraftforge.common.ToolActions; +import net.minecraftforge.common.loot.CanToolPerformAction; import net.minecraftforge.fml.util.ObfuscationReflectionHelper; import java.util.List; @@ -50,7 +51,7 @@ import net.minecraft.world.level.storage.loot.entries.LootPoolEntryContainer; import net.minecraft.world.level.storage.loot.parameters.LootContextParamSet; /** - * Currently used only for replacing shears item to shears tag + * Currently used only for replacing shears item to shears_dig tool action */ public final class ForgeLootTableProvider extends LootTableProvider { @@ -73,13 +74,13 @@ public final class ForgeLootTableProvider extends LootTableProvider { private Consumer> replaceAndFilterChangesOnly(Consumer> consumer) { return (newConsumer) -> consumer.accept((resourceLocation, builder) -> { - if (findAndReplaceInLootTableBuilder(builder, Items.SHEARS, Tags.Items.SHEARS)) { + if (findAndReplaceInLootTableBuilder(builder, Items.SHEARS, ToolActions.SHEARS_DIG)) { newConsumer.accept(resourceLocation, builder); } }); } - private boolean findAndReplaceInLootTableBuilder(LootTable.Builder builder, Item from, Tag.Named to) { + private boolean findAndReplaceInLootTableBuilder(LootTable.Builder builder, Item from, ToolAction toolAction) { List lootPools = ObfuscationReflectionHelper.getPrivateValue(LootTable.Builder.class, builder, "f_7915" + "6_"); boolean found = false; @@ -88,7 +89,7 @@ public final class ForgeLootTableProvider extends LootTableProvider { } for (LootPool lootPool : lootPools) { - if (findAndReplaceInLootPool(lootPool, from, to)) { + if (findAndReplaceInLootPool(lootPool, from, toolAction)) { found = true; } } @@ -96,7 +97,7 @@ public final class ForgeLootTableProvider extends LootTableProvider { return found; } - private boolean findAndReplaceInLootPool(LootPool lootPool, Item from, Tag.Named to) { + private boolean findAndReplaceInLootPool(LootPool lootPool, Item from, ToolAction toolAction) { List lootEntries = ObfuscationReflectionHelper.getPrivateValue(LootPool.class, lootPool, "f_7902" +"3_"); List lootConditions = ObfuscationReflectionHelper.getPrivateValue(LootPool.class, lootPool, "f_7902" + "4_"); boolean found = false; @@ -107,7 +108,7 @@ public final class ForgeLootTableProvider extends LootTableProvider { for (LootPoolEntryContainer lootEntry : lootEntries) { if (lootEntry instanceof CompositeEntryBase) { - if (findAndReplaceInParentedLootEntry((CompositeEntryBase) lootEntry, from, to)) { + if (findAndReplaceInParentedLootEntry((CompositeEntryBase) lootEntry, from, toolAction)) { found = true; } } @@ -120,15 +121,15 @@ public final class ForgeLootTableProvider extends LootTableProvider { for (int i = 0; i < lootConditions.size(); i++) { LootItemCondition lootCondition = lootConditions.get(i); if (lootCondition instanceof MatchTool && checkMatchTool((MatchTool) lootCondition, from)) { - lootConditions.set(i, MatchTool.toolMatches(ItemPredicate.Builder.item().of(to)).build()); + lootConditions.set(i, CanToolPerformAction.canToolPerformAction(toolAction).build()); found = true; } else if (lootCondition instanceof InvertedLootItemCondition) { LootItemCondition invLootCondition = ObfuscationReflectionHelper.getPrivateValue(InvertedLootItemCondition.class, (InvertedLootItemCondition) lootCondition, "f_8168" + "1_"); if (invLootCondition instanceof MatchTool && checkMatchTool((MatchTool) invLootCondition, from)) { - lootConditions.set(i, InvertedLootItemCondition.invert(MatchTool.toolMatches(ItemPredicate.Builder.item().of(to))).build()); + lootConditions.set(i, InvertedLootItemCondition.invert(CanToolPerformAction.canToolPerformAction(toolAction)).build()); found = true; - } else if (invLootCondition instanceof AlternativeLootItemCondition && findAndReplaceInAlternative((AlternativeLootItemCondition) invLootCondition, from, to)) { + } else if (invLootCondition instanceof AlternativeLootItemCondition && findAndReplaceInAlternative((AlternativeLootItemCondition) invLootCondition, from, toolAction)) { found = true; } } @@ -137,7 +138,7 @@ public final class ForgeLootTableProvider extends LootTableProvider { return found; } - private boolean findAndReplaceInParentedLootEntry(CompositeEntryBase entry, Item from, Tag.Named to) { + private boolean findAndReplaceInParentedLootEntry(CompositeEntryBase entry, Item from, ToolAction toolAction) { LootPoolEntryContainer[] lootEntries = ObfuscationReflectionHelper.getPrivateValue(CompositeEntryBase.class, entry, "f_7942" + "8_"); boolean found = false; @@ -146,7 +147,7 @@ public final class ForgeLootTableProvider extends LootTableProvider { } for (LootPoolEntryContainer lootEntry : lootEntries) { - if (findAndReplaceInLootEntry(lootEntry, from, to)) { + if (findAndReplaceInLootEntry(lootEntry, from, toolAction)) { found = true; } } @@ -154,7 +155,7 @@ public final class ForgeLootTableProvider extends LootTableProvider { return found; } - private boolean findAndReplaceInLootEntry(LootPoolEntryContainer entry, Item from, Tag.Named to) { + private boolean findAndReplaceInLootEntry(LootPoolEntryContainer entry, Item from, ToolAction toolAction) { LootItemCondition[] lootConditions = ObfuscationReflectionHelper.getPrivateValue(LootPoolEntryContainer.class, entry, "f_7963" + "6_"); boolean found = false; @@ -163,10 +164,10 @@ public final class ForgeLootTableProvider extends LootTableProvider { } for (int i = 0; i < lootConditions.length; i++) { - if (lootConditions[i] instanceof AlternativeLootItemCondition && findAndReplaceInAlternative((AlternativeLootItemCondition) lootConditions[i], from, to)) { + if (lootConditions[i] instanceof AlternativeLootItemCondition && findAndReplaceInAlternative((AlternativeLootItemCondition) lootConditions[i], from, toolAction)) { found = true; } else if (lootConditions[i] instanceof MatchTool && checkMatchTool((MatchTool) lootConditions[i], from)) { - lootConditions[i] = MatchTool.toolMatches(ItemPredicate.Builder.item().of(to)).build(); + lootConditions[i] = CanToolPerformAction.canToolPerformAction(toolAction).build(); found = true; } } @@ -174,7 +175,7 @@ public final class ForgeLootTableProvider extends LootTableProvider { return found; } - private boolean findAndReplaceInAlternative(AlternativeLootItemCondition alternative, Item from, Tag.Named to) { + private boolean findAndReplaceInAlternative(AlternativeLootItemCondition alternative, Item from, ToolAction toolAction) { LootItemCondition[] lootConditions = ObfuscationReflectionHelper.getPrivateValue(AlternativeLootItemCondition.class, alternative, "f_8146" + "8_"); boolean found = false; @@ -184,7 +185,7 @@ public final class ForgeLootTableProvider extends LootTableProvider { for (int i = 0; i < lootConditions.length; i++) { if (lootConditions[i] instanceof MatchTool && checkMatchTool((MatchTool) lootConditions[i], from)) { - lootConditions[i] = MatchTool.toolMatches(ItemPredicate.Builder.item().of(to)).build(); + lootConditions[i] = CanToolPerformAction.canToolPerformAction(toolAction).build(); found = true; } } diff --git a/src/main/java/net/minecraftforge/common/loot/CanToolPerformAction.java b/src/main/java/net/minecraftforge/common/loot/CanToolPerformAction.java new file mode 100644 index 0000000000..c08c785eb9 --- /dev/null +++ b/src/main/java/net/minecraftforge/common/loot/CanToolPerformAction.java @@ -0,0 +1,61 @@ +package net.minecraftforge.common.loot; + +import com.google.common.collect.ImmutableSet; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonObject; +import com.google.gson.JsonSerializationContext; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.storage.loot.LootContext; +import net.minecraft.world.level.storage.loot.parameters.LootContextParam; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; +import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType; +import net.minecraftforge.common.ToolAction; + +import javax.annotation.Nonnull; +import java.util.Set; + +/** + * This LootItemCondition "forge:can_tool_perform_action" can be used to check if a tool can perform a given ToolAction. + */ +public class CanToolPerformAction implements LootItemCondition { + + public static final LootItemConditionType LOOT_CONDITION_TYPE = new LootItemConditionType(new CanToolPerformAction.Serializer()); + + final ToolAction action; + + public CanToolPerformAction(ToolAction action) { + this.action = action; + } + + @Nonnull + public LootItemConditionType getType() { + return LOOT_CONDITION_TYPE; + } + + @Nonnull + public Set> getReferencedContextParams() { + return ImmutableSet.of(LootContextParams.TOOL); + } + + public boolean test(LootContext lootContext) { + ItemStack itemstack = lootContext.getParamOrNull(LootContextParams.TOOL); + return itemstack != null && itemstack.canPerformAction(this.action); + } + + public static LootItemCondition.Builder canToolPerformAction(ToolAction action) { + return () -> new CanToolPerformAction(action); + } + + public static class Serializer implements net.minecraft.world.level.storage.loot.Serializer { + public void serialize(JsonObject json, CanToolPerformAction itemCondition, @Nonnull JsonSerializationContext context) { + json.addProperty("action", itemCondition.action.name()); + } + + @Nonnull + public CanToolPerformAction deserialize(JsonObject json, @Nonnull JsonDeserializationContext context) { + return new CanToolPerformAction(ToolAction.get(json.get("action").getAsString())); + } + } + +}