Skip to content

Commit

Permalink
[1.20.4] Add trident throw and brushing tool actions (#351)
Browse files Browse the repository at this point in the history
Closes #190
  • Loading branch information
TelepathicGrunt authored Dec 16, 2023
1 parent b1c7210 commit 233bd73
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
12 changes: 12 additions & 0 deletions patches/net/minecraft/world/item/BrushItem.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- a/net/minecraft/world/item/BrushItem.java
+++ b/net/minecraft/world/item/BrushItem.java
@@ -148,4 +_,9 @@
};
}
}
+
+ @Override
+ public boolean canPerformAction(ItemStack stack, net.neoforged.neoforge.common.ToolAction toolAction) {
+ return net.neoforged.neoforge.common.ToolActions.DEFAULT_BRUSH_ACTIONS.contains(toolAction);
+ }
}
12 changes: 12 additions & 0 deletions patches/net/minecraft/world/item/TridentItem.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- a/net/minecraft/world/item/TridentItem.java
+++ b/net/minecraft/world/item/TridentItem.java
@@ -151,4 +_,9 @@
public int getEnchantmentValue() {
return 1;
}
+
+ @Override
+ public boolean canPerformAction(ItemStack stack, net.neoforged.neoforge.common.ToolAction toolAction) {
+ return net.neoforged.neoforge.common.ToolActions.DEFAULT_TRIDENT_ACTIONS.contains(toolAction);
+ }
}
16 changes: 15 additions & 1 deletion src/main/java/net/neoforged/neoforge/common/ToolActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,26 @@ public class ToolActions {

/**
* A tool action corresponding to the 'block' action of shields.
* Items should expose this tool action in order to enable damage blocking when the item is being "used".
*/
public static final ToolAction SHIELD_BLOCK = ToolAction.get("shield_block");

/**
* This action corresponds to right-clicking the fishing rod.
* 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 ToolAction FISHING_ROD_CAST = ToolAction.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 ToolAction TRIDENT_THROW = ToolAction.get("trident_throw");

/**
* Exposed by brushes to allow querying tool behaviours for items that can brush Suspicious Blocks.
*/
public static final ToolAction BRUSH_BRUSH = ToolAction.get("brush_brush");

// Default actions supported by each tool type
public static final Set<ToolAction> DEFAULT_AXE_ACTIONS = of(AXE_DIG, AXE_STRIP, AXE_SCRAPE, AXE_WAX_OFF);
public static final Set<ToolAction> DEFAULT_HOE_ACTIONS = of(HOE_DIG, HOE_TILL);
Expand All @@ -112,6 +124,8 @@ public class ToolActions {
public static final Set<ToolAction> DEFAULT_SHEARS_ACTIONS = of(SHEARS_DIG, SHEARS_HARVEST, SHEARS_CARVE, SHEARS_DISARM);
public static final Set<ToolAction> DEFAULT_SHIELD_ACTIONS = of(SHIELD_BLOCK);
public static final Set<ToolAction> DEFAULT_FISHING_ROD_ACTIONS = of(FISHING_ROD_CAST);
public static final Set<ToolAction> DEFAULT_TRIDENT_ACTIONS = of(TRIDENT_THROW);
public static final Set<ToolAction> DEFAULT_BRUSH_ACTIONS = of(BRUSH_BRUSH);

private static Set<ToolAction> of(ToolAction... actions) {
return Stream.of(actions).collect(Collectors.toCollection(Sets::newIdentityHashSet));
Expand Down

0 comments on commit 233bd73

Please sign in to comment.