Проанализируй два этих метода. [code]
- User
Проанализируй два этих метода.
kotlinprivate fun finishBrewQuest(villager: Villager, player: Player, potion: ItemStack, reply: () -> Unit) { val nmsVillager = (villager as CraftVillager).handle val nmsPotion = CraftItemStack.asNMSCopy(potion) val nmsPlayer = (player as CraftPlayer).handle var i = 0; val s = 6 plugin.server.scheduler.runTaskTimer(plugin, { task -> nmsVillager.isNoAi = true nmsVillager.setItemSlot(EquipmentSlot.MAINHAND, nmsPotion) nmsVillager.tradingPlayer = nmsPlayer villager.world.playSound(villager.location, Sound.ENTITY_GENERIC_DRINK, 1F, 1F) villager.world.playSound(villager.location, Sound.ENTITY_VILLAGER_TRADE, 1F, 1F) if (i++ >= s) { nmsVillager.setItemSlot(EquipmentSlot.MAINHAND, net.minecraft.world.item.ItemStack.EMPTY) villager.takeItemFromQuillInventory(potion, 1) villager.addItemToQuillInventory(ItemStack(Material.GLASS_BOTTLE)) villager.addPotionEffect((potion.itemMeta as PotionMeta).basePotionType!!.potionEffects.first()) nmsVillager.isNoAi = false reply.invoke() task.cancel() } }, 0, 20) } private fun Villager.eatSomething() { val food = quillInventory.filterNotNull().find { it.type.isEdible } ?: return val nmsVillager = (this as CraftVillager).handle val nmsFood = CraftItemStack.asNMSCopy(food) var i = 0 val s = 3 plugin.server.scheduler.runTaskTimer(plugin, { task -> nmsVillager.isNoAi = true nmsVillager.setItemSlot(EquipmentSlot.MAINHAND, nmsFood) val sound = when (food.type) { Material.HONEY_BOTTLE -> Sound.ITEM_HONEY_BOTTLE_DRINK Material.MUSHROOM_STEW, Material.RABBIT_STEW, Material.SUSPICIOUS_STEW -> Sound.ENTITY_GENERIC_DRINK else -> Sound.ENTITY_GENERIC_EAT } this.world.playSound(this.location, sound, 1F, 1F) if (i++ >= s) { nmsVillager.setItemSlot(EquipmentSlot.MAINHAND, net.minecraft.world.item.ItemStack.EMPTY) this.takeItemFromQuillInventory(food, 1) if (food.type.toString().contains("STEW")) this.addItemToQuillInventory(ItemStack(Material.BOWL)) if (food.type == Material.HONEY_BOTTLE) this.addItemToQuillInventory(ItemStack(Material.GLASS_BOTTLE)) this.world.playSound(this.location, Sound.ENTITY_VILLAGER_YES, 1F, 1F) this.world.playSound(this.location, Sound.ENTITY_PLAYER_BURP, 1F, 1F) this.hunger += 7.5 if (hunger >= 20.0) { this.addPotionEffect(PotionEffect(PotionEffectType.REGENERATION, 200, 1)) } nmsVillager.isNoAi = false task.cancel() } }, 0, 10) } - Assistant
- User
Попробуй избежать дублирования кода в этих методах.
- Assistant