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 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
}
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);
}
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);
}
Aggregations