use of org.spongepowered.api.item.merchant.TradeOffer in project SpongeCommon by SpongePowered.
the class IMixinEntityVillager$ITradeList method accept.
@Override
default void accept(Merchant owner, List<TradeOffer> tradeOffers, Random random) {
MerchantRecipeList tempList = new MerchantRecipeList();
for (TradeOffer offer : tradeOffers) {
tempList.add(TradeOfferUtil.toNative(offer));
}
addMerchantRecipe((IMerchant) owner, tempList, random);
tradeOffers.clear();
for (MerchantRecipe recipe : tempList) {
tradeOffers.add(TradeOfferUtil.fromNative(recipe));
}
}
use of org.spongepowered.api.item.merchant.TradeOffer in project SpongeCommon by SpongePowered.
the class MixinEntityVillagerEmeraldForItems method apply.
@Override
public TradeOffer apply(Random random) {
checkNotNull(random, "Random cannot be null!");
int buyingCount = 1;
if (this.price != null) {
buyingCount = this.price.getPrice(random);
}
final ItemStack buyingItem = new ItemStack(this.buyingItem, buyingCount, 0);
return (TradeOffer) new MerchantRecipe(buyingItem, Items.EMERALD);
}
use of org.spongepowered.api.item.merchant.TradeOffer in project SpongeCommon by SpongePowered.
the class MixinEntityVillagerListEnchantedBookForEmeralds method apply.
@Override
public TradeOffer apply(Random random) {
checkNotNull(random, "Random cannot be null!");
Enchantment enchantment = Enchantment.REGISTRY.getRandomObject(random);
int enchantmentLevel = MathHelper.getInt(random, enchantment.getMinLevel(), enchantment.getMaxLevel());
ItemStack itemstack = ItemEnchantedBook.getEnchantedItemStack(new EnchantmentData(enchantment, enchantmentLevel));
int emeraldCount = 2 + random.nextInt(5 + enchantmentLevel * 10) + 3 * enchantmentLevel;
if (enchantment.isTreasureEnchantment()) {
emeraldCount *= 2;
}
if (emeraldCount > 64) {
emeraldCount = 64;
}
return (TradeOffer) new MerchantRecipe(new ItemStack(Items.BOOK), new ItemStack(Items.EMERALD, emeraldCount), itemstack);
}
use of org.spongepowered.api.item.merchant.TradeOffer in project SpongeCommon by SpongePowered.
the class MixinEntityVillagerListEnchantedItemForEmeralds method apply.
@Override
public TradeOffer apply(Random random) {
checkNotNull(random, "Random cannot be null!");
int emeraldCount = 1;
if (this.priceInfo != null) {
emeraldCount = this.priceInfo.getPrice(random);
}
ItemStack itemstack = new ItemStack(Items.EMERALD, emeraldCount, 0);
ItemStack itemstack1 = new ItemStack(this.enchantedItemStack.getItem(), 1, this.enchantedItemStack.getMetadata());
itemstack1 = EnchantmentHelper.addRandomEnchantment(random, itemstack1, 5 + random.nextInt(15), false);
return (TradeOffer) new MerchantRecipe(itemstack, itemstack1);
}
use of org.spongepowered.api.item.merchant.TradeOffer in project SpongeCommon by SpongePowered.
the class SpongeTradeOfferBuilder method build.
@SuppressWarnings("ConstantConditions")
@Override
public TradeOffer build() throws IllegalStateException {
checkState(this.firstItem != null, "Trading item has not been set");
checkState(this.sellingItem != null, "Selling item has not been set");
checkState(this.useCount <= this.maxUses, "Usage count cannot be greater than the max usage count (%s)", this.maxUses);
final ItemStack first = this.firstItem.createStack();
final ItemStack second = this.secondItem == null ? null : this.secondItem.createStack();
final ItemStack selling = this.sellingItem.createStack();
final MerchantOffer merchantOffer = new MerchantOffer(ItemStackUtil.toNative(first), ItemStackUtil.toNative(second), ItemStackUtil.toNative(selling), this.useCount, this.maxUses, this.merchantExperienceGranted, (float) this.priceGrowthMultiplier);
((MerchantOfferAccessor) merchantOffer).accessor$rewardExp(this.allowsExperience);
((MerchantOfferAccessor) merchantOffer).accessor$demand(this.demandBonus);
return (TradeOffer) merchantOffer;
}
Aggregations