Class PlayerChangeCraftingAmountEvent

java.lang.Object
net.risingworld.api.events.Event
net.risingworld.api.events.player.PlayerEvent
net.risingworld.api.events.player.ui.PlayerChangeCraftingAmountEvent

public final class PlayerChangeCraftingAmountEvent extends PlayerEvent
Called when a player changes the amount of items to craft in the crafting menu (e.g. via the plus/minus buttons or the input field). This event is not called if the amount changes because the player selects another recipe, use PlayerSelectCraftingRecipeEvent.getAmount() instead.

While the player holds a plus/minus button (or changes the amount with a gamepad), the amount is only sent to the server every 250 ms, so not every single intermediate value triggers this event. The final amount is always sent once the player releases the button. The amount is set on the client, so this event arrives with a small delay (network latency) and cannot be cancelled. If you want to prevent the player from crafting something, use the PlayerCraftItemEvent instead.
Clients only send amount changes to the server if any plugin listens for this event, so it does not cause network traffic otherwise.
See Also:

Example: Show the amount the player wants to craft
1@EventMethod
2public void onPlayerChangeCraftingAmount(PlayerChangeCraftingAmountEvent event) {
3 Crafting.Recipe recipe = event.getRecipe();
4 if (recipe == null) return;
5 event.getPlayer().showStatusMessage(event.getAmount() + "x " + recipe.name, 3);
6}
  • Method Details

    • getRecipe

      public Crafting.Recipe getRecipe()
      Gets the recipe which is currently selected in the crafting menu.
      Returns:
      the selected crafting recipe.
    • getVariant

      public int getVariant()
      Gets the currently selected variant of the recipe, or -1 if no variant is selected. See PlayerSelectCraftingRecipeEvent.getVariant() for more information.
      Returns:
      the selected variant, or -1 if no variant is selected.
    • getAmount

      public int getAmount()
      Gets the new amount of items the player wants to craft.
      Returns:
      the amount of items to craft.