Search in sources :

Example 1 with MerchantRecipe

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

the class TileTradeStation method attemptTrade.

private boolean attemptTrade(List<EntityVillager> villagers, int tradeSet) {
    ItemStack buy1 = recipeSlots.getStackInSlot(tradeSet * 3 + 0);
    ItemStack buy2 = recipeSlots.getStackInSlot(tradeSet * 3 + 1);
    ItemStack sell = recipeSlots.getStackInSlot(tradeSet * 3 + 2);
    for (EntityVillager villager : villagers) {
        MerchantRecipeList recipes = villager.getRecipes(null);
        for (MerchantRecipe recipe : recipes) {
            if (recipe.isRecipeDisabled())
                continue;
            //noinspection ConstantConditions
            if (recipe.getItemToBuy() != null && !InvTools.isItemLessThanOrEqualTo(recipe.getItemToBuy(), buy1))
                continue;
            //noinspection ConstantConditions
            if (recipe.getSecondItemToBuy() != null && !InvTools.isItemLessThanOrEqualTo(recipe.getSecondItemToBuy(), buy2))
                continue;
            if (!InvTools.isItemGreaterOrEqualThan(recipe.getItemToSell(), sell))
                continue;
            //                System.out.printf("Buying: %d %s Found: %d%n", recipe.getItemToBuy().stackSize, recipe.getItemToBuy().getDisplayName(), InvTools.countItems(invInput, recipe.getItemToBuy()));
            if (canDoTrade(recipe)) {
                //                    System.out.println("Can do trade");
                doTrade(villager, recipe);
                return true;
            }
        }
    }
    return false;
}
Also used : MerchantRecipeList(net.minecraft.village.MerchantRecipeList) MerchantRecipe(net.minecraft.village.MerchantRecipe) EntityVillager(net.minecraft.entity.passive.EntityVillager) ItemStack(net.minecraft.item.ItemStack)

Example 2 with MerchantRecipe

use of net.minecraft.village.MerchantRecipe in project NetherEx by LogicTechCorp.

the class Trade method getRandomTrade.

public MerchantRecipe getRandomTrade(Random rand) {
    ItemStack outputStack = getItemToSell().copy();
    ItemStack inputA = getItemToBuy().copy();
    ItemStack inputB = getSecondItemToBuy().copy();
    outputStack.setCount(rand.nextInt((outputAmount.getMax() - outputAmount.getMin()) + 1) + outputAmount.getMin());
    inputA.setCount(rand.nextInt((inputAAmount.getMax() - inputAAmount.getMin()) + 1) + inputAAmount.getMin());
    inputB.setCount(rand.nextInt((inputBAmount.getMax() - inputBAmount.getMin()) + 1) + inputBAmount.getMin());
    if (outputEnchantments.size() > 0) {
        for (TradeOffer.Enchantment outputEnchantment : outputEnchantments) {
            Enchantment enchantment = Enchantment.getEnchantmentByLocation(outputEnchantment.getName());
            TradeOffer.Amount enchantmentAmount = outputEnchantment.getAmount();
            if (enchantment != null) {
                if (outputStack.getItem() instanceof ItemEnchantedBook) {
                    ((ItemEnchantedBook) outputStack.getItem()).addEnchantment(outputStack, new EnchantmentData(enchantment, rand.nextInt((enchantmentAmount.getMax() - enchantmentAmount.getMin()) + 1) + enchantmentAmount.getMin()));
                } else {
                    outputStack.addEnchantment(enchantment, rand.nextInt((enchantmentAmount.getMax() - enchantmentAmount.getMin()) + 1) + enchantmentAmount.getMin());
                }
            }
        }
    }
    return new MerchantRecipe(inputA, inputB, outputStack, 0, rand.nextInt((offerAmount.getMax() - offerAmount.getMin()) + 1) + offerAmount.getMin());
}
Also used : MerchantRecipe(net.minecraft.village.MerchantRecipe) ItemStack(net.minecraft.item.ItemStack) Enchantment(net.minecraft.enchantment.Enchantment) ItemEnchantedBook(net.minecraft.item.ItemEnchantedBook) EnchantmentData(net.minecraft.enchantment.EnchantmentData)

Example 3 with MerchantRecipe

use of net.minecraft.village.MerchantRecipe in project MorePlanets by SteveKunG.

the class EntityNibiruVillager method updateAITasks.

@Override
protected void updateAITasks() {
    if (--this.randomTickDivider <= 0) {
        BlockPos blockpos = new BlockPos(this);
        this.world.getVillageCollection().addToVillagerPositionList(blockpos);
        this.randomTickDivider = 70 + this.rand.nextInt(50);
        this.villageObj = this.world.getVillageCollection().getNearestVillage(blockpos, 32);
        if (this.villageObj == null) {
            this.detachHome();
        } else {
            BlockPos blockpos1 = this.villageObj.getCenter();
            this.setHomePosAndDistance(blockpos1, (int) (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.world.setEntityState(this, (byte) 14);
                    this.villageObj.modifyPlayerReputation(this.lastBuyingPlayer, 1);
                }
            }
            this.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 200, 0));
        }
    }
    super.updateAITasks();
}
Also used : MerchantRecipe(net.minecraft.village.MerchantRecipe) PotionEffect(net.minecraft.potion.PotionEffect) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with MerchantRecipe

use of net.minecraft.village.MerchantRecipe in project SpongeCommon by SpongePowered.

the class SpongeTradeOfferBuilder method build.

@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();
    MerchantRecipe recipe = new MerchantRecipe(ItemStackUtil.toNative(first), ItemStackUtil.toNative(second), ItemStackUtil.toNative(selling), this.useCount, this.maxUses);
    recipe.rewardsExp = this.allowsExperience;
    return (TradeOffer) recipe;
}
Also used : MerchantRecipe(net.minecraft.village.MerchantRecipe) ItemStack(org.spongepowered.api.item.inventory.ItemStack) TradeOffer(org.spongepowered.api.item.merchant.TradeOffer)

Example 5 with MerchantRecipe

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

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