Search in sources :

Example 1 with TradeOffer

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));
    }
}
Also used : MerchantRecipeList(net.minecraft.village.MerchantRecipeList) MerchantRecipe(net.minecraft.village.MerchantRecipe) TradeOffer(org.spongepowered.api.item.merchant.TradeOffer)

Example 2 with TradeOffer

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);
}
Also used : MerchantRecipe(net.minecraft.village.MerchantRecipe) ItemStack(net.minecraft.item.ItemStack) TradeOffer(org.spongepowered.api.item.merchant.TradeOffer)

Example 3 with TradeOffer

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);
}
Also used : MerchantRecipe(net.minecraft.village.MerchantRecipe) Enchantment(net.minecraft.enchantment.Enchantment) ItemStack(net.minecraft.item.ItemStack) EnchantmentData(net.minecraft.enchantment.EnchantmentData) TradeOffer(org.spongepowered.api.item.merchant.TradeOffer)

Example 4 with TradeOffer

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);
}
Also used : MerchantRecipe(net.minecraft.village.MerchantRecipe) ItemStack(net.minecraft.item.ItemStack) TradeOffer(org.spongepowered.api.item.merchant.TradeOffer)

Example 5 with TradeOffer

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;
}
Also used : MerchantOffer(net.minecraft.world.item.trading.MerchantOffer) ItemStack(org.spongepowered.api.item.inventory.ItemStack) MerchantOfferAccessor(org.spongepowered.common.accessor.world.item.trading.MerchantOfferAccessor) TradeOffer(org.spongepowered.api.item.merchant.TradeOffer)

Aggregations

TradeOffer (org.spongepowered.api.item.merchant.TradeOffer)10 MerchantRecipe (net.minecraft.village.MerchantRecipe)6 ItemStack (net.minecraft.item.ItemStack)5 ItemStack (org.spongepowered.api.item.inventory.ItemStack)3 MerchantRecipeList (net.minecraft.village.MerchantRecipeList)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Component (net.kyori.adventure.text.Component)1 Enchantment (net.minecraft.enchantment.Enchantment)1 EnchantmentData (net.minecraft.enchantment.EnchantmentData)1 MerchantOffer (net.minecraft.world.item.trading.MerchantOffer)1 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)1 BlockState (org.spongepowered.api.block.BlockState)1 BlockEntity (org.spongepowered.api.block.entity.BlockEntity)1 BannerPatternLayer (org.spongepowered.api.data.meta.BannerPatternLayer)1 Career (org.spongepowered.api.data.type.Career)1 WireAttachmentType (org.spongepowered.api.data.type.WireAttachmentType)1 PotionEffect (org.spongepowered.api.effect.potion.PotionEffect)1