Class AbstractEffectToolCustomizer

java.lang.Object
net.xun.armory.api.item.tools.AbstractEffectToolCustomizer
All Implemented Interfaces:
ToolCustomizer

public abstract class AbstractEffectToolCustomizer extends Object implements ToolCustomizer
Abstract base class for tool customizers that apply hit effects depending on the tool type.

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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    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.
    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.
    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.
    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.
    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.
    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.
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 call onHit(ToolType, boolean, LivingEntity, LivingEntity) and apply the hit effect if the attack succeeds.

      Specified by:
      createTool in interface ToolCustomizer
      Parameters:
      type - the type of tool to create (SWORD, AXE, PICKAXE, HOE, SHOVEL)
      tier - the material tier of the tool
      properties - 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 hit
      target - the entity that was hit
      attacker - 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 overridden hurtEnemy methods of the created tools.

      Parameters:
      toolType - the type of tool used
      flag - the result of the original hurtEnemy call (true if the target was damaged)
      target - the entity that was hit
      attacker - the entity that performed the attack
      Returns:
      the same flag value, allowing chaining in hurtEnemy
    • 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 tier
      properties - the item properties
      Returns:
      a new SwordItem with 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 tier
      properties - the item properties
      Returns:
      a new AxeItem with 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 tier
      properties - the item properties
      Returns:
      a new AxeItem with 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 tier
      properties - the item properties
      Returns:
      a new AxeItem with 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 tier
      properties - the item properties
      Returns:
      a new AxeItem with hit effect support