Search in sources :

Example 16 with MerchantRecipe

use of net.minecraft.village.MerchantRecipe 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 17 with MerchantRecipe

use of net.minecraft.village.MerchantRecipe 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)

Example 18 with MerchantRecipe

use of net.minecraft.village.MerchantRecipe in project Galacticraft by micdoodle8.

the class EntityAlienVillager method updateAITasks.

@Override
protected void updateAITasks() {
    if (--this.randomTickDivider <= 0) {
        BlockPos blockpos = new BlockPos(this);
        this.worldObj.getVillageCollection().addToVillagerPositionList(blockpos);
        this.randomTickDivider = 70 + this.rand.nextInt(50);
        this.villageObj = this.worldObj.getVillageCollection().getNearestVillage(blockpos, 32);
        if (this.villageObj == null) {
            this.detachHome();
        } else {
            BlockPos blockpos1 = this.villageObj.getCenter();
            this.setHomePosAndDistance(blockpos1, (int) ((float) this.villageObj.getVillageRadius() * 1.0F));
            if (this.isLookingForHome) {
                this.isLookingForHome = false;
                this.villageObj.setDefaultPlayerReputation(5);
            }
        }
    }
    if (!this.isTrading() && this.timeUntilReset > 0) {
        --this.timeUntilReset;
        if (this.timeUntilReset <= 0) {
            if (this.needsInitilization) {
                for (MerchantRecipe merchantrecipe : this.buyingList) {
                    if (merchantrecipe.isRecipeDisabled()) {
                        merchantrecipe.increaseMaxTradeUses(this.rand.nextInt(6) + this.rand.nextInt(6) + 2);
                    }
                }
                this.populateBuyingList();
                this.needsInitilization = false;
                if (this.villageObj != null && this.lastBuyingPlayer != null) {
                    this.worldObj.setEntityState(this, (byte) 14);
                    this.villageObj.setReputationForPlayer(this.lastBuyingPlayer, 1);
                }
            }
            this.addPotionEffect(new PotionEffect(Potion.regeneration.id, 200, 0));
        }
    }
    super.updateAITasks();
}
Also used : MerchantRecipe(net.minecraft.village.MerchantRecipe) PotionEffect(net.minecraft.potion.PotionEffect)

Example 19 with MerchantRecipe

use of net.minecraft.village.MerchantRecipe in project Railcraft by Railcraft.

the class TradeStationLogic method nextTrade.

private void nextTrade(int tradeSet) {
    List<EntityVillager> villagers = findNearbyVillagers(AREA);
    Collections.shuffle(villagers);
    EntityVillager villager;
    if (villagers.isEmpty()) {
        villager = new EntityVillager(theWorldAsserted());
    } else {
        villager = villagers.iterator().next();
    }
    MerchantRecipeList recipes = villager.getRecipes(RailcraftFakePlayer.get((WorldServer) theWorldAsserted(), getX(), getY(), getZ()));
    assert recipes != null;
    MerchantRecipe recipe = recipes.get(MiscTools.RANDOM.nextInt(recipes.size()));
    recipeSlots.setInventorySlotContents(tradeSet * 3, recipe.getItemToBuy());
    recipeSlots.setInventorySlotContents(tradeSet * 3 + 1, recipe.getSecondItemToBuy());
    recipeSlots.setInventorySlotContents(tradeSet * 3 + 2, recipe.getItemToSell());
}
Also used : MerchantRecipeList(net.minecraft.village.MerchantRecipeList) MerchantRecipe(net.minecraft.village.MerchantRecipe) EntityVillager(net.minecraft.entity.passive.EntityVillager) WorldServer(net.minecraft.world.WorldServer)

Example 20 with MerchantRecipe

use of net.minecraft.village.MerchantRecipe in project PneumaticCraft by MineMaarten.

the class VillagerHandler method manipulateTradesForVillager.

@Override
public void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeList recipeList, Random rand) {
    recipeList.addToListWithCheck(new MerchantRecipe(new ItemStack(net.minecraft.init.Items.emerald, 10 + rand.nextInt(10)), null, new ItemStack(Itemss.PCBBlueprint)));
    for (int i = 0; i < ItemAssemblyProgram.PROGRAMS_AMOUNT; i++) {
        recipeList.addToListWithCheck(new MerchantRecipe(new ItemStack(net.minecraft.init.Items.emerald, rand.nextInt(5) + 7), null, new ItemStack(Itemss.assemblyProgram, 1, i)));
    }
    recipeList.addToListWithCheck(new MerchantRecipe(new ItemStack(net.minecraft.init.Items.emerald, rand.nextInt(5) + 1), null, new ItemStack(Itemss.nukeVirus)));
    recipeList.addToListWithCheck(new MerchantRecipe(new ItemStack(net.minecraft.init.Items.emerald, rand.nextInt(5) + 1), null, new ItemStack(Itemss.stopWorm)));
}
Also used : MerchantRecipe(net.minecraft.village.MerchantRecipe) ItemStack(net.minecraft.item.ItemStack)

Aggregations

MerchantRecipe (net.minecraft.village.MerchantRecipe)21 ItemStack (net.minecraft.item.ItemStack)14 EntityVillager (net.minecraft.entity.passive.EntityVillager)7 MerchantRecipeList (net.minecraft.village.MerchantRecipeList)7 TradeOffer (org.spongepowered.api.item.merchant.TradeOffer)7 PotionEffect (net.minecraft.potion.PotionEffect)3 Enchantment (net.minecraft.enchantment.Enchantment)2 EnchantmentData (net.minecraft.enchantment.EnchantmentData)2 BlockPos (net.minecraft.util.math.BlockPos)2 WorldServer (net.minecraft.world.WorldServer)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IPneumaticRecipeRegistry (me.desht.pneumaticcraft.api.recipe.IPneumaticRecipeRegistry)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemEnchantedBook (net.minecraft.item.ItemEnchantedBook)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1 IPneumaticRecipeRegistry (pneumaticCraft.api.recipe.IPneumaticRecipeRegistry)1