Contents
Class WeightedTrade
java.lang.Object
com.hypixel.hytale.builtin.adventure.shop.barter.WeightedTrade
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final BuilderCodec<WeightedTrade> static final WeightedTrade[] -
Constructor Summary
ConstructorsConstructorDescriptionWeightedTrade(double weight, BarterItemStack output, BarterItemStack[] input, int stock) WeightedTrade(double weight, BarterItemStack output, BarterItemStack[] input, int stockMin, int stockMax) -
Method Summary
Modifier and TypeMethodDescriptiongetInput()intGet the maximum stock (or fixed stock if not a range).intGet the minimum stock (or fixed stock if not a range).int[]Get the stock range.doublebooleanCheck if this trade has randomized stock.intresolveStock(Random random) Resolve the stock to a concrete value.Deprecated.toBarterTrade(Random random) Convert this weighted trade to a concrete BarterTrade with resolved stock.toString()
-
Field Details
-
CODEC
-
EMPTY_ARRAY
-
-
Constructor Details
-
WeightedTrade
public WeightedTrade(double weight, @Nonnull BarterItemStack output, @Nonnull BarterItemStack[] input, int stock) -
WeightedTrade
public WeightedTrade(double weight, @Nonnull BarterItemStack output, @Nonnull BarterItemStack[] input, int stockMin, int stockMax)
-
-
Method Details
-
getWeight
public double getWeight()- Specified by:
getWeightin interfaceIWeightedElement
-
getOutput
-
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
Resolve the stock to a concrete value.- Parameters:
random- Random source for range resolution- Returns:
- The resolved stock value
-
toBarterTrade
Convert this weighted trade to a concrete BarterTrade with resolved stock.- Parameters:
random- Random source for stock range resolution
-
toBarterTrade
Deprecated.UsetoBarterTrade(Random)for proper range supportConvert this weighted trade to a concrete BarterTrade using minimum stock. -
toString
-
toBarterTrade(Random)for proper range support