Class WeightedTrade

java.lang.Object
com.hypixel.hytale.builtin.adventure.shop.barter.WeightedTrade
All Implemented Interfaces:
IWeightedElement

public class WeightedTrade extends Object implements IWeightedElement
A trade with an associated weight for random selection. Used in PoolTradeSlot for weighted random trade selection.

JSON format (fixed stock):

{
  "Weight": 50,
  "Output": { "ItemId": "...", "Quantity": 1 },
  "Input": [{ "ItemId": "...", "Quantity": 1 }],
  "Stock": 10
}
JSON format (randomized stock):
{
  "Weight": 50,
  "Output": { "ItemId": "...", "Quantity": 1 },
  "Input": [{ "ItemId": "...", "Quantity": 1 }],
  "Stock": [5, 15]
}
  • Field Details

  • Constructor Details

  • Method Details

    • getWeight

      public double getWeight()
      Specified by:
      getWeight in interface IWeightedElement
    • getOutput

      @Nonnull public BarterItemStack getOutput()
    • getInput

      @Nonnull public BarterItemStack[] getInput()
    • getStockRange

      @Nonnull public int[] getStockRange()
      Get the stock range.
      Returns:
      array with 1 element (fixed) or 2 elements [min, max]
    • hasStockRange

      public boolean hasStockRange()
      Check if this trade has randomized stock.
    • getStockMin

      public int getStockMin()
      Get the minimum stock (or fixed stock if not a range).
    • getStockMax

      public int getStockMax()
      Get the maximum stock (or fixed stock if not a range).
    • resolveStock

      public int resolveStock(@Nonnull Random random)
      Resolve the stock to a concrete value.
      Parameters:
      random - Random source for range resolution
      Returns:
      The resolved stock value
    • toBarterTrade

      @Nonnull public BarterTrade toBarterTrade(@Nonnull Random random)
      Convert this weighted trade to a concrete BarterTrade with resolved stock.
      Parameters:
      random - Random source for stock range resolution
    • toBarterTrade

      @Deprecated @Nonnull public BarterTrade toBarterTrade()
      Deprecated.
      Use toBarterTrade(Random) for proper range support
      Convert this weighted trade to a concrete BarterTrade using minimum stock.
    • toString

      @Nonnull public String toString()
      Overrides:
      toString in class Object