Class AnvilUpdateEvent

java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.AnvilUpdateEvent
All Implemented Interfaces:
net.neoforged.bus.api.ICancellableEvent

public class AnvilUpdateEvent extends net.neoforged.bus.api.Event implements net.neoforged.bus.api.ICancellableEvent
This event is fired when an anvil's left input is not empty, and any of the inputs (left, right, or name) are changed.

It is fired after the vanilla result has been computed, and allows for modification (or overriding) of the result.

This event is fired on both the logical server and logical client.

  • Field Details

  • Constructor Details

  • Method Details

    • getLeft

      public ItemStack getLeft()
      Returns a copy of the item in the left input slot.
      Returns:
      a copy of the item in the left input slot
    • getRight

      public ItemStack getRight()
      Returns a copy of the item in the right input slot.
      Returns:
      a copy of the item in the right input slot
    • getName

      @Nullable public @Nullable String getName()
      This is the name as sent by the client. It may be null if none has been sent. If empty, it indicates the user wishes to clear the custom name from the item.

      The server is unable to change the name field, as there is no S2C packet for it.

      Returns:
      The name that the output item should be set to, if applicable.
    • getVanillaResult

      public AnvilUpdateEvent.VanillaResult getVanillaResult()
      Returns a view of the vanilla result for the given anvil inputs.
      Returns:
      a view of the vanilla result for the given anvil inputs
    • getOutput

      public ItemStack getOutput()
      Returns a mutable reference to the current output stack, defaulting to the vanilla output.

      If this event is cancelled, this output is ignored.

      Returns:
      The item that will be set in the output slot.
    • setOutput

      public void setOutput(ItemStack output)
      Sets the output to the given item stack.
      Parameters:
      output - The stack to change the output to.
    • getXpCost

      public int getXpCost()
      Returns the level cost of the anvil operation, defaulting to the vanilla cost.

      If this event is cancelled, the level cost is ignored.

      Returns:
      The level cost of the anvil operation.
    • setXpCost

      public void setXpCost(int xpCost)
      Sets the level cost of the anvil operation.
      Parameters:
      cost - The new level cost.
    • getMaterialCost

      public int getMaterialCost()
      Returns the material cost of the anvil operation, defaulting to the vanilla cost.

      The material cost is how many units of the right input stack are consumed.

      Returns:
      The material cost of the anvil operation.
    • setMaterialCost

      public void setMaterialCost(int materialCost)
      Sets the material cost (how many right inputs are consumed).

      A material cost of zero consumes the entire stack (due to vanilla behavior).

      A material cost higher than the count of the right stack consumes the entire stack.

      The material cost being higher than the right item count does not prevent the output from being available.

      Parameters:
      materialCost - The new material cost.
    • getPlayer

      public Player getPlayer()
      Returns:
      The player using this anvil container.
    • setCanceled

      public void setCanceled(boolean canceled)
      Cancels the event, preventing any further handling.

      When the event is cancelled, the outputs set by this event are ignored, and the anvil will produce no output.

      Specified by:
      setCanceled in interface net.neoforged.bus.api.ICancellableEvent