@Override public void addMerchantRecipe(IMerchant merchant, MerchantRecipeList recipeList, Random random) { recipeList.add(new MerchantRecipe(in, out)); } }
@Override public void useRecipe(MerchantRecipe recipe) { recipe.incrementToolUses(); livingSoundTime = -getTalkInterval(); int i = 3 + rand.nextInt(4); if (recipe.getToolUses() == 1 || rand.nextInt(5) == 0) { // TODO Will need to come back to this, mating code got changed // TODO isWillingToMate = true; i += 5; } if (recipe.getItemToBuy() .getItem() == Items.EMERALD) { wealth += recipe.getItemToBuy() .getMaxStackSize(); } if (recipe.getRewardsExp()) { world.spawnEntity(new EntityXPOrb(world, posX, posY + 0.5D, posZ, i)); } }
if(!pstack.isEmpty() && recipes != null) for(MerchantRecipe recipe : recipes) if(recipe != null && !recipe.isRecipeDisabled() && (equalStacks(pstack, recipe.getItemToBuy()) || equalStacks(pstack, recipe.getItemToSell()))) { entIdBuilder.add(villager.getEntityId()); break;
@Override public void useRecipe(@Nonnull MerchantRecipe recipe) { if (entity != null && entity.isEntityAlive() && !entity.world.isRemote) { recipe.incrementToolUses(); if (existingList != null) { NBTTagCompound nbt = entity.getEntityData(); nbt.setTag("Stock", existingList.getRecipiesAsTags()); ItemStack toSell = recipe.getItemToSell(); ItemStack toBuy = recipe.getItemToBuy(); AnimalTradeEvent event = new AnimalTradeEvent(entity, customer, toBuy, toSell); MinecraftForge.EVENT_BUS.post(event); } entity.playLivingSound(); } }
match = false; rec = (MerchantRecipe) list.get(r); disabled = (rec.isRecipeDisabled()) ? "[x] " : ""; buy = rec.getItemToBuy(); buySecond = rec.getSecondItemToBuy(); sell = rec.getItemToSell();
private void updateTradingStackSizes(MerchantRecipeList recipeList) { if (recipeList != null) { for (Object obj : recipeList) { MerchantRecipe recipe = (MerchantRecipe) obj; ItemStack toSell = recipe.getItemToSell(); int stackSizeToSell = toSell.getCount(); ItemStack toBuy = recipe.getItemToBuy(); int stackSizeToBuy = toBuy.getCount(); ItemStack secondBuy = recipe.getSecondItemToBuy(); int stackSizeSecond = secondBuy.getCount(); if (stackSizeToSell > 1 && stackSizeToSell != MathHelper.floor(stackSizeToSell * 1.25F)) { stackSizeToSell = MathHelper.floor(stackSizeToSell * 1.25F); } else if (stackSizeToBuy > 1 && stackSizeToBuy != MathHelper.ceil(stackSizeToBuy / 1.25F)) { stackSizeToBuy = MathHelper.ceil(stackSizeToBuy / 1.25F); } else if (secondBuy != null && stackSizeSecond > 1 && stackSizeSecond != MathHelper.ceil(stackSizeSecond / 1.25F)) { stackSizeSecond = MathHelper.ceil(stackSizeSecond / 1.25F); } toSell.setCount(stackSizeToSell); toBuy.setCount(stackSizeToBuy); secondBuy.setCount(stackSizeSecond); } lastViewVillagerGui = true; } }
MerchantRecipe merchantRecipe = (MerchantRecipe)merchantRecipeList.get(currentRecipeIndex); ItemStack buyingItemStack1 = merchantRecipe.getItemToBuy(); ItemStack buyingItemStack2 = merchantRecipe.getSecondItemToBuy();
@Override public List<String> getTooltips() { List<String> tt = new ArrayList<String>(); MerchantRecipeList merchantrecipelist = parent.getContainer().getTrades(); if (merchantrecipelist == null) { return tt; } MerchantRecipe r = merchantrecipelist.get(recipeIndex); if (r == null) { return tt; } if (r.isRecipeDisabled()) { tt.add(UtilChat.lang("merchant.deprecated")); } else { tt.add(UtilChat.lang("tile.tool_trade.button.tooltip")); } if (r.getItemToSell() != null) {// && r.getItemToSell().getItem() == Items.ENCHANTED_BOOK Map<Enchantment, Integer> map = EnchantmentHelper.getEnchantments(r.getItemToSell()); if (map != null) { for (Map.Entry<Enchantment, Integer> entry : map.entrySet()) { tt.add(entry.getKey().getTranslatedName(entry.getValue())); } } } return tt; } }
protected void updateAITasks() { 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.getHive() != null && this.lastBuyingPlayer != null) { this.world.setEntityState(this, (byte) 14); this.getHive().setWorld(this.world); this.getHive().modifyPlayerReputation(this.lastBuyingPlayer, 1); } } this.addPotionEffect(new PotionEffect(MobEffects.REGENERATION, 200, 0)); } } super.updateAITasks(); }
int y = this.y + 1; GlStateManager.pushMatrix(); ModCyclic.proxy.renderItemOnGui(r.getItemToBuy(), parent.itemRender, parent.fontRenderer, x, y); x += spacing; ModCyclic.proxy.renderItemOnGui(r.getSecondItemToBuy(), parent.itemRender, parent.fontRenderer, x, y); x += spacing; ModCyclic.proxy.renderItemOnGui(r.getItemToSell(), parent.itemRender, parent.fontRenderer, x, y); GlStateManager.popMatrix(); if (r.isRecipeDisabled()) { parent.mc.getTextureManager().bindTexture(TRADE_REDX); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
if (merchantrecipelist != null) { MerchantRecipe merchantrecipe = merchantrecipelist.canRecipeBeUsed(itemstack, itemstack1, this.currentRecipeIndex); if (merchantrecipe != null && !merchantrecipe.isRecipeDisabled()) { this.currentRecipe = merchantrecipe; this.setInventorySlotContents(2, merchantrecipe.getItemToSell().copy()); if (merchantrecipe != null && !merchantrecipe.isRecipeDisabled()) { this.currentRecipe = merchantrecipe; this.setInventorySlotContents(2, merchantrecipe.getItemToSell().copy());
@SubscribeEvent public void onEntityInteractEvent(EntityInteract event) { if (event.getEntity() instanceof EntityPlayer == false) { return; } EntityPlayer player = (EntityPlayer) event.getEntity(); // ItemStack held = player.getHeldItemMainhand(); ItemStack itemstack = event.getItemStack(); if (itemstack != null && itemstack.getItem() instanceof ItemVillagerMagic && itemstack.getCount() > 0) { if (event.getTarget() instanceof EntityVillager) { EntityVillager villager = ((EntityVillager) event.getTarget()); int count = 0; for (MerchantRecipe merchantrecipe : villager.getRecipes(player)) { if (merchantrecipe.isRecipeDisabled()) { //vanilla code as of 1.9.4 odes this (2d6+2) merchantrecipe.increaseMaxTradeUses(villager.getEntityWorld().rand.nextInt(6) + villager.getEntityWorld().rand.nextInt(6) + 2); count++; } } if (count > 0) { UtilChat.addChatMessage(player, UtilChat.lang("item.apple_emerald.merchant") + count); consumeSelf(itemstack); } event.setCanceled(true);// stop the GUI inventory opening && horse mounting } } }
public void addBuyItemStack(MerchantRecipeList recipeList, Random random, ItemStack stack, float chance, int price, int variation) { if (random.nextFloat() < chance) { MerchantRecipe recipe = new MerchantRecipe(stack, null, new ItemStack(Items.EMERALD, price + random.nextInt(variation))); recipeList.add(recipe); } }
public void doTrade(EntityPlayer player, int selectedMerchantRecipe) { MerchantRecipe trade = getTrades().get(selectedMerchantRecipe); if (trade.isRecipeDisabled()) { return; ItemStack itemToBuy = trade.getItemToBuy().copy(); ItemStack itemSecondBuy = (trade.getSecondItemToBuy().isEmpty()) ? ItemStack.EMPTY : trade.getSecondItemToBuy().copy(); ItemStack firstItem = ItemStack.EMPTY; ItemStack secondItem = ItemStack.EMPTY; ItemStack purchased = trade.getItemToSell().copy(); player.entityDropItem(purchased, 1); this.merchant.useRecipe(trade);
public void useRecipe(MerchantRecipe recipe) { recipe.incrementToolUses(); this.livingSoundTime = -this.getTalkInterval(); if(this.getHive() != null && this.getCustomer() != null){ this.getHive().setWorld(this.world); this.getHive().modifyPlayerReputation(this.getCustomer().getUniqueID(), 2); } this.playSound(ModSounds.MYRMEX_IDLE, this.getSoundVolume(), this.getSoundPitch()); int i = 3 + this.rand.nextInt(4); if (recipe.getToolUses() == 1 || this.rand.nextInt(5) == 0) { this.timeUntilReset = 40; this.needsInitilization = true; if (this.buyingPlayer != null) { this.lastBuyingPlayer = this.buyingPlayer.getUniqueID(); } else { this.lastBuyingPlayer = null; } i += 5; } if (recipe.getItemToBuy().getItem() == ModItems.myrmex_desert_resin || recipe.getItemToBuy().getItem() == ModItems.myrmex_jungle_resin) { this.wealth += recipe.getItemToBuy().getCount(); } if (recipe.getRewardsExp()) { this.world.spawnEntity(new EntityXPOrb(this.world, this.posX, this.posY + 0.5D, this.posZ, i)); } }
public void addSellItemStack(MerchantRecipeList recipeList, Random random, ItemStack stack, float chance, int price, int variation) { if (random.nextFloat() < chance) { MerchantRecipe recipe = new MerchantRecipe(new ItemStack(Items.EMERALD, price + random.nextInt(variation)), null, stack); recipeList.add(recipe); } } }
/** * Add a recipe to SELL something for emeralds */ private void addRecipe(MerchantRecipeList list, ItemStack stack, int emeralds, Random rnd, float prop) { if (rnd.nextFloat() < prop) { list.add(new MerchantRecipe(new ItemStack(Items.EMERALD, emeralds), stack)); } }
/** * Add a recipe to BUY something for emeralds */ private void addRecipe(MerchantRecipeList list, int emeralds, ItemStack stack, Random rnd, float prop) { if (rnd.nextFloat() < prop) { list.add(new MerchantRecipe(new ItemStack(Items.EMERALD, emeralds), stack)); } }
public void addSellPart(MerchantRecipeList recipeList, Random random, int part, float chance, int price, int variation) { if (random.nextFloat() < chance) { MerchantRecipe recipe = new MerchantRecipe(new ItemStack(Items.EMERALD, price + random.nextInt(variation)), null, new ItemStack(MatterOverdrive.ITEMS.androidParts, 1, part)); recipeList.add(recipe); } }
public void addBuyPart(MerchantRecipeList recipeList, Random random, int part, float chance, int price, int variation) { if (random.nextFloat() < chance) { MerchantRecipe recipe = new MerchantRecipe(new ItemStack(MatterOverdrive.ITEMS.androidParts, 1, part), null, new ItemStack(Items.EMERALD, price + random.nextInt(variation))); recipeList.add(recipe); } }