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
Fired when either anvil input slot or item name is changed, provided that the left input slot holds an item (checked after the change).
Called from AnvilMenu.createResult().
If the event is canceled, vanilla logic is skipped and the output is set to ItemStack.EMPTY.
If not canceled and output is non-empty, the provided stack is used and vanilla logic is skipped.
If not canceled and output is empty, vanilla behavior proceeds as normal.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private long
     
    private final net.minecraft.world.item.ItemStack
     
    private int
     
    private final String
     
    private net.minecraft.world.item.ItemStack
     
    private final net.minecraft.world.entity.player.Player
     
    private final net.minecraft.world.item.ItemStack
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    AnvilUpdateEvent(net.minecraft.world.item.ItemStack left, net.minecraft.world.item.ItemStack right, String name, long cost, net.minecraft.world.entity.player.Player player)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    This is the level cost of this anvil operation.
    net.minecraft.world.item.ItemStack
     
    int
    The material cost is how many units of the right input stack are consumed.
    @Nullable String
    This is the name as sent by the client.
    net.minecraft.world.item.ItemStack
    This is the output as determined by the event, not by the vanilla behavior between these two items.
    net.minecraft.world.entity.player.Player
     
    net.minecraft.world.item.ItemStack
     
    void
    setCost(long cost)
    Changes the level cost of this operation.
    void
    setMaterialCost(int materialCost)
    Sets how many right inputs are consumed.
    void
    setOutput(net.minecraft.world.item.ItemStack output)
    Sets the output slot to a specific itemstack.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface net.neoforged.bus.api.ICancellableEvent

    isCanceled, setCanceled
  • Field Details

    • left

      private final net.minecraft.world.item.ItemStack left
    • name

      private final String name
    • output

      private net.minecraft.world.item.ItemStack output
    • cost

      private long cost
    • materialCost

      private int materialCost
    • player

      private final net.minecraft.world.entity.player.Player player
  • Constructor Details

    • AnvilUpdateEvent

      public AnvilUpdateEvent(net.minecraft.world.item.ItemStack left, net.minecraft.world.item.ItemStack right, String name, long cost, net.minecraft.world.entity.player.Player player)
  • Method Details

    • getLeft

      public net.minecraft.world.item.ItemStack getLeft()
      Returns:
      The item in the left input (leftmost) anvil slot.
    • getRight

      public net.minecraft.world.item.ItemStack getRight()
      Returns:
      The item in the right input (center) anvil 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.
      Returns:
      The name that the output item will be set to, if applicable.
    • getOutput

      public net.minecraft.world.item.ItemStack getOutput()
      This is the output as determined by the event, not by the vanilla behavior between these two items.
      If you are the first receiver of this event, it is guaranteed to be empty.
      It will only be non-empty if changed by an event handler.
      If this event is cancelled, this output stack is discarded.
      Returns:
      The item to set in the output (rightmost) anvil slot.
    • setOutput

      public void setOutput(net.minecraft.world.item.ItemStack output)
      Sets the output slot to a specific itemstack.
      Parameters:
      output - The stack to change the output to.
    • getCost

      public long getCost()
      This is the level cost of this anvil operation.
      When unchanged, it is guaranteed to be left.getRepairCost() + right.getRepairCost().
      Returns:
      The level cost of this anvil operation.
    • setCost

      public void setCost(long cost)
      Changes the level cost of this operation.
      The level cost does prevent the output from being available.
      That is, a player without enough experience may not take the output.

      Values will be clamped to the range 0 - MAX_INT.

      Parameters:
      cost - The new level cost.
    • getMaterialCost

      public int getMaterialCost()
      The material cost is how many units of the right input stack are consumed.
      Returns:
      The material cost of this anvil operation.
    • setMaterialCost

      public void setMaterialCost(int materialCost)
      Sets how many right inputs are consumed.
      A material cost of zero consumes the entire stack.
      A material cost higher than the count of the right stack consumes the entire stack.
      The material cost does not prevent the output from being available.
      Parameters:
      materialCost - The new material cost.
    • getPlayer

      public net.minecraft.world.entity.player.Player getPlayer()
      Returns:
      The player using this anvil container.