Class AbstractEffectToolCustomizer
- All Implemented Interfaces:
ToolCustomizer
This class implements ToolCustomizer and provides a template for creating Minecraft
tools (sword, axe, pickaxe, hoe, shovel) that trigger a custom effect when they successfully
hit an enemy. Subclasses only need to implement handleHitEffect(ToolType, LivingEntity, LivingEntity)
to define the actual effect logic.
The hit effect is only executed on the server side and only when the attack actually
damages the target (i.e., hurtEnemy returns true).
- Since:
- 2.1.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected net.minecraft.world.item.ItemcreateAxe(net.minecraft.world.item.Tier tier, net.minecraft.world.item.Item.Properties properties) Creates an axe item that applies hit effects.protected net.minecraft.world.item.ItemcreateHoe(net.minecraft.world.item.Tier tier, net.minecraft.world.item.Item.Properties properties) Creates a hoe item that applies hit effects.protected net.minecraft.world.item.ItemcreatePickaxe(net.minecraft.world.item.Tier tier, net.minecraft.world.item.Item.Properties properties) Creates a pickaxe item that applies hit effects.protected net.minecraft.world.item.ItemcreateShovel(net.minecraft.world.item.Tier tier, net.minecraft.world.item.Item.Properties properties) Creates a shovel item that applies hit effects.protected net.minecraft.world.item.ItemcreateSword(net.minecraft.world.item.Tier tier, net.minecraft.world.item.Item.Properties properties) Creates a sword item that applies hit effects.net.minecraft.world.item.ItemcreateTool(ToolType type, net.minecraft.world.item.Tier tier, net.minecraft.world.item.Item.Properties properties) Creates a tool of the specified type with the given tier and item properties.protected abstract voidhandleHitEffect(ToolType toolType, net.minecraft.world.entity.LivingEntity target, net.minecraft.world.entity.LivingEntity attacker) Handles the hit effect for a specific tool type on the target entity.protected booleanonHit(ToolType toolType, boolean flag, net.minecraft.world.entity.LivingEntity target, net.minecraft.world.entity.LivingEntity attacker) Processes a hit from a tool, applying the hit effect if the attack succeeded and the game is not on the client side.
-
Constructor Details
-
AbstractEffectToolCustomizer
public AbstractEffectToolCustomizer()
-
-
Method Details
-
createTool
public net.minecraft.world.item.Item createTool(ToolType type, net.minecraft.world.item.Tier tier, net.minecraft.world.item.Item.Properties properties) Creates a tool of the specified type with the given tier and item properties.The returned tool overrides
Item.hurtEnemy(ItemStack, LivingEntity, LivingEntity)to callonHit(ToolType, boolean, LivingEntity, LivingEntity)and apply the hit effect if the attack succeeds.- Specified by:
createToolin interfaceToolCustomizer- Parameters:
type- the type of tool to create (SWORD, AXE, PICKAXE, HOE, SHOVEL)tier- the material tier of the toolproperties- the item properties (durability, crafting group, etc.)- Returns:
- a new tool item that applies a hit effect on successful attacks
- Throws:
IllegalArgumentException- if the tool type is not supported
-
handleHitEffect
protected abstract void handleHitEffect(ToolType toolType, net.minecraft.world.entity.LivingEntity target, net.minecraft.world.entity.LivingEntity attacker) Handles the hit effect for a specific tool type on the target entity.This method is called only on the server side and only when the attack successfully damages the target. Subclasses must implement this method to define the actual effect, such as applying potion effects, dealing additional damage, or playing sounds.
- Parameters:
toolType- the type of tool that caused the hittarget- the entity that was hitattacker- the entity that performed the attack
-
onHit
protected boolean onHit(ToolType toolType, boolean flag, net.minecraft.world.entity.LivingEntity target, net.minecraft.world.entity.LivingEntity attacker) Processes a hit from a tool, applying the hit effect if the attack succeeded and the game is not on the client side.This method delegates to
handleHitEffect(ToolType, LivingEntity, LivingEntity)when conditions are met. It is intended to be called from within the overriddenhurtEnemymethods of the created tools.- Parameters:
toolType- the type of tool usedflag- the result of the originalhurtEnemycall (true if the target was damaged)target- the entity that was hitattacker- the entity that performed the attack- Returns:
- the same
flagvalue, allowing chaining inhurtEnemy
-
createSword
protected net.minecraft.world.item.Item createSword(net.minecraft.world.item.Tier tier, net.minecraft.world.item.Item.Properties properties) Creates a sword item that applies hit effects.- Parameters:
tier- the material tierproperties- the item properties- Returns:
- a new
SwordItemwith hit effect support
-
createAxe
protected net.minecraft.world.item.Item createAxe(net.minecraft.world.item.Tier tier, net.minecraft.world.item.Item.Properties properties) Creates an axe item that applies hit effects.- Parameters:
tier- the material tierproperties- the item properties- Returns:
- a new
AxeItemwith hit effect support
-
createPickaxe
protected net.minecraft.world.item.Item createPickaxe(net.minecraft.world.item.Tier tier, net.minecraft.world.item.Item.Properties properties) Creates a pickaxe item that applies hit effects.- Parameters:
tier- the material tierproperties- the item properties- Returns:
- a new
AxeItemwith hit effect support
-
createHoe
protected net.minecraft.world.item.Item createHoe(net.minecraft.world.item.Tier tier, net.minecraft.world.item.Item.Properties properties) Creates a hoe item that applies hit effects.- Parameters:
tier- the material tierproperties- the item properties- Returns:
- a new
AxeItemwith hit effect support
-
createShovel
protected net.minecraft.world.item.Item createShovel(net.minecraft.world.item.Tier tier, net.minecraft.world.item.Item.Properties properties) Creates a shovel item that applies hit effects.- Parameters:
tier- the material tierproperties- the item properties- Returns:
- a new
AxeItemwith hit effect support
-