Проанализируй этот класс. [code]
- User
Проанализируй этот класс.
class VillagerInteractionGUI( private val plugin: QuestIntelligence, private val villager: Villager, private val viewer: Player, ) { private val pivot: Location = this.calculatePosition() private val lines: MutableMap<TextDisplay, () -> Unit> = mutableMapOf() private val height = 1.4 private val maxDistance = 4.5 private val size = 0.35F private val step = 0.1 private val defaultColor = Color.fromARGB(150, 0, 0, 0) private val selectedColor = Color.fromARGB(150, 200, 200, 0) private fun calculatePosition(): Location { return viewer.eyeLocation.add(villager.location.add(0.0, height, 0.0)).multiply(0.5) } fun relocate() { if (viewer.location.distance(villager.location.add(0.0, height, 0.0)) > maxDistance) { this.destroy() return } val location = this.calculatePosition() lines.keys.forEach { display -> display.teleport(location.clone().add(0.0, -lines.keys.indexOf(display) * step, 0.0)) } } var index: Int = 0 set(value) { field = if (value >= lines.size) 0 else if (value < 0) lines.size - 1 else value update() } fun addLine(text: String, function: () -> Unit) { val display = viewer.world.spawnEntity( pivot.clone().add(0.0, -lines.size * step, 0.0), EntityType.TEXT_DISPLAY ) as TextDisplay display.isVisibleByDefault = false viewer.showEntity(plugin, display) display.transformation = Transformation(Vector3f(0f, 0f, 0f), AxisAngle4f(), Vector3f(size, size, size), AxisAngle4f()) display.text(Component.text(text)) display.billboard = Display.Billboard.CENTER lines[display] = function update() } fun invokeSelected() { lines[lines.keys.toList()[index]]!!.invoke() } private fun update() { lines.keys.forEach { display -> display.backgroundColor = defaultColor } lines.keys.toList()[index].backgroundColor = selectedColor } fun destroy() { menus.remove(this.viewer) lines.keys.forEach(TextDisplay::remove) lines.clear() } } - Assistant
- User
Поговорим об улучшениях. Давай начнём с читаемости.
- Assistant
- User
Напиши класс целиком.
- Assistant
- User
Проанализируй вычисление отображения дисплея. Что если в метод relocate добавить вычисление кватернионов, связанных с поворотом дисплея так, чтобы он всегда был направлен на player.eyeLocation?
- Assistant
- User
- Assistant
- User
- Assistant
- User
Раздели этот метод на несколько.
- Assistant