Class AnvilUpdateEvent
- All Implemented Interfaces:
net.neoforged.bus.api.ICancellableEvent
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
A record packing all the vanilla result data. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetLeft()
Returns a copy of the item in the left input slot.int
Returns the material cost of the anvil operation, defaulting to the vanilla cost.@Nullable String
getName()
This is the name as sent by the client.Returns a mutable reference to the current output stack, defaulting to the vanilla output.getRight()
Returns a copy of the item in the right input slot.Returns a view of the vanilla result for the given anvil inputs.int
Returns the level cost of the anvil operation, defaulting to the vanilla cost.void
setCanceled
(boolean canceled) Cancels the event, preventing any further handling.void
setMaterialCost
(int materialCost) Sets the material cost (how many right inputs are consumed).void
Sets the output to the given item stack.void
setXpCost
(int xpCost) Sets the level cost of the anvil operation.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
-
Field Details
-
left
-
right
-
name
-
vanillaResult
-
player
-
output
-
xpCost
private int xpCost -
materialCost
private int materialCost
-
-
Constructor Details
-
AnvilUpdateEvent
-
-
Method Details
-
getLeft
Returns a copy of the item in the left input slot.- Returns:
- a copy of the item in the left input slot
-
getRight
Returns a copy of the item in the right input slot.- Returns:
- a copy of the item in the right input slot
-
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
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
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
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
- 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 interfacenet.neoforged.bus.api.ICancellableEvent
-