Search in sources :

Example 6 with MerchantRecipe

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

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

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

use of net.minecraft.village.MerchantRecipe in project pnc-repressurized by TeamPneumatic.

the class CraftingRegistrator method registerAmadronOffers.

private static void registerAmadronOffers() {
    PneumaticRecipeRegistry registry = PneumaticRecipeRegistry.getInstance();
    registry.registerDefaultStaticAmadronOffer(new ItemStack(Items.EMERALD, 8), new ItemStack(Itemss.PCB_BLUEPRINT));
    registry.registerDefaultStaticAmadronOffer(new ItemStack(Items.EMERALD, 8), new ItemStack(Itemss.ASSEMBLY_PROGRAM, 1, 0));
    registry.registerDefaultStaticAmadronOffer(new ItemStack(Items.EMERALD, 8), new ItemStack(Itemss.ASSEMBLY_PROGRAM, 1, 1));
    registry.registerDefaultStaticAmadronOffer(new ItemStack(Items.EMERALD, 14), new ItemStack(Itemss.ASSEMBLY_PROGRAM, 1, 2));
    registry.registerDefaultStaticAmadronOffer(new FluidStack(Fluids.OIL, 5000), new ItemStack(Items.EMERALD, 1));
    registry.registerDefaultStaticAmadronOffer(new FluidStack(Fluids.DIESEL, 4000), new ItemStack(Items.EMERALD, 1));
    registry.registerDefaultStaticAmadronOffer(new FluidStack(Fluids.LUBRICANT, 2500), new ItemStack(Items.EMERALD, 1));
    registry.registerDefaultStaticAmadronOffer(new FluidStack(Fluids.KEROSENE, 3000), new ItemStack(Items.EMERALD, 1));
    registry.registerDefaultStaticAmadronOffer(new FluidStack(Fluids.GASOLINE, 2000), new ItemStack(Items.EMERALD, 1));
    registry.registerDefaultStaticAmadronOffer(new FluidStack(Fluids.LPG, 1000), new ItemStack(Items.EMERALD, 1));
    registry.registerDefaultStaticAmadronOffer(new ItemStack(Items.EMERALD), new FluidStack(Fluids.OIL, 1000));
    registry.registerDefaultStaticAmadronOffer(new ItemStack(Items.EMERALD, 5), new FluidStack(Fluids.LUBRICANT, 1000));
    for (int i = 0; i < 256; i++) {
        try {
            for (int j = 0; j < 10; j++) {
                EntityVillager villager = new EntityVillager(null, i);
                MerchantRecipeList list = villager.getRecipes(null);
                for (MerchantRecipe recipe : list) {
                    if (recipe.getSecondItemToBuy().isEmpty() && !recipe.getItemToBuy().isEmpty() && !recipe.getItemToSell().isEmpty()) {
                        registry.registerDefaultPeriodicAmadronOffer(recipe.getItemToBuy(), recipe.getItemToSell());
                    }
                }
            }
        } catch (Throwable e) {
        }
    }
}
Also used : MerchantRecipeList(net.minecraft.village.MerchantRecipeList) MerchantRecipe(net.minecraft.village.MerchantRecipe) IPneumaticRecipeRegistry(me.desht.pneumaticcraft.api.recipe.IPneumaticRecipeRegistry) FluidStack(net.minecraftforge.fluids.FluidStack) EntityVillager(net.minecraft.entity.passive.EntityVillager) ItemStack(net.minecraft.item.ItemStack)

Example 10 with MerchantRecipe

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

the class TradeStationLogic method attemptTrade.

private void attemptTrade(List<EntityVillager> villagers, int tradeSet) {
    ItemStack buy1 = recipeSlots.getStackInSlot(tradeSet * 3);
    ItemStack buy2 = recipeSlots.getStackInSlot(tradeSet * 3 + 1);
    ItemStack sell = recipeSlots.getStackInSlot(tradeSet * 3 + 2);
    for (EntityVillager villager : villagers) {
        MerchantRecipeList recipes = villager.getRecipes(RailcraftFakePlayer.get((WorldServer) theWorldAsserted(), getX(), getY(), getZ()));
        if (recipes != null) {
            for (MerchantRecipe recipe : recipes) {
                if (recipe.isRecipeDisabled())
                    continue;
                // TODO: There must be clearer way to write this!
                ItemStack firstItem = recipe.getItemToBuy();
                ItemStack secondItem = recipe.getSecondItemToBuy();
                if (!InvTools.isEmpty(firstItem) && !InvTools.isItemLessThanOrEqualTo(firstItem, buy1))
                    continue;
                if (!InvTools.isEmpty(secondItem) && !InvTools.isItemLessThanOrEqualTo(secondItem, 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;
                }
            }
        }
    }
}
Also used : MerchantRecipeList(net.minecraft.village.MerchantRecipeList) MerchantRecipe(net.minecraft.village.MerchantRecipe) EntityVillager(net.minecraft.entity.passive.EntityVillager) WorldServer(net.minecraft.world.WorldServer) 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