Class AnvilUpdateEvent


  • public class AnvilUpdateEvent
    extends net.minecraftforge.eventbus.api.Event
    AnvilUpdateEvent is fired when the inputs (either input stack, or the name) to an anvil are changed.
    It is called from RepairContainer#updateRepairOutput.
    If the event is canceled, vanilla behavior will not run, and the output will be set to ItemStack.EMPTY.
    If the event is not canceled, but the output is not empty, it will set the output and not run vanilla behavior.
    if the output is empty, and the event is not canceled, vanilla behavior will execute.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class net.minecraftforge.eventbus.api.Event

        net.minecraftforge.eventbus.api.Event.HasResult, net.minecraftforge.eventbus.api.Event.Result
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getCost()
      This is the level cost of this anvil operation.
      ItemStack getLeft()  
      int getMaterialCost()
      The material cost is how many units of the right input stack are consumed.
      java.lang.String getName()
      This is the name as sent by the client.
      ItemStack getOutput()
      This is the output as determined by the event, not by the vanilla behavior between these two items.
      PlayerEntity getPlayer()
      Nullable in the case someone is using the deprecated constructor.
      ItemStack getRight()  
      void setCost​(int cost)
      Changes the level cost of this operation.
      void setMaterialCost​(int materialCost)
      Sets how many right inputs are consumed.
      void setOutput​(ItemStack output)
      Sets the output slot to a specific itemstack.
      • Methods inherited from class net.minecraftforge.eventbus.api.Event

        getListenerList, getParentListenerList, getPhase, getResult, hasResult, isCancelable, isCanceled, setCanceled, setPhase, setResult, setup
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • name

        private final java.lang.String name
      • cost

        private int cost
      • materialCost

        private int materialCost
    • Constructor Detail

      • AnvilUpdateEvent

        @Deprecated
        public AnvilUpdateEvent​(ItemStack left,
                                ItemStack right,
                                java.lang.String name,
                                int cost)
        Deprecated.
    • Method Detail

      • getLeft

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

        public ItemStack getRight()
        Returns:
        The item in the right input (center) anvil slot.
      • getName

        @Nullable
        public java.lang.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 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​(ItemStack output)
        Sets the output slot to a specific itemstack.
        Parameters:
        output - The stack to change the output to.
      • getCost

        public int 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​(int 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.
        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

        @Nullable
        public PlayerEntity getPlayer()
        Nullable in the case someone is using the deprecated constructor.
        Returns:
        The player using this anvil container.