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