From 9a7f279f91282c3dec7dc5c5ba990ccf96e77639 Mon Sep 17 00:00:00 2001 From: alpha Date: Tue, 16 Jul 2024 01:04:32 -0500 Subject: [PATCH] WIP Tool actions refactor --- .../build.gradle | 0 .../e363a18310a24f02bdb404f7180170842373bd76 | 0 .../loot_tables/blocks/acacia_leaves.json | 0 .../loot_tables/blocks/azalea_leaves.json | 0 .../loot_tables/blocks/birch_leaves.json | 0 .../loot_tables/blocks/cherry_leaves.json | 0 .../minecraft/loot_tables/blocks/cobweb.json | 0 .../loot_tables/blocks/dark_oak_leaves.json | 0 .../loot_tables/blocks/dead_bush.json | 0 .../minecraft/loot_tables/blocks/fern.json | 0 .../blocks/flowering_azalea_leaves.json | 0 .../loot_tables/blocks/glow_lichen.json | 0 .../loot_tables/blocks/hanging_roots.json | 0 .../loot_tables/blocks/jungle_leaves.json | 0 .../loot_tables/blocks/large_fern.json | 0 .../loot_tables/blocks/mangrove_leaves.json | 0 .../loot_tables/blocks/nether_sprouts.json | 0 .../loot_tables/blocks/oak_leaves.json | 0 .../loot_tables/blocks/seagrass.json | 0 .../loot_tables/blocks/short_grass.json | 0 .../loot_tables/blocks/small_dripleaf.json | 0 .../loot_tables/blocks/spruce_leaves.json | 0 .../loot_tables/blocks/tall_grass.json | 0 .../loot_tables/blocks/tall_seagrass.json | 0 .../loot_tables/blocks/twisting_vines.json | 0 .../blocks/twisting_vines_plant.json | 0 .../minecraft/loot_tables/blocks/vine.json | 0 .../loot_tables/blocks/weeping_vines.json | 0 .../blocks/weeping_vines_plant.json | 0 .../porting_lib/tool/ItemAbilities.java | 161 ++++++++++++++++++ .../porting_lib/tool/ItemAbility.java | 50 ++++++ .../tool/addons/ToolActionItem.java | 8 +- .../tool/data/ToolActionsData.java | 0 .../data/ToolActionsLootTableProvider.java | 16 +- .../tool/extensions/BlockStateExtensions.java | 12 +- .../tool/extensions/ItemStackExtensions.java | 17 ++ .../extensions/VanillaToolActionItem.java | 4 +- .../tool/loot/CanItemPerformAbility.java} | 43 +++-- .../porting_lib/tool/mixin/AxeItemMixin.java | 8 +- .../tool/mixin/BambooSaplingBlockMixin.java | 4 +- .../tool/mixin/BambooStalkBlockMixin.java | 4 +- .../tool/mixin/BeehiveBlockMixin.java | 4 +- .../porting_lib/tool/mixin/BlockMixin.java | 0 .../tool/mixin/BlockStateMixin.java | 0 .../tool/mixin/BuilderAccessor.java | 0 .../mixin/CompositeEntryBaseAccessor.java | 0 .../CompositeLootItemConditionAccessor.java | 0 .../tool/mixin/FishingHookMixin.java | 4 +- .../tool/mixin/FishingHookRendererMixin.java | 4 +- .../tool/mixin/FishingRodItemMixin.java | 8 +- .../porting_lib/tool/mixin/HoeItemMixin.java | 8 +- .../InvertedLootItemConditionAccessor.java | 0 .../tool/mixin/ItemStackMixin.java | 4 +- .../tool/mixin/LivingEntityMixin.java | 4 +- .../mixin/LootPoolEntryContainerAccessor.java | 0 .../tool/mixin/PickaxeItemMixin.java | 8 +- .../porting_lib/tool/mixin/PlayerMixin.java | 6 +- .../tool/mixin/PumpkinBlockMixin.java | 4 +- .../tool/mixin/ShearsItemMixin.java | 8 +- .../tool/mixin/ShieldItemMixin.java | 8 +- .../tool/mixin/ShovelItemMixin.java | 8 +- ...topHoldingItemIfNoLongerAdmiringMixin.java | 4 +- .../tool/mixin/SwordItemMixin.java | 8 +- .../tool/mixin/TripWireBlockMixin.java | 6 +- .../src/main/resources/fabric.mod.json | 2 +- .../porting_lib_tool_actions.accesswidener | 0 .../porting_lib_tool_actions.mixins.json | 0 .../porting_lib/loot/PortingLibLoot.java | 6 - .../extensions/LootContextExtensions.java | 4 - .../loot/mixin/LootContextMixin.java | 5 - .../porting_lib/tool/ToolAction.java | 47 ----- .../porting_lib/tool/ToolActions.java | 115 ------------- .../tool/extensions/BlockExtensions.java | 88 ---------- .../tool/extensions/ItemStackExtensions.java | 9 - 74 files changed, 323 insertions(+), 376 deletions(-) rename modules/{tool_actions => item_abilities}/build.gradle (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/.cache/e363a18310a24f02bdb404f7180170842373bd76 (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/acacia_leaves.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/azalea_leaves.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/birch_leaves.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/cherry_leaves.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/cobweb.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/dark_oak_leaves.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/dead_bush.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/fern.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/flowering_azalea_leaves.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/glow_lichen.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/hanging_roots.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/jungle_leaves.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/large_fern.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/mangrove_leaves.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/nether_sprouts.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/oak_leaves.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/seagrass.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/short_grass.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/small_dripleaf.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/spruce_leaves.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/tall_grass.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/tall_seagrass.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/twisting_vines.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/twisting_vines_plant.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/vine.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/weeping_vines.json (100%) rename modules/{tool_actions => item_abilities}/src/generated/resources/data/minecraft/loot_tables/blocks/weeping_vines_plant.json (100%) create mode 100644 modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/ItemAbilities.java create mode 100644 modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/ItemAbility.java rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/addons/ToolActionItem.java (56%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/data/ToolActionsData.java (100%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/data/ToolActionsLootTableProvider.java (96%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/BlockStateExtensions.java (78%) create mode 100644 modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/ItemStackExtensions.java rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/VanillaToolActionItem.java (51%) rename modules/{tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/loot/CanToolPerformAction.java => item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/loot/CanItemPerformAbility.java} (54%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/AxeItemMixin.java (56%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BambooSaplingBlockMixin.java (77%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BambooStalkBlockMixin.java (77%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BeehiveBlockMixin.java (88%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BlockMixin.java (100%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BlockStateMixin.java (100%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BuilderAccessor.java (100%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/CompositeEntryBaseAccessor.java (100%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/CompositeLootItemConditionAccessor.java (100%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingHookMixin.java (88%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingHookRendererMixin.java (87%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingRodItemMixin.java (57%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/HoeItemMixin.java (56%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/InvertedLootItemConditionAccessor.java (100%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ItemStackMixin.java (88%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/LivingEntityMixin.java (87%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/LootPoolEntryContainerAccessor.java (100%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PickaxeItemMixin.java (57%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PlayerMixin.java (88%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PumpkinBlockMixin.java (88%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShearsItemMixin.java (57%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShieldItemMixin.java (57%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShovelItemMixin.java (57%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/StopHoldingItemIfNoLongerAdmiringMixin.java (88%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/SwordItemMixin.java (57%) rename modules/{tool_actions => item_abilities}/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/TripWireBlockMixin.java (81%) rename modules/{tool_actions => item_abilities}/src/main/resources/fabric.mod.json (96%) rename modules/{tool_actions => item_abilities}/src/main/resources/porting_lib_tool_actions.accesswidener (100%) rename modules/{tool_actions => item_abilities}/src/main/resources/porting_lib_tool_actions.mixins.json (100%) delete mode 100644 modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/ToolAction.java delete mode 100644 modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/ToolActions.java delete mode 100644 modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/BlockExtensions.java delete mode 100644 modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/ItemStackExtensions.java diff --git a/modules/tool_actions/build.gradle b/modules/item_abilities/build.gradle similarity index 100% rename from modules/tool_actions/build.gradle rename to modules/item_abilities/build.gradle diff --git a/modules/tool_actions/src/generated/resources/.cache/e363a18310a24f02bdb404f7180170842373bd76 b/modules/item_abilities/src/generated/resources/.cache/e363a18310a24f02bdb404f7180170842373bd76 similarity index 100% rename from modules/tool_actions/src/generated/resources/.cache/e363a18310a24f02bdb404f7180170842373bd76 rename to modules/item_abilities/src/generated/resources/.cache/e363a18310a24f02bdb404f7180170842373bd76 diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/acacia_leaves.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/acacia_leaves.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/acacia_leaves.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/acacia_leaves.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/azalea_leaves.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/azalea_leaves.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/azalea_leaves.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/azalea_leaves.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/birch_leaves.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/birch_leaves.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/birch_leaves.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/birch_leaves.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/cherry_leaves.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/cherry_leaves.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/cherry_leaves.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/cherry_leaves.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/cobweb.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/cobweb.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/cobweb.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/cobweb.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/dark_oak_leaves.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/dark_oak_leaves.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/dark_oak_leaves.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/dark_oak_leaves.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/dead_bush.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/dead_bush.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/dead_bush.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/dead_bush.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/fern.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/fern.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/fern.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/fern.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/flowering_azalea_leaves.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/flowering_azalea_leaves.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/flowering_azalea_leaves.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/flowering_azalea_leaves.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/glow_lichen.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/glow_lichen.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/glow_lichen.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/glow_lichen.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/hanging_roots.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/hanging_roots.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/hanging_roots.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/hanging_roots.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/jungle_leaves.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/jungle_leaves.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/jungle_leaves.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/jungle_leaves.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/large_fern.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/large_fern.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/large_fern.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/large_fern.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/mangrove_leaves.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/mangrove_leaves.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/mangrove_leaves.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/mangrove_leaves.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/nether_sprouts.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/nether_sprouts.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/nether_sprouts.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/nether_sprouts.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/oak_leaves.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/oak_leaves.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/oak_leaves.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/oak_leaves.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/seagrass.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/seagrass.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/seagrass.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/seagrass.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/short_grass.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/short_grass.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/short_grass.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/short_grass.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/small_dripleaf.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/small_dripleaf.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/small_dripleaf.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/small_dripleaf.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/spruce_leaves.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/spruce_leaves.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/spruce_leaves.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/spruce_leaves.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/tall_grass.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/tall_grass.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/tall_grass.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/tall_grass.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/tall_seagrass.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/tall_seagrass.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/tall_seagrass.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/tall_seagrass.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/twisting_vines.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/twisting_vines.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/twisting_vines.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/twisting_vines.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/twisting_vines_plant.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/twisting_vines_plant.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/twisting_vines_plant.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/twisting_vines_plant.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/vine.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/vine.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/vine.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/vine.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/weeping_vines.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/weeping_vines.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/weeping_vines.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/weeping_vines.json diff --git a/modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/weeping_vines_plant.json b/modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/weeping_vines_plant.json similarity index 100% rename from modules/tool_actions/src/generated/resources/data/minecraft/loot_tables/blocks/weeping_vines_plant.json rename to modules/item_abilities/src/generated/resources/data/minecraft/loot_tables/blocks/weeping_vines_plant.json diff --git a/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/ItemAbilities.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/ItemAbilities.java new file mode 100644 index 000000000..0d73c4046 --- /dev/null +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/ItemAbilities.java @@ -0,0 +1,161 @@ +/* + * Copyright (c) Forge Development LLC and contributors + * SPDX-License-Identifier: LGPL-2.1-only + */ + +package io.github.fabricators_of_create.porting_lib.tool; + +import com.google.common.collect.Sets; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import net.minecraft.core.BlockPos; +import net.minecraft.core.dispenser.BlockSource; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.item.ItemStack; + +public class ItemAbilities { + /** + * Exposed by axes to allow querying tool behaviours + */ + public static final ItemAbility AXE_DIG = ItemAbility.get("axe_dig"); + + /** + * Exposed by pickaxes to allow querying tool behaviours + */ + public static final ItemAbility PICKAXE_DIG = ItemAbility.get("pickaxe_dig"); + + /** + * Exposed by shovels to allow querying tool behaviours + */ + public static final ItemAbility SHOVEL_DIG = ItemAbility.get("shovel_dig"); + + /** + * Exposed by hoes to allow querying tool behaviours + */ + public static final ItemAbility HOE_DIG = ItemAbility.get("hoe_dig"); + + /** + * Exposed by swords to allow querying tool behaviours + */ + public static final ItemAbility SWORD_DIG = ItemAbility.get("sword_dig"); + + /** + * Exposed by shears to allow querying tool behaviours + */ + public static final ItemAbility SHEARS_DIG = ItemAbility.get("shears_dig"); + + /** + * Passed onto {@link IBlockExtension#getToolModifiedState} when an axe wants to strip a log + */ + public static final ItemAbility AXE_STRIP = ItemAbility.get("axe_strip"); + + /** + * Passed onto {@link IBlockExtension#getToolModifiedState} when an axe wants to scrape oxidization off copper + */ + public static final ItemAbility AXE_SCRAPE = ItemAbility.get("axe_scrape"); + + /** + * Passed onto {@link IBlockExtension#getToolModifiedState} when an axe wants to remove wax out of copper + */ + public static final ItemAbility AXE_WAX_OFF = ItemAbility.get("axe_wax_off"); + + /** + * Passed onto {@link IBlockExtension#getToolModifiedState} when a shovel wants to turn dirt into path + */ + public static final ItemAbility SHOVEL_FLATTEN = ItemAbility.get("shovel_flatten"); + + /** + * Passed onto {@link IBlockExtension#getToolModifiedState} when a shovel wants to douse a campfire + */ + public static final ItemAbility SHOVEL_DOUSE = ItemAbility.get("shovel_douse"); + + /** + * Used during player attack to figure out if a sweep attack should be performed + * + * @see IItemExtension#getSweepHitBox + */ + public static final ItemAbility SWORD_SWEEP = ItemAbility.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. + * + * @see CommonHooks#tryDispenseShearsHarvestBlock(BlockSource, ItemStack, ServerLevel, BlockPos) + */ + 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 on a pumpkin to carve it. + */ + public static final ItemAbility SHEARS_CARVE = ItemAbility.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 ItemAbility SHEARS_DISARM = ItemAbility.get("shears_disarm"); + + /** + * This action is exposed by shears and corresponds to a trim action that is triggered with a right click on a block that supports such behavior. + * Example: Right click with shears on a {@link net.minecraft.world.level.block.GrowingPlantHeadBlock growing plant} to stop it from growing. + */ + public static final ItemAbility SHEARS_TRIM = ItemAbility.get("shears_trim"); + + /** + * Passed onto {@link IBlockExtension#getToolModifiedState} when a hoe wants to turn dirt into soil + */ + public static final ItemAbility HOE_TILL = ItemAbility.get("till"); + + /** + * An item ability corresponding to the 'block' action of shields. + * Items should expose this item ability in order to enable damage blocking when the item is being "used". + */ + public static final ItemAbility SHIELD_BLOCK = ItemAbility.get("shield_block"); + + /** + * This action corresponds to right-clicking the fishing rod to reel it in after earlier casting. + * Needed for modded fishing rods so that the FishingHook entity can properly function. + */ + public static final ItemAbility FISHING_ROD_CAST = ItemAbility.get("fishing_rod_cast"); + + /** + * Exposed by trident-like items to allow querying tool behaviours for items that can be thrown like Tridents. + */ + public static final ItemAbility TRIDENT_THROW = ItemAbility.get("trident_throw"); + + /** + * Exposed by brushes to allow querying tool behaviours for items that can brush Suspicious Blocks. + */ + public static final ItemAbility BRUSH_BRUSH = ItemAbility.get("brush_brush"); + + /** + * Passed onto {@link IBlockExtension#getToolModifiedState} when flint and steel or fire charge want to light a campfire/candle/cake. + * Note that dispensers with flint and steel will also use this but will have no player. + */ + public static final ItemAbility FIRESTARTER_LIGHT = ItemAbility.get("firestarter_light"); + + // Default actions supported by each tool type + 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, HOE_TILL); + public static final Set DEFAULT_SHOVEL_ACTIONS = of(SHOVEL_DIG, SHOVEL_FLATTEN, SHOVEL_DOUSE); + 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_REMOVE_ARMOR, SHEARS_CARVE, SHEARS_DISARM, SHEARS_TRIM); + 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); + public static final Set DEFAULT_BRUSH_ACTIONS = of(BRUSH_BRUSH); + public static final Set DEFAULT_FLINT_ACTIONS = of(FIRESTARTER_LIGHT); + public static final Set DEFAULT_FIRECHARGE_ACTIONS = of(FIRESTARTER_LIGHT); + + private static Set of(ItemAbility... actions) { + return Stream.of(actions).collect(Collectors.toCollection(Sets::newIdentityHashSet)); + } +} diff --git a/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/ItemAbility.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/ItemAbility.java new file mode 100644 index 000000000..f13d853ac --- /dev/null +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/ItemAbility.java @@ -0,0 +1,50 @@ +package io.github.fabricators_of_create.porting_lib.tool; + +import com.mojang.serialization.Codec; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public final class ItemAbility { + private static final Map actions = new ConcurrentHashMap<>(); + + public static Codec CODEC = Codec.STRING.xmap(ItemAbility::get, ItemAbility::name); + + /** + * Returns all registered actions. + * This collection can be kept around, and will update itself in response to changes to the map. + * See {@link ConcurrentHashMap#values()} for details. + */ + public static Collection getActions() { + return Collections.unmodifiableCollection(actions.values()); + } + + /** + * Gets or creates a new ItemAbility for the given name. + */ + public static ItemAbility get(String name) { + return actions.computeIfAbsent(name, ItemAbility::new); + } + + /** + * Returns the name of this item ability + */ + public String name() { + return name; + } + + @Override + public String toString() { + return "ItemAbility[" + name + "]"; + } + + private final String name; + + /** + * Use {@link #get(String)} to get or create a ItemAbility + */ + private ItemAbility(String name) { + this.name = name; + } +} diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/addons/ToolActionItem.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/addons/ToolActionItem.java similarity index 56% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/addons/ToolActionItem.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/addons/ToolActionItem.java index 40f288b61..e92a4d9f0 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/addons/ToolActionItem.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/addons/ToolActionItem.java @@ -1,18 +1,18 @@ package io.github.fabricators_of_create.porting_lib.tool.addons; -import io.github.fabricators_of_create.porting_lib.tool.ToolAction; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbility; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; import net.minecraft.world.item.ItemStack; public interface ToolActionItem { /** * Queries if an item can perform the given action. - * See {@link ToolActions} for a description of each stock action + * See {@link ItemAbilities} for a description of each stock action * @param stack The stack being used * @param toolAction The action being queried * @return True if the stack can perform the action */ - default boolean canPerformAction(ItemStack stack, ToolAction toolAction) { + default boolean canPerformAction(ItemStack stack, ItemAbility toolAction) { return false; } } diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/data/ToolActionsData.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/data/ToolActionsData.java similarity index 100% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/data/ToolActionsData.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/data/ToolActionsData.java diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/data/ToolActionsLootTableProvider.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/data/ToolActionsLootTableProvider.java similarity index 96% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/data/ToolActionsLootTableProvider.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/data/ToolActionsLootTableProvider.java index fe887ea61..7a90c362c 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/data/ToolActionsLootTableProvider.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/data/ToolActionsLootTableProvider.java @@ -17,16 +17,16 @@ import com.google.common.collect.Sets; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; -import io.github.fabricators_of_create.porting_lib.tool.loot.CanToolPerformAction; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; +import io.github.fabricators_of_create.porting_lib.tool.loot.CanItemPerformAbility; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.minecraft.Util; import net.minecraft.advancements.critereon.ItemPredicate; import net.minecraft.core.Holder; +import net.minecraft.core.HolderLookup; import net.minecraft.data.CachedOutput; import net.minecraft.data.DataProvider; -import net.minecraft.data.PackOutput; import net.minecraft.data.loot.LootTableProvider; import net.minecraft.data.loot.LootTableSubProvider; import net.minecraft.data.loot.packs.VanillaLootTableProvider; @@ -70,8 +70,8 @@ public final class ToolActionsLootTableProvider extends LootTableProvider { private final List> conditionReplacers = new ArrayList<>(); - public ToolActionsLootTableProvider(FabricDataOutput packOutput) { - super(packOutput, Set.of(), VanillaLootTableProvider.create(packOutput).subProviders); + public ToolActionsLootTableProvider(FabricDataOutput packOutput, CompletableFuture provider) { + super(packOutput, Set.of(), VanillaLootTableProvider.create(packOutput, provider).subProviders, provider); } protected void validate(Map map, ValidationContext validationcontext) { @@ -81,13 +81,13 @@ protected void validate(Map map, ValidationContext public List getTables() { replaceLootItemCondition(condition -> { if (condition instanceof MatchTool matchTool && checkMatchTool(matchTool, Items.SHEARS)) { - return CanToolPerformAction.canToolPerformAction(ToolActions.SHEARS_DIG); + return CanItemPerformAbility.canItemPerformAbility(ItemAbilities.SHEARS_DIG); } return null; }); - return this.subProviders.stream().map(entry -> { + return this.getTables().stream().map(entry -> { // Provides new sub provider with filtering only changed loot tables and replacing condition item to condition tag - return new LootTableProvider.SubProviderEntry(() -> replaceAndFilterChangesOnly(entry.provider().get()), entry.paramSet()); + return new LootTableProvider.SubProviderEntry(provider -> replaceAndFilterChangesOnly(entry.provider().apply(provider)), entry.paramSet()); }).collect(Collectors.toList()); } diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/BlockStateExtensions.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/BlockStateExtensions.java similarity index 78% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/BlockStateExtensions.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/BlockStateExtensions.java index 36bcac04a..18ec18dea 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/BlockStateExtensions.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/BlockStateExtensions.java @@ -1,7 +1,7 @@ package io.github.fabricators_of_create.porting_lib.tool.extensions; -import io.github.fabricators_of_create.porting_lib.tool.ToolAction; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbility; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; @@ -14,8 +14,8 @@ public interface BlockStateExtensions { /** * Returns the state that this block should transform into when right-clicked by a tool. - * For example: Used to determine if {@link ToolActions#AXE_STRIP an axe can strip}, - * {@link ToolActions#SHOVEL_FLATTEN a shovel can path}, or {@link ToolActions#HOE_TILL a hoe can till}. + * For example: Used to determine if {@link ItemAbilities#AXE_STRIP an axe can strip}, + * {@link ItemAbilities#SHOVEL_FLATTEN a shovel can path}, or {@link ItemAbilities#HOE_TILL a hoe can till}. * Returns {@code null} if nothing should happen. * * @param context The use on context that the action was performed in @@ -24,7 +24,7 @@ public interface BlockStateExtensions { * @return The resulting state after the action has been performed */ @Nullable - default BlockState getToolModifiedState(UseOnContext context, ToolAction toolAction, boolean simulate) { + default BlockState getToolModifiedState(UseOnContext context, ItemAbility toolAction, boolean simulate) { return ((BlockState) this).getBlock().getToolModifiedState(((BlockState) this), context, toolAction, simulate); } @@ -41,7 +41,7 @@ default BlockState getToolModifiedState(UseOnContext context, ToolAction toolAct * @return The resulting state after the action has been performed */ @Nullable - default BlockState getToolModifiedState(Level world, BlockPos pos, Player player, ItemStack stack, ToolAction toolAction) { + default BlockState getToolModifiedState(Level world, BlockPos pos, Player player, ItemStack stack, ItemAbility toolAction) { return ((BlockState) this).getBlock().getToolModifiedState(((BlockState) this), world, pos, player, stack, toolAction); } } diff --git a/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/ItemStackExtensions.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/ItemStackExtensions.java new file mode 100644 index 000000000..2a1063107 --- /dev/null +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/ItemStackExtensions.java @@ -0,0 +1,17 @@ +package io.github.fabricators_of_create.porting_lib.tool.extensions; + +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbility; + +public interface ItemStackExtensions { + /** + * Queries if an item can perform the given action. + * See {@link ItemAbilities} for a description of each stock action + * + * @param itemAbility The action being queried + * @return True if the stack can perform the action + */ + default boolean canPerformAction(ItemAbility itemAbility) { + return self().getItem().canPerformAction(self(), itemAbility); + } +} diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/VanillaToolActionItem.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/VanillaToolActionItem.java similarity index 51% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/VanillaToolActionItem.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/VanillaToolActionItem.java index c68637358..508b3bed1 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/VanillaToolActionItem.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/VanillaToolActionItem.java @@ -1,8 +1,8 @@ package io.github.fabricators_of_create.porting_lib.tool.extensions; -import io.github.fabricators_of_create.porting_lib.tool.ToolAction; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbility; import net.minecraft.world.item.ItemStack; public interface VanillaToolActionItem { - boolean port_lib$canPerformAction(ItemStack stack, ToolAction toolAction); + boolean port_lib$canPerformAction(ItemStack stack, ItemAbility toolAction); } diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/loot/CanToolPerformAction.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/loot/CanItemPerformAbility.java similarity index 54% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/loot/CanToolPerformAction.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/loot/CanItemPerformAbility.java index a5eb16b90..b58d8fac1 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/loot/CanToolPerformAction.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/loot/CanItemPerformAbility.java @@ -1,14 +1,14 @@ package io.github.fabricators_of_create.porting_lib.tool.loot; import com.google.common.collect.ImmutableSet; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonObject; -import com.google.gson.JsonSerializationContext; import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + import io.github.fabricators_of_create.porting_lib.core.PortingLib; -import io.github.fabricators_of_create.porting_lib.tool.ToolAction; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbility; import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.item.ItemStack; @@ -22,47 +22,42 @@ import java.util.Set; /** - * This LootItemCondition "porting_lib:can_tool_perform_action" can be used to check if a tool can perform a given ToolAction. + * This LootItemCondition "porting_lib:can_item_perform_ability" can be used to check if a tool can perform a given ItemAbility. */ -public class CanToolPerformAction implements LootItemCondition { - public static final Codec CODEC = Codec.STRING.xmap(CanToolPerformAction::ofNamed, CanToolPerformAction::getActionName); - public static final LootItemConditionType LOOT_CONDITION_TYPE = new LootItemConditionType(CODEC); - - final ToolAction action; +public class CanItemPerformAbility implements LootItemCondition { + public static MapCodec CODEC = RecordCodecBuilder.mapCodec( + builder -> builder + .group( + ItemAbility.CODEC.fieldOf("ability").forGetter(action -> action.ability)) + .apply(builder, CanItemPerformAbility::new)); - public CanToolPerformAction(ToolAction action) { - this.action = action; - } + public static final LootItemConditionType LOOT_CONDITION_TYPE = new LootItemConditionType(CODEC); - public static CanToolPerformAction ofNamed(String name) { - return new CanToolPerformAction(ToolAction.get(name)); - } + final ItemAbility ability; - public String getActionName() { - return this.action.name(); + public CanItemPerformAbility(ItemAbility ability) { + this.ability = ability; } - @NotNull public LootItemConditionType getType() { return LOOT_CONDITION_TYPE; } - @NotNull 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); + return itemstack != null && itemstack.canPerformAction(this.ability); } - public static LootItemCondition.Builder canToolPerformAction(ToolAction action) { - return () -> new CanToolPerformAction(action); + public static LootItemCondition.Builder canItemPerformAbility(ItemAbility action) { + return () -> new CanItemPerformAbility(action); } public static void init() { - Registry.register(BuiltInRegistries.LOOT_CONDITION_TYPE, PortingLib.id("can_tool_perform_action"), CanToolPerformAction.LOOT_CONDITION_TYPE); + Registry.register(BuiltInRegistries.LOOT_CONDITION_TYPE, PortingLib.id("can_item_perform_ability"), CanItemPerformAbility.LOOT_CONDITION_TYPE); } } diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/AxeItemMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/AxeItemMixin.java similarity index 56% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/AxeItemMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/AxeItemMixin.java index 9d565097d..35b4eec56 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/AxeItemMixin.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/AxeItemMixin.java @@ -1,7 +1,7 @@ package io.github.fabricators_of_create.porting_lib.tool.mixin; -import io.github.fabricators_of_create.porting_lib.tool.ToolAction; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbility; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; import io.github.fabricators_of_create.porting_lib.tool.extensions.VanillaToolActionItem; import net.minecraft.world.item.AxeItem; @@ -12,7 +12,7 @@ @Mixin(AxeItem.class) public class AxeItemMixin implements VanillaToolActionItem { @Override - public boolean port_lib$canPerformAction(ItemStack stack, ToolAction toolAction) { - return ToolActions.DEFAULT_AXE_ACTIONS.contains(toolAction); + public boolean port_lib$canPerformAction(ItemStack stack, ItemAbility toolAction) { + return ItemAbilities.DEFAULT_AXE_ACTIONS.contains(toolAction); } } diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BambooSaplingBlockMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BambooSaplingBlockMixin.java similarity index 77% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BambooSaplingBlockMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BambooSaplingBlockMixin.java index 48fc81e30..bff4b24aa 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BambooSaplingBlockMixin.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BambooSaplingBlockMixin.java @@ -2,7 +2,7 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; import io.github.fabricators_of_create.porting_lib.tool.addons.ToolActionItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; @@ -17,7 +17,7 @@ public class BambooSaplingBlockMixin { @ModifyExpressionValue(method = "getDestroyProgress", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;getMainHandItem()Lnet/minecraft/world/item/ItemStack;")) private ItemStack toolActionIsSword(ItemStack original) { if (original.getItem() instanceof ToolActionItem) - return original.canPerformAction(ToolActions.SWORD_DIG) ? original.getItem() instanceof SwordItem ? original : Items.IRON_SWORD.getDefaultInstance() : Items.AIR.getDefaultInstance(); + return original.canPerformAction(ItemAbilities.SWORD_DIG) ? original.getItem() instanceof SwordItem ? original : Items.IRON_SWORD.getDefaultInstance() : Items.AIR.getDefaultInstance(); return original; } } diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BambooStalkBlockMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BambooStalkBlockMixin.java similarity index 77% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BambooStalkBlockMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BambooStalkBlockMixin.java index eeaba8fb0..629aeb8b3 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BambooStalkBlockMixin.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BambooStalkBlockMixin.java @@ -2,7 +2,7 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; import io.github.fabricators_of_create.porting_lib.tool.addons.ToolActionItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; @@ -17,7 +17,7 @@ public class BambooStalkBlockMixin { @ModifyExpressionValue(method = "getDestroyProgress", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;getMainHandItem()Lnet/minecraft/world/item/ItemStack;")) private ItemStack toolActionIsSword(ItemStack original) { if (original.getItem() instanceof ToolActionItem) - return original.canPerformAction(ToolActions.SWORD_DIG) ? original.getItem() instanceof SwordItem ? original : Items.IRON_SWORD.getDefaultInstance() : Items.AIR.getDefaultInstance(); + return original.canPerformAction(ItemAbilities.SWORD_DIG) ? original.getItem() instanceof SwordItem ? original : Items.IRON_SWORD.getDefaultInstance() : Items.AIR.getDefaultInstance(); return original; } } diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BeehiveBlockMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BeehiveBlockMixin.java similarity index 88% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BeehiveBlockMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BeehiveBlockMixin.java index b0fdec04c..660539d78 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BeehiveBlockMixin.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BeehiveBlockMixin.java @@ -5,7 +5,7 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; import io.github.fabricators_of_create.porting_lib.tool.addons.ToolActionItem; import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; @@ -22,7 +22,7 @@ public class BeehiveBlockMixin { private boolean supportsToolAction(boolean original, BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { ItemStack stack = player.getItemInHand(hand); if (stack.getItem() instanceof ToolActionItem toolActionItem) - return toolActionItem.canPerformAction(stack, ToolActions.SHEARS_HARVEST); + return toolActionItem.canPerformAction(stack, ItemAbilities.SHEARS_HARVEST); return original; } } diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BlockMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BlockMixin.java similarity index 100% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BlockMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BlockMixin.java diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BlockStateMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BlockStateMixin.java similarity index 100% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BlockStateMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BlockStateMixin.java diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BuilderAccessor.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BuilderAccessor.java similarity index 100% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BuilderAccessor.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/BuilderAccessor.java diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/CompositeEntryBaseAccessor.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/CompositeEntryBaseAccessor.java similarity index 100% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/CompositeEntryBaseAccessor.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/CompositeEntryBaseAccessor.java diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/CompositeLootItemConditionAccessor.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/CompositeLootItemConditionAccessor.java similarity index 100% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/CompositeLootItemConditionAccessor.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/CompositeLootItemConditionAccessor.java diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingHookMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingHookMixin.java similarity index 88% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingHookMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingHookMixin.java index 8c10ba848..a4ace5003 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingHookMixin.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingHookMixin.java @@ -2,7 +2,7 @@ import com.llamalad7.mixinextras.injector.ModifyReceiver; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; import io.github.fabricators_of_create.porting_lib.tool.addons.ToolActionItem; import net.minecraft.world.entity.projectile.FishingHook; @@ -20,7 +20,7 @@ public class FishingHookMixin { @ModifyReceiver(method = "shouldStopFishing", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;is(Lnet/minecraft/world/item/Item;)Z")) private ItemStack toolActionCast(ItemStack instance, Item item) { if (instance.getItem() instanceof ToolActionItem) { - if (instance.canPerformAction(ToolActions.FISHING_ROD_CAST)) { + if (instance.canPerformAction(ItemAbilities.FISHING_ROD_CAST)) { return instance.getItem() instanceof FishingRodItem ? instance : Items.FISHING_ROD.getDefaultInstance(); } return Items.AIR.getDefaultInstance(); diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingHookRendererMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingHookRendererMixin.java similarity index 87% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingHookRendererMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingHookRendererMixin.java index d6229373f..6428fd95f 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingHookRendererMixin.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingHookRendererMixin.java @@ -4,7 +4,7 @@ import com.llamalad7.mixinextras.sugar.Local; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; import io.github.fabricators_of_create.porting_lib.tool.addons.ToolActionItem; import net.minecraft.client.renderer.entity.FishingHookRenderer; @@ -18,7 +18,7 @@ public class FishingHookRendererMixin { @ModifyExpressionValue(method = "render(Lnet/minecraft/world/entity/projectile/FishingHook;FFLcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/client/renderer/MultiBufferSource;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;is(Lnet/minecraft/world/item/Item;)Z")) private boolean toolActionFishingHook(boolean original, @Local(index = 13) ItemStack stack) { if (stack.getItem() instanceof ToolActionItem) - return stack.canPerformAction(ToolActions.FISHING_ROD_CAST); + return stack.canPerformAction(ItemAbilities.FISHING_ROD_CAST); return original; } } diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingRodItemMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingRodItemMixin.java similarity index 57% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingRodItemMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingRodItemMixin.java index fc12bea4c..7599ccbe0 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingRodItemMixin.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/FishingRodItemMixin.java @@ -1,7 +1,7 @@ package io.github.fabricators_of_create.porting_lib.tool.mixin; -import io.github.fabricators_of_create.porting_lib.tool.ToolAction; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbility; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; import io.github.fabricators_of_create.porting_lib.tool.extensions.VanillaToolActionItem; import net.minecraft.world.item.FishingRodItem; @@ -12,7 +12,7 @@ @Mixin(FishingRodItem.class) public class FishingRodItemMixin implements VanillaToolActionItem { @Override - public boolean port_lib$canPerformAction(ItemStack stack, ToolAction toolAction) { - return ToolActions.DEFAULT_FISHING_ROD_ACTIONS.contains(toolAction); + public boolean port_lib$canPerformAction(ItemStack stack, ItemAbility toolAction) { + return ItemAbilities.DEFAULT_FISHING_ROD_ACTIONS.contains(toolAction); } } diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/HoeItemMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/HoeItemMixin.java similarity index 56% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/HoeItemMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/HoeItemMixin.java index 3488c3182..98da9117c 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/HoeItemMixin.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/HoeItemMixin.java @@ -1,7 +1,7 @@ package io.github.fabricators_of_create.porting_lib.tool.mixin; -import io.github.fabricators_of_create.porting_lib.tool.ToolAction; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbility; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; import io.github.fabricators_of_create.porting_lib.tool.extensions.VanillaToolActionItem; import net.minecraft.world.item.HoeItem; @@ -12,7 +12,7 @@ @Mixin(HoeItem.class) public class HoeItemMixin implements VanillaToolActionItem { @Override - public boolean port_lib$canPerformAction(ItemStack stack, ToolAction toolAction) { - return ToolActions.DEFAULT_HOE_ACTIONS.contains(toolAction); + public boolean port_lib$canPerformAction(ItemStack stack, ItemAbility toolAction) { + return ItemAbilities.DEFAULT_HOE_ACTIONS.contains(toolAction); } } diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/InvertedLootItemConditionAccessor.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/InvertedLootItemConditionAccessor.java similarity index 100% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/InvertedLootItemConditionAccessor.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/InvertedLootItemConditionAccessor.java diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ItemStackMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ItemStackMixin.java similarity index 88% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ItemStackMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ItemStackMixin.java index d5c5112f1..701173e8a 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ItemStackMixin.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ItemStackMixin.java @@ -1,6 +1,6 @@ package io.github.fabricators_of_create.porting_lib.tool.mixin; -import io.github.fabricators_of_create.porting_lib.tool.ToolAction; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbility; import io.github.fabricators_of_create.porting_lib.tool.addons.ToolActionItem; import io.github.fabricators_of_create.porting_lib.tool.extensions.ItemStackExtensions; import io.github.fabricators_of_create.porting_lib.tool.extensions.VanillaToolActionItem; @@ -16,7 +16,7 @@ public abstract class ItemStackMixin implements ItemStackExtensions { public abstract Item getItem(); @Override - public boolean canPerformAction(ToolAction toolAction) { + public boolean canPerformAction(ItemAbility toolAction) { var item = getItem(); if (item instanceof ToolActionItem toolActionItem) return toolActionItem.canPerformAction((ItemStack) (Object) this, toolAction); diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/LivingEntityMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/LivingEntityMixin.java similarity index 87% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/LivingEntityMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/LivingEntityMixin.java index 74f244913..d0d75112e 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/LivingEntityMixin.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/LivingEntityMixin.java @@ -2,7 +2,7 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; import io.github.fabricators_of_create.porting_lib.tool.addons.ToolActionItem; import net.minecraft.world.entity.LivingEntity; @@ -21,7 +21,7 @@ public class LivingEntityMixin { @ModifyExpressionValue(method = "isBlocking", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/Item;getUseAnimation(Lnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/item/UseAnim;")) private UseAnim isToolActionBlocking(UseAnim original) { if (this.useItem.getItem() instanceof ToolActionItem) { - if (!this.useItem.canPerformAction(ToolActions.SHIELD_BLOCK)) + if (!this.useItem.canPerformAction(ItemAbilities.SHIELD_BLOCK)) return UseAnim.NONE; else return UseAnim.BLOCK; diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/LootPoolEntryContainerAccessor.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/LootPoolEntryContainerAccessor.java similarity index 100% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/LootPoolEntryContainerAccessor.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/LootPoolEntryContainerAccessor.java diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PickaxeItemMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PickaxeItemMixin.java similarity index 57% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PickaxeItemMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PickaxeItemMixin.java index 08968f1df..de3b1870b 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PickaxeItemMixin.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PickaxeItemMixin.java @@ -1,7 +1,7 @@ package io.github.fabricators_of_create.porting_lib.tool.mixin; -import io.github.fabricators_of_create.porting_lib.tool.ToolAction; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbility; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; import io.github.fabricators_of_create.porting_lib.tool.extensions.VanillaToolActionItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.PickaxeItem; @@ -11,7 +11,7 @@ @Mixin(PickaxeItem.class) public class PickaxeItemMixin implements VanillaToolActionItem { @Override - public boolean port_lib$canPerformAction(ItemStack stack, ToolAction toolAction) { - return ToolActions.DEFAULT_PICKAXE_ACTIONS.contains(toolAction); + public boolean port_lib$canPerformAction(ItemStack stack, ItemAbility toolAction) { + return ItemAbilities.DEFAULT_PICKAXE_ACTIONS.contains(toolAction); } } diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PlayerMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PlayerMixin.java similarity index 88% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PlayerMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PlayerMixin.java index 8ffafec69..4410deb3f 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PlayerMixin.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PlayerMixin.java @@ -12,7 +12,7 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; import io.github.fabricators_of_create.porting_lib.tool.addons.ToolActionItem; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -28,7 +28,7 @@ protected PlayerMixin(EntityType entityType, Level level @ModifyExpressionValue(method = "hurtCurrentlyUsedShield", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;is(Lnet/minecraft/world/item/Item;)Z")) private boolean shieldToolAction(boolean original) { if (this.useItem.getItem() instanceof ToolActionItem) { - return this.useItem.canPerformAction(ToolActions.SHIELD_BLOCK); + return this.useItem.canPerformAction(ItemAbilities.SHIELD_BLOCK); } return original; } @@ -36,7 +36,7 @@ private boolean shieldToolAction(boolean original) { @ModifyReceiver(method = "attack", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;getItem()Lnet/minecraft/world/item/Item;")) private ItemStack canSwordSweep(ItemStack instance) { if (instance.getItem() instanceof ToolActionItem) { - if (instance.canPerformAction(ToolActions.SWORD_SWEEP)) { + if (instance.canPerformAction(ItemAbilities.SWORD_SWEEP)) { return instance.getItem() instanceof SwordItem ? instance : Items.IRON_SWORD.getDefaultInstance(); } return Items.AIR.getDefaultInstance(); diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PumpkinBlockMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PumpkinBlockMixin.java similarity index 88% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PumpkinBlockMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PumpkinBlockMixin.java index 09a2563a3..08ac64054 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PumpkinBlockMixin.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/PumpkinBlockMixin.java @@ -2,7 +2,7 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; import io.github.fabricators_of_create.porting_lib.tool.addons.ToolActionItem; import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; @@ -23,7 +23,7 @@ public class PumpkinBlockMixin { private boolean supportsToolAction(boolean original, BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { ItemStack stack = player.getItemInHand(hand); if (stack.getItem() instanceof ToolActionItem toolActionItem) - return toolActionItem.canPerformAction(stack, ToolActions.SHEARS_CARVE); + return toolActionItem.canPerformAction(stack, ItemAbilities.SHEARS_CARVE); return original; } } diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShearsItemMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShearsItemMixin.java similarity index 57% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShearsItemMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShearsItemMixin.java index 4928ff156..24778d01f 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShearsItemMixin.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShearsItemMixin.java @@ -1,7 +1,7 @@ package io.github.fabricators_of_create.porting_lib.tool.mixin; -import io.github.fabricators_of_create.porting_lib.tool.ToolAction; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbility; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; import io.github.fabricators_of_create.porting_lib.tool.extensions.VanillaToolActionItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ShearsItem; @@ -11,7 +11,7 @@ @Mixin(ShearsItem.class) public class ShearsItemMixin implements VanillaToolActionItem { @Override - public boolean port_lib$canPerformAction(ItemStack stack, ToolAction toolAction) { - return ToolActions.DEFAULT_SHEARS_ACTIONS.contains(toolAction); + public boolean port_lib$canPerformAction(ItemStack stack, ItemAbility toolAction) { + return ItemAbilities.DEFAULT_SHEARS_ACTIONS.contains(toolAction); } } diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShieldItemMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShieldItemMixin.java similarity index 57% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShieldItemMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShieldItemMixin.java index 72002dba6..7f09fa6b5 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShieldItemMixin.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShieldItemMixin.java @@ -1,7 +1,7 @@ package io.github.fabricators_of_create.porting_lib.tool.mixin; -import io.github.fabricators_of_create.porting_lib.tool.ToolAction; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbility; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; import io.github.fabricators_of_create.porting_lib.tool.extensions.VanillaToolActionItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ShieldItem; @@ -11,7 +11,7 @@ @Mixin(ShieldItem.class) public class ShieldItemMixin implements VanillaToolActionItem { @Override - public boolean port_lib$canPerformAction(ItemStack stack, ToolAction toolAction) { - return ToolActions.DEFAULT_SHIELD_ACTIONS.contains(toolAction); + public boolean port_lib$canPerformAction(ItemStack stack, ItemAbility toolAction) { + return ItemAbilities.DEFAULT_SHIELD_ACTIONS.contains(toolAction); } } diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShovelItemMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShovelItemMixin.java similarity index 57% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShovelItemMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShovelItemMixin.java index ef43da326..4bb8857a0 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShovelItemMixin.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/ShovelItemMixin.java @@ -1,7 +1,7 @@ package io.github.fabricators_of_create.porting_lib.tool.mixin; -import io.github.fabricators_of_create.porting_lib.tool.ToolAction; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbility; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; import io.github.fabricators_of_create.porting_lib.tool.extensions.VanillaToolActionItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ShovelItem; @@ -11,7 +11,7 @@ @Mixin(ShovelItem.class) public class ShovelItemMixin implements VanillaToolActionItem { @Override - public boolean port_lib$canPerformAction(ItemStack stack, ToolAction toolAction) { - return ToolActions.DEFAULT_SHOVEL_ACTIONS.contains(toolAction); + public boolean port_lib$canPerformAction(ItemStack stack, ItemAbility toolAction) { + return ItemAbilities.DEFAULT_SHOVEL_ACTIONS.contains(toolAction); } } diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/StopHoldingItemIfNoLongerAdmiringMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/StopHoldingItemIfNoLongerAdmiringMixin.java similarity index 88% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/StopHoldingItemIfNoLongerAdmiringMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/StopHoldingItemIfNoLongerAdmiringMixin.java index 53f2b0baf..f6611cb4d 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/StopHoldingItemIfNoLongerAdmiringMixin.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/StopHoldingItemIfNoLongerAdmiringMixin.java @@ -2,7 +2,7 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; import io.github.fabricators_of_create.porting_lib.tool.addons.ToolActionItem; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.monster.piglin.Piglin; @@ -19,7 +19,7 @@ public class StopHoldingItemIfNoLongerAdmiringMixin { private static boolean isToolActionBlocking(boolean original, ServerLevel level, Piglin piglin) { ItemStack offHand = piglin.getOffhandItem(); if (offHand.getItem() instanceof ToolActionItem) - return offHand.canPerformAction(ToolActions.SHIELD_BLOCK); + return offHand.canPerformAction(ItemAbilities.SHIELD_BLOCK); return original; } } diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/SwordItemMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/SwordItemMixin.java similarity index 57% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/SwordItemMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/SwordItemMixin.java index f44e9273f..0b83d9e43 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/SwordItemMixin.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/SwordItemMixin.java @@ -1,7 +1,7 @@ package io.github.fabricators_of_create.porting_lib.tool.mixin; -import io.github.fabricators_of_create.porting_lib.tool.ToolAction; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbility; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; import io.github.fabricators_of_create.porting_lib.tool.extensions.VanillaToolActionItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.SwordItem; @@ -11,7 +11,7 @@ @Mixin(SwordItem.class) public class SwordItemMixin implements VanillaToolActionItem { @Override - public boolean port_lib$canPerformAction(ItemStack stack, ToolAction toolAction) { - return ToolActions.DEFAULT_SWORD_ACTIONS.contains(toolAction); + public boolean port_lib$canPerformAction(ItemStack stack, ItemAbility toolAction) { + return ItemAbilities.DEFAULT_SWORD_ACTIONS.contains(toolAction); } } diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/TripWireBlockMixin.java b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/TripWireBlockMixin.java similarity index 81% rename from modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/TripWireBlockMixin.java rename to modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/TripWireBlockMixin.java index 880003ff9..7e2d52ea5 100644 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/TripWireBlockMixin.java +++ b/modules/item_abilities/src/main/java/io/github/fabricators_of_create/porting_lib/tool/mixin/TripWireBlockMixin.java @@ -2,17 +2,15 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; +import io.github.fabricators_of_create.porting_lib.tool.ItemAbilities; import io.github.fabricators_of_create.porting_lib.tool.addons.ToolActionItem; import net.minecraft.core.BlockPos; -import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.TripWireBlock; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.BlockHitResult; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -23,7 +21,7 @@ public class TripWireBlockMixin { private boolean supportsToolAction(boolean original, Level world, BlockPos pos, BlockState state, Player player) { ItemStack stack = player.getMainHandItem(); if (stack.getItem() instanceof ToolActionItem toolActionItem) - return toolActionItem.canPerformAction(stack, ToolActions.SHEARS_DISARM); + return toolActionItem.canPerformAction(stack, ItemAbilities.SHEARS_DISARM); return original; } } diff --git a/modules/tool_actions/src/main/resources/fabric.mod.json b/modules/item_abilities/src/main/resources/fabric.mod.json similarity index 96% rename from modules/tool_actions/src/main/resources/fabric.mod.json rename to modules/item_abilities/src/main/resources/fabric.mod.json index cd6bb18ae..a4d1493be 100644 --- a/modules/tool_actions/src/main/resources/fabric.mod.json +++ b/modules/item_abilities/src/main/resources/fabric.mod.json @@ -6,7 +6,7 @@ "description": "Utilities for tool interactions.", "entrypoints": { "main": [ - "io.github.fabricators_of_create.porting_lib.tool.loot.CanToolPerformAction::init" + "io.github.fabricators_of_create.porting_lib.tool.loot.CanItemPerformAbility::init" ], "fabric-datagen": [ "io.github.fabricators_of_create.porting_lib.tool.data.ToolActionsData" diff --git a/modules/tool_actions/src/main/resources/porting_lib_tool_actions.accesswidener b/modules/item_abilities/src/main/resources/porting_lib_tool_actions.accesswidener similarity index 100% rename from modules/tool_actions/src/main/resources/porting_lib_tool_actions.accesswidener rename to modules/item_abilities/src/main/resources/porting_lib_tool_actions.accesswidener diff --git a/modules/tool_actions/src/main/resources/porting_lib_tool_actions.mixins.json b/modules/item_abilities/src/main/resources/porting_lib_tool_actions.mixins.json similarity index 100% rename from modules/tool_actions/src/main/resources/porting_lib_tool_actions.mixins.json rename to modules/item_abilities/src/main/resources/porting_lib_tool_actions.mixins.json diff --git a/modules/loot/src/main/java/io/github/fabricators_of_create/porting_lib/loot/PortingLibLoot.java b/modules/loot/src/main/java/io/github/fabricators_of_create/porting_lib/loot/PortingLibLoot.java index 2564001b5..4a66a7188 100644 --- a/modules/loot/src/main/java/io/github/fabricators_of_create/porting_lib/loot/PortingLibLoot.java +++ b/modules/loot/src/main/java/io/github/fabricators_of_create/porting_lib/loot/PortingLibLoot.java @@ -86,10 +86,4 @@ public static ObjectArrayList modifyLoot(ResourceLocation lootTableId } return generatedLoot; } - - public static int getLootingLevel(Entity target, @Nullable Entity killer, @Nullable DamageSource cause) { - if (killer instanceof LivingEntity) - return EnchantmentHelper.getMobLooting((LivingEntity)killer); - return 0; - } } diff --git a/modules/loot/src/main/java/io/github/fabricators_of_create/porting_lib/loot/extensions/LootContextExtensions.java b/modules/loot/src/main/java/io/github/fabricators_of_create/porting_lib/loot/extensions/LootContextExtensions.java index 560a01770..49534459b 100644 --- a/modules/loot/src/main/java/io/github/fabricators_of_create/porting_lib/loot/extensions/LootContextExtensions.java +++ b/modules/loot/src/main/java/io/github/fabricators_of_create/porting_lib/loot/extensions/LootContextExtensions.java @@ -3,10 +3,6 @@ import net.minecraft.resources.ResourceLocation; public interface LootContextExtensions { - default int getLootingModifier() { - throw new RuntimeException("this should be overridden via mixin. what?"); - } - default void setQueriedLootTableId(ResourceLocation queriedLootTableId) { throw new RuntimeException("this should be overridden via mixin. what?"); } diff --git a/modules/loot/src/main/java/io/github/fabricators_of_create/porting_lib/loot/mixin/LootContextMixin.java b/modules/loot/src/main/java/io/github/fabricators_of_create/porting_lib/loot/mixin/LootContextMixin.java index 2df30c2ea..2c285b948 100644 --- a/modules/loot/src/main/java/io/github/fabricators_of_create/porting_lib/loot/mixin/LootContextMixin.java +++ b/modules/loot/src/main/java/io/github/fabricators_of_create/porting_lib/loot/mixin/LootContextMixin.java @@ -33,9 +33,4 @@ public void setQueriedLootTableId(ResourceLocation queriedLootTableId) { public ResourceLocation getQueriedLootTableId() { return this.queriedLootTableId == null ? LootTableIdCondition.UNKNOWN_LOOT_TABLE : this.queriedLootTableId; } - - @Override - public int getLootingModifier() { - return PortingLibLoot.getLootingLevel(getParamOrNull(LootContextParams.THIS_ENTITY), getParamOrNull(LootContextParams.KILLER_ENTITY), getParamOrNull(LootContextParams.DAMAGE_SOURCE)); - } } diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/ToolAction.java b/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/ToolAction.java deleted file mode 100644 index 8307f82aa..000000000 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/ToolAction.java +++ /dev/null @@ -1,47 +0,0 @@ -package io.github.fabricators_of_create.porting_lib.tool; - -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -@SuppressWarnings("ClassCanBeRecord") -public class ToolAction { - private static final Map actions = new ConcurrentHashMap<>(); - private final String name; - - /** - * Use {@link #get(String)} to get or create a ToolAction - */ - private ToolAction(String name) { - this.name = name; - } - - /** - * Returns all registered actions. - * This collection can be kept around, and will update itself in response to changes to the map. - * See {@link ConcurrentHashMap#values()} for details. - */ - public static Collection getActions() { - return Collections.unmodifiableCollection(actions.values()); - } - - /** - * Gets or creates a new ToolAction for the given name. - */ - public static ToolAction get(String name) { - return actions.computeIfAbsent(name, ToolAction::new); - } - - /** - * Returns the name of this tool action - */ - public String name() { - return name; - } - - @Override - public String toString() { - return "ToolAction[" + name + "]"; - } -} diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/ToolActions.java b/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/ToolActions.java deleted file mode 100644 index eae40ad7e..000000000 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/ToolActions.java +++ /dev/null @@ -1,115 +0,0 @@ -package io.github.fabricators_of_create.porting_lib.tool; - -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import com.google.common.collect.Sets; - -import io.github.fabricators_of_create.porting_lib.tool.extensions.BlockExtensions; - -public class ToolActions { - /** - * Exposed by axes to allow querying tool behaviours - */ - public static final ToolAction AXE_DIG = ToolAction.get("axe_dig"); - - /** - * Exposed by pickaxes to allow querying tool behaviours - */ - public static final ToolAction PICKAXE_DIG = ToolAction.get("pickaxe_dig"); - - /** - * Exposed by shovels to allow querying tool behaviours - */ - public static final ToolAction SHOVEL_DIG = ToolAction.get("shovel_dig"); - - /** - * Exposed by shovels to allow querying tool behaviours - */ - public static final ToolAction HOE_DIG = ToolAction.get("hoe_dig"); - - /** - * Exposed by swords to allow querying tool behaviours - */ - 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 BlockExtensions#getToolModifiedState} when an axe wants to strip a log - */ - public static final ToolAction AXE_STRIP = ToolAction.get("axe_strip"); - - /** - * Passed onto {@link BlockExtensions#getToolModifiedState} when an axe wants to scrape oxidization off copper - */ - public static final ToolAction AXE_SCRAPE = ToolAction.get("axe_scrape"); - - /** - * Passed onto {@link BlockExtensions#getToolModifiedState} when an axe wants to remove wax out of copper - */ - public static final ToolAction AXE_WAX_OFF = ToolAction.get("axe_wax_off"); - - /** - * Passed onto {@link BlockExtensions#getToolModifiedState} when a shovel wants to turn dirt into path - */ - public static final ToolAction SHOVEL_FLATTEN = ToolAction.get("shovel_flatten"); - - /** - * Used during player attack to figure out if a sweep attack should be performed - * - * @see 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 BlockExtensions#getToolModifiedState} when a hoe wants to turn dirt into soil - */ - public static final ToolAction HOE_TILL = ToolAction.get("till"); - - /** - * A tool action corresponding to the 'block' action of shields. - */ - public static final ToolAction SHIELD_BLOCK = ToolAction.get("shield_block"); - - /** - * This action corresponds to right-clicking the fishing rod. - */ - public static final ToolAction FISHING_ROD_CAST = ToolAction.get("fishing_rod_cast"); - - // Default actions supported by each tool type - 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, 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); - public static final Set DEFAULT_SHIELD_ACTIONS = of(SHIELD_BLOCK); - public static final Set DEFAULT_FISHING_ROD_ACTIONS = of(FISHING_ROD_CAST); - - private static Set of(ToolAction... actions) { - return Stream.of(actions).collect(Collectors.toCollection(Sets::newIdentityHashSet)); - } -} diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/BlockExtensions.java b/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/BlockExtensions.java deleted file mode 100644 index 5b005f6eb..000000000 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/BlockExtensions.java +++ /dev/null @@ -1,88 +0,0 @@ -package io.github.fabricators_of_create.porting_lib.tool.extensions; - -import io.github.fabricators_of_create.porting_lib.tool.ToolAction; -import io.github.fabricators_of_create.porting_lib.tool.ToolActions; -import net.minecraft.core.BlockPos; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.AxeItem; -import net.minecraft.world.item.HoneycombItem; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.Items; -import net.minecraft.world.item.ShovelItem; -import net.minecraft.world.item.context.UseOnContext; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.WeatheringCopper; -import net.minecraft.world.level.block.state.BlockState; - -import org.jetbrains.annotations.Nullable; - -import java.util.Optional; - -// TODO: Re-evaluate how to make this work -@Deprecated(forRemoval = true) -public interface BlockExtensions { - /** - * Returns the state that this block should transform into when right-clicked by a tool. - * For example: Used to determine if {@link ToolActions#AXE_STRIP an axe can strip}, - * {@link ToolActions#SHOVEL_FLATTEN a shovel can path}, or {@link ToolActions#HOE_TILL a hoe can till}. - * Returns {@code null} if nothing should happen. - * - * @param state The current state - * @param context The use on context that the action was performed in - * @param toolAction The action being performed by the tool - * @param simulate If {@code true}, no actions that modify the world in any way should be performed. If {@code false}, the world may be modified. - * @return The resulting state after the action has been performed - */ - @Nullable - default BlockState getToolModifiedState(BlockState state, UseOnContext context, ToolAction toolAction, boolean simulate) { - BlockState toolModifiedState = getToolModifiedState(state, context.getLevel(), context.getClickedPos(), - context.getPlayer(), context.getItemInHand(), toolAction); - - if (toolModifiedState == null && ToolActions.HOE_TILL == toolAction && context.getItemInHand().canPerformAction(ToolActions.HOE_TILL)) { - // Logic copied from HoeItem#TILLABLES; needs to be kept in sync during updating - Block block = state.getBlock(); - if (block == Blocks.ROOTED_DIRT) { - if (!simulate && !context.getLevel().isClientSide) { - Block.popResourceFromFace(context.getLevel(), context.getClickedPos(), context.getClickedFace(), new ItemStack(Items.HANGING_ROOTS)); - } - return Blocks.DIRT.defaultBlockState(); - } else if ((block == Blocks.GRASS_BLOCK || block == Blocks.DIRT_PATH || block == Blocks.DIRT || block == Blocks.COARSE_DIRT) && - context.getLevel().getBlockState(context.getClickedPos().above()).isAir()) { - return block == Blocks.COARSE_DIRT ? Blocks.DIRT.defaultBlockState() : Blocks.FARMLAND.defaultBlockState(); - } - } - - return toolModifiedState; - } - - /** - * Returns the state that this block should transform into when right clicked by a tool. - * For example: Used to determine if an axe can strip, a shovel can path, or a hoe can till. - * Return null if vanilla behavior should be disabled. - * - * @param state The current state - * @param world The world - * @param pos The block position in world - * @param player The player clicking the block - * @param stack The stack being used by the player - * @param toolAction The action being performed by the tool - * @return The resulting state after the action has been performed - */ - @Nullable - default BlockState getToolModifiedState(BlockState state, Level world, BlockPos pos, Player player, ItemStack stack, ToolAction toolAction) { - if (!stack.canPerformAction(toolAction)) return null; - if (ToolActions.AXE_STRIP.equals(toolAction)) { - Block block = AxeItem.STRIPPABLES.get(state.getBlock()); - return block != null ? block.defaultBlockState() : null; - } - else if(ToolActions.AXE_SCRAPE.equals(toolAction)) return WeatheringCopper.getPrevious(state).orElse(null); - else if(ToolActions.AXE_WAX_OFF.equals(toolAction)) return Optional.ofNullable(HoneycombItem.WAX_OFF_BY_BLOCK.get().get(state.getBlock())).map((p_150694_) -> { - return p_150694_.withPropertiesOf(state); - }).orElse(null); - //else if(ToolActions.HOE_TILL.equals(toolAction)) return HoeItem.getHoeTillingState(state); //TODO HoeItem bork - else if (ToolActions.SHOVEL_FLATTEN.equals(toolAction)) return ShovelItem.FLATTENABLES.get(state.getBlock()); - return null; - } -} diff --git a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/ItemStackExtensions.java b/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/ItemStackExtensions.java deleted file mode 100644 index 0af500e3d..000000000 --- a/modules/tool_actions/src/main/java/io/github/fabricators_of_create/porting_lib/tool/extensions/ItemStackExtensions.java +++ /dev/null @@ -1,9 +0,0 @@ -package io.github.fabricators_of_create.porting_lib.tool.extensions; - -import io.github.fabricators_of_create.porting_lib.tool.ToolAction; - -public interface ItemStackExtensions { - default boolean canPerformAction(ToolAction toolAction) { - throw new RuntimeException("this should be overridden via mixin. what?"); - } -}