package ru.dbotthepony.mc.otm.entity

import net.minecraft.sounds.SoundEvent
import net.minecraft.sounds.SoundEvents
import net.minecraft.world.entity.EntityType
import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.entity.ai.attributes.AttributeSupplier
import net.minecraft.world.entity.ai.attributes.Attributes
import net.minecraft.world.entity.ai.goal.AvoidEntityGoal
import net.minecraft.world.entity.ai.goal.LookAtPlayerGoal
import net.minecraft.world.entity.ai.goal.MeleeAttackGoal
import net.minecraft.world.entity.ai.goal.RandomLookAroundGoal
import net.minecraft.world.entity.ai.goal.WaterAvoidingRandomStrollGoal
import net.minecraft.world.entity.ai.goal.target.HurtByTargetGoal
import net.minecraft.world.entity.ai.goal.target.NearestAttackableTargetGoal
import net.minecraft.world.entity.ai.navigation.GroundPathNavigation
import net.minecraft.world.entity.ai.navigation.PathNavigation
import net.minecraft.world.entity.animal.frog.Frog
import net.minecraft.world.entity.monster.*
import net.minecraft.world.entity.npc.Villager
import net.minecraft.world.entity.player.Player
import net.minecraft.world.item.ItemStack
import net.minecraft.world.level.Level

class AndroidMelee(type: EntityType<AndroidMelee>, level: Level) : Monster(type, level) {

	override fun registerGoals() {
		goalSelector.addGoal(8, RandomLookAroundGoal(this))
		goalSelector.addGoal(7, WaterAvoidingRandomStrollGoal(this, 0.6))
		goalSelector.addGoal(8, LookAtPlayerGoal(this, Player::class.java, 8f))
		goalSelector.addGoal(3, NearestAttackableTargetGoal(this, LivingEntity::class.java, 10, true, true) { entity ->
				entity is Player ||
				entity is Villager ||
				entity is AbstractIllager ||
				entity is Zombie ||
				entity is AbstractSkeleton
		})

		goalSelector.addGoal(1, AvoidEntityGoal(this, Frog::class.java, 8.0F, 1.2, 1.5))

		goalSelector.addGoal(2, MeleeAttackGoal(this, 1.0, true))
		targetSelector.addGoal(1, HurtByTargetGoal(this))
	}

	override fun getArmorSlots(): MutableIterable<ItemStack> {
		return super.getArmorSlots()
	}

	override fun getHurtSound(damageSource: net.minecraft.world.damagesource.DamageSource): SoundEvent {
		return SoundEvents.HEAVY_CORE_BREAK
	}

	override fun getDeathSound(): SoundEvent {
		return SoundEvents.VAULT_BREAK
	}

	override fun createNavigation(level: Level): PathNavigation = GroundPathNavigation(this, level)

	companion object {
		fun createAttributes() : AttributeSupplier.Builder {
			return createMonsterAttributes()
				.add(Attributes.MAX_HEALTH, 30.0)
				.add(Attributes.ARMOR, 4.0)
				.add(Attributes.SCALE, 1.1)
				.add(Attributes.MOVEMENT_SPEED, 0.3)
				.add(Attributes.ATTACK_DAMAGE, 4.0)
		}
	}
}
