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