Interface TradeOfferGenerator
-
- All Superinterfaces:
BiFunction<Entity,Random,TradeOffer>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface TradeOfferGenerator extends BiFunction<Entity,Random,TradeOffer>
Represents a generator to createTradeOffers with a bit of randomization based onItemStackGenerators for populatingItemStacks and finally generating aTradeOffer.Can be directly implemented as a lambda as follows:
The by-product of a direct implementation is that you would be needing to build out functions accepting thefinal TradeOfferGenerator generator = (merchant, random) -> TradeOffer.builder() .firstBuyingItem(ItemStack.of(ItemTypes.EMERALD, 64)) .sellingItem(ItemStack.builder() .itemType(ItemTypes.DIAMOND_SWORD) .quantity(1) .add(Keys.APPLIED_ENCHANTMENTS, List.of(Enchantment.of(EnchantmentTypes.SHARPNESS, 1000))) .build() ) .merchantExperienceGranted(5) .priceGrowthMultiplier(1.3f) .maxUses(20) .build() );randominstance to add dynamism to your generatedTradeOffers. As such, a handy builder has been provided withbuilder()and the related methods exposed inItemStackGenerator.The primary use of this, and why the
Randommust be provided as part of theBiFunctionsignature is that during multiple world instances, there's differentRandominstances instantiated, and more can be provided without the necessity to change the generator. One advantage to using a generator is the ability to provide some "randomization" or "chance" on the various aspects of the generatedTradeOfferversus creating a static non-changing offer. Normally, the vanillaTradeOffers are using a similar generator with limited scopes of what theItemStackcan be customized as.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceTradeOfferGenerator.BuilderA simple builder to create aTradeOfferGenerator.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description TradeOfferapply(Entity entity, Random random)static TradeOfferGenerator.Builderbuilder()Gets a newTradeOfferGenerator.Builderto create a newTradeOfferGenerator.-
Methods inherited from interface java.util.function.BiFunction
andThen
-
-
-
-
Method Detail
-
builder
static TradeOfferGenerator.Builder builder()
Gets a newTradeOfferGenerator.Builderto create a newTradeOfferGenerator.- Returns:
- The new builder
-
apply
TradeOffer apply(Entity entity, Random random)
- Specified by:
applyin interfaceBiFunction<Entity,Random,TradeOffer>
-
-