Search in sources :

Example 6 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 7 with TradeOffer

use of org.spongepowered.api.item.merchant.TradeOffer in project SpongeCommon by SpongePowered.

the class MixinEntityVillager method populateBuyingList.

/**
 * @author gabizou - January 13th, 2016
 * @reason This overwrites the current method using the multi-dimension array with
 * our {@link VillagerRegistry} to handle career levels and registrations
 * for {@link TradeOfferGenerator}s. Note that this takes over entirely
 * whatever vanilla does, but this allows for maximum customization for
 * plugins to handle gracefully.
 */
@SuppressWarnings("unchecked")
@Overwrite
public void populateBuyingList() {
    // populateBuyingList
    // Sponge
    List<Career> careers = (List<Career>) this.profession.getCareers();
    if (this.careerId != 0 && this.careerLevel != 0) {
        ++this.careerLevel;
    } else {
        // Sponge change aentityvillager$itradelist to use this.profession.getCareers()
        this.careerId = this.rand.nextInt(careers.size()) + 1;
        this.careerLevel = 1;
    }
    if (this.buyingList == null) {
        this.buyingList = new MerchantRecipeList();
    }
    // Sponge start - use our own registry stuffs
    checkState(this.careerId <= careers.size(), "The villager career id is out of bounds fo the available Careers! Found: " + this.careerId + " when the current maximum is: " + careers.size());
    final Career careerLevel = careers.get(this.careerId - 1);
    SpongeVillagerRegistry.getInstance().populateOffers(this, (List<TradeOffer>) (List<?>) this.buyingList, careerLevel, this.careerLevel, this.rand);
// Sponge end
}
Also used : MerchantRecipeList(net.minecraft.village.MerchantRecipeList) MerchantRecipeList(net.minecraft.village.MerchantRecipeList) List(java.util.List) Career(org.spongepowered.api.data.type.Career) SpongeCareer(org.spongepowered.common.entity.SpongeCareer) TradeOffer(org.spongepowered.api.item.merchant.TradeOffer) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 8 with TradeOffer

use of org.spongepowered.api.item.merchant.TradeOffer in project SpongeCommon by SpongePowered.

the class MixinEntityVillagerItemAndEmeraldToItem method apply.

@Override
public TradeOffer apply(Random random) {
    checkNotNull(random, "Random cannot be null!");
    int buyingCount = 1;
    if (this.buyingPriceInfo != null) {
        buyingCount = this.buyingPriceInfo.getPrice(random);
    }
    int sellingCount = 1;
    if (this.sellingPriceInfo != null) {
        sellingCount = this.sellingPriceInfo.getPrice(random);
    }
    final ItemStack itemStackBuying = new ItemStack(this.buyingItemStack.getItem(), buyingCount, this.buyingItemStack.getMetadata());
    final ItemStack emeraldStack = new ItemStack(Items.EMERALD);
    final ItemStack itemStackSelling = new ItemStack(this.sellingItemstack.getItem(), sellingCount, this.sellingItemstack.getMetadata());
    return (TradeOffer) new MerchantRecipe(itemStackBuying, emeraldStack, itemStackSelling);
}
Also used : MerchantRecipe(net.minecraft.village.MerchantRecipe) ItemStack(net.minecraft.item.ItemStack) TradeOffer(org.spongepowered.api.item.merchant.TradeOffer)

Example 9 with TradeOffer

use of org.spongepowered.api.item.merchant.TradeOffer in project SpongeCommon by SpongePowered.

the class MixinEntityVillagerListItemForEmeralds method apply.

@Override
public TradeOffer apply(Random random) {
    checkNotNull(random, "Random cannot be null!");
    int amount = 1;
    if (this.priceInfo != null) {
        amount = this.priceInfo.getPrice(random);
    }
    ItemStack itemstack;
    ItemStack itemstack1;
    if (amount < 0) {
        itemstack = new ItemStack(Items.EMERALD, 1, 0);
        itemstack1 = new ItemStack(this.itemToBuy.getItem(), -amount, this.itemToBuy.getMetadata());
    } else {
        itemstack = new ItemStack(Items.EMERALD, amount, 0);
        itemstack1 = new ItemStack(this.itemToBuy.getItem(), 1, this.itemToBuy.getMetadata());
    }
    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)

Aggregations

TradeOffer (org.spongepowered.api.item.merchant.TradeOffer)9 MerchantRecipe (net.minecraft.village.MerchantRecipe)7 ItemStack (net.minecraft.item.ItemStack)5 MerchantRecipeList (net.minecraft.village.MerchantRecipeList)2 ItemStack (org.spongepowered.api.item.inventory.ItemStack)2 List (java.util.List)1 Enchantment (net.minecraft.enchantment.Enchantment)1 EnchantmentData (net.minecraft.enchantment.EnchantmentData)1 Career (org.spongepowered.api.data.type.Career)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1 SpongeCareer (org.spongepowered.common.entity.SpongeCareer)1