Interface TradeOfferGenerator
-
- All Superinterfaces:
java.util.function.BiFunction<Entity,java.util.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 java.util.function.BiFunction<Entity,java.util.Random,TradeOffer>
Represents a generator to createTradeOffer
s with a bit of randomization based onItemStackGenerator
s for populatingItemStack
s and finally generating aTradeOffer
.Can be directly implemented as a lambda as follows:
final 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() );
random
instance 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
Random
must be provided as part of theBiFunction
signature is that during multiple world instances, there's differentRandom
instances 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 generatedTradeOffer
versus creating a static non-changing offer. Normally, the vanillaTradeOffer
s are using a similar generator with limited scopes of what theItemStack
can be customized as.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
TradeOfferGenerator.Builder
A simple builder to create aTradeOfferGenerator
.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description TradeOffer
apply(Entity entity, java.util.Random random)
static TradeOfferGenerator.Builder
builder()
Gets a newTradeOfferGenerator.Builder
to create a newTradeOfferGenerator
.
-
-
-
Method Detail
-
builder
static TradeOfferGenerator.Builder builder()
Gets a newTradeOfferGenerator.Builder
to create a newTradeOfferGenerator
.- Returns:
- The new builder
-
apply
TradeOffer apply(Entity entity, java.util.Random random)
- Specified by:
apply
in interfacejava.util.function.BiFunction<Entity,java.util.Random,TradeOffer>
-
-