Fixed illusioner goals
This commit is contained in:
@@ -2,7 +2,6 @@ package com.willfp.eco.internal.spigot.proxy.common.ai.entity
|
||||
|
||||
import com.willfp.eco.core.entities.ai.entity.EntityGoalIllusionerBlindnessSpell
|
||||
import com.willfp.eco.internal.spigot.proxy.common.ai.EntityGoalFactory
|
||||
import com.willfp.eco.internal.spigot.proxy.common.ai.opengoals.IllusionerBlindnessSpellGoal
|
||||
import net.minecraft.world.entity.PathfinderMob
|
||||
import net.minecraft.world.entity.ai.goal.Goal
|
||||
import net.minecraft.world.entity.monster.Illusioner
|
||||
@@ -11,11 +10,14 @@ object IllusionerBlindnessSpellGoalFactory : EntityGoalFactory<EntityGoalIllusio
|
||||
override fun create(apiGoal: EntityGoalIllusionerBlindnessSpell, entity: PathfinderMob): Goal? {
|
||||
if (entity !is Illusioner) return null
|
||||
|
||||
return IllusionerBlindnessSpellGoal(
|
||||
entity
|
||||
)
|
||||
// Have to use reflection for it to work
|
||||
return Illusioner::class.java.declaredClasses[1]
|
||||
.getDeclaredConstructor(Illusioner::class.java)
|
||||
.apply { isAccessible = true }
|
||||
.newInstance(entity) as Goal
|
||||
}
|
||||
|
||||
override fun isGoalOfType(goal: Goal) = goal is IllusionerBlindnessSpellGoal
|
||||
|| goal::class.java.name.contains("IllusionerBlindnessSpellGoal")
|
||||
override fun isGoalOfType(goal: Goal): Boolean {
|
||||
return Illusioner::class.java.declaredClasses[1].isInstance(goal)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.willfp.eco.internal.spigot.proxy.common.ai.entity
|
||||
|
||||
import com.willfp.eco.core.entities.ai.entity.EntityGoalIllusionerMirrorSpell
|
||||
import com.willfp.eco.internal.spigot.proxy.common.ai.EntityGoalFactory
|
||||
import com.willfp.eco.internal.spigot.proxy.common.ai.opengoals.IllusionerMirrorSpellGoal
|
||||
import net.minecraft.world.entity.PathfinderMob
|
||||
import net.minecraft.world.entity.ai.goal.Goal
|
||||
import net.minecraft.world.entity.monster.Illusioner
|
||||
@@ -11,11 +10,14 @@ object IllusionerMirrorSpellGoalFactory : EntityGoalFactory<EntityGoalIllusioner
|
||||
override fun create(apiGoal: EntityGoalIllusionerMirrorSpell, entity: PathfinderMob): Goal? {
|
||||
if (entity !is Illusioner) return null
|
||||
|
||||
return IllusionerMirrorSpellGoal(
|
||||
entity
|
||||
)
|
||||
// Have to use reflection for it to work
|
||||
return Illusioner::class.java.declaredClasses[0]
|
||||
.getDeclaredConstructor(Illusioner::class.java)
|
||||
.apply { isAccessible = true }
|
||||
.newInstance(entity) as Goal
|
||||
}
|
||||
|
||||
override fun isGoalOfType(goal: Goal) = goal is IllusionerMirrorSpellGoal
|
||||
|| goal::class.java.name.contains("IllusionerMirrorSpellGoal")
|
||||
override fun isGoalOfType(goal: Goal): Boolean {
|
||||
return Illusioner::class.java.declaredClasses[0].isInstance(goal)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.common.ai.opengoals
|
||||
|
||||
import net.minecraft.sounds.SoundEvent
|
||||
import net.minecraft.sounds.SoundEvents
|
||||
import net.minecraft.world.Difficulty
|
||||
import net.minecraft.world.effect.MobEffectInstance
|
||||
import net.minecraft.world.effect.MobEffects
|
||||
import net.minecraft.world.entity.monster.Illusioner
|
||||
import net.minecraft.world.entity.monster.SpellcasterIllager
|
||||
import org.bukkit.event.entity.EntityPotionEffectEvent
|
||||
|
||||
class IllusionerBlindnessSpellGoal(
|
||||
private val illusioner: Illusioner
|
||||
) : OpenUseSpellGoal(illusioner) {
|
||||
override val castingInterval = 180
|
||||
override val castingTime = 20
|
||||
override val spellPrepareSound: SoundEvent = SoundEvents.ILLUSIONER_PREPARE_BLINDNESS
|
||||
override val spell: SpellcasterIllager.IllagerSpell = SpellcasterIllager.IllagerSpell.BLINDNESS
|
||||
|
||||
private var lastTargetId = 0
|
||||
|
||||
override fun canUse(): Boolean {
|
||||
return if (super.canUse()) {
|
||||
false
|
||||
} else if (illusioner.target == null) {
|
||||
false
|
||||
} else if (illusioner.target!!.id == lastTargetId) {
|
||||
false
|
||||
} else {
|
||||
illusioner.level.getCurrentDifficultyAt(illusioner.blockPosition()).isHarderThan(
|
||||
Difficulty.NORMAL.ordinal.toFloat()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override fun start() {
|
||||
super.start()
|
||||
if (illusioner.target != null) {
|
||||
lastTargetId = illusioner.target!!.id
|
||||
}
|
||||
}
|
||||
|
||||
override fun performSpellCasting() {
|
||||
illusioner.target?.addEffect(
|
||||
MobEffectInstance(MobEffects.BLINDNESS, 400),
|
||||
illusioner,
|
||||
EntityPotionEffectEvent.Cause.ATTACK
|
||||
) // CraftBukkit
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.common.ai.opengoals
|
||||
|
||||
import net.minecraft.sounds.SoundEvent
|
||||
import net.minecraft.sounds.SoundEvents
|
||||
import net.minecraft.world.effect.MobEffectInstance
|
||||
import net.minecraft.world.effect.MobEffects
|
||||
import net.minecraft.world.entity.monster.Illusioner
|
||||
import net.minecraft.world.entity.monster.SpellcasterIllager
|
||||
import org.bukkit.event.entity.EntityPotionEffectEvent
|
||||
|
||||
class IllusionerMirrorSpellGoal(
|
||||
private val illusioner: Illusioner
|
||||
) : OpenUseSpellGoal(illusioner) {
|
||||
override val castingInterval = 340
|
||||
override val castingTime = 20
|
||||
override val spellPrepareSound: SoundEvent = SoundEvents.ILLUSIONER_PREPARE_MIRROR
|
||||
override val spell: SpellcasterIllager.IllagerSpell = SpellcasterIllager.IllagerSpell.DISAPPEAR
|
||||
|
||||
override fun canUse(): Boolean {
|
||||
return if (!super.canUse()) false else !illusioner.hasEffect(MobEffects.INVISIBILITY)
|
||||
}
|
||||
|
||||
override fun performSpellCasting() {
|
||||
illusioner.addEffect(
|
||||
MobEffectInstance(MobEffects.INVISIBILITY, 1200),
|
||||
EntityPotionEffectEvent.Cause.ILLUSION
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.common.ai.opengoals
|
||||
|
||||
import net.minecraft.sounds.SoundEvent
|
||||
import net.minecraft.world.entity.EntityType
|
||||
import net.minecraft.world.entity.LivingEntity
|
||||
import net.minecraft.world.entity.ai.goal.Goal
|
||||
import net.minecraft.world.entity.monster.SpellcasterIllager
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
class DelegatedSpellcaster(private val handle: SpellcasterIllager) : SpellcasterIllager(
|
||||
handle.type as EntityType<out SpellcasterIllager>,
|
||||
handle.level
|
||||
) {
|
||||
var openSpellCastingTickCount
|
||||
get() = this.spellCastingTickCount
|
||||
set(value) {
|
||||
this.spellCastingTickCount = value
|
||||
}
|
||||
|
||||
val openCastingSoundEvent = this.castingSoundEvent
|
||||
|
||||
override fun applyRaidBuffs(wave: Int, unused: Boolean) {
|
||||
handle.applyRaidBuffs(wave, unused)
|
||||
}
|
||||
|
||||
override fun getCelebrateSound(): SoundEvent {
|
||||
return handle.celebrateSound
|
||||
}
|
||||
|
||||
override fun getCastingSoundEvent(): SoundEvent {
|
||||
return this.openCastingSoundEvent
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
|
||||
abstract class OpenUseSpellGoal(
|
||||
private val handle: SpellcasterIllager
|
||||
) : Goal() {
|
||||
private var attackWarmupDelay = 0
|
||||
private var nextAttackTickCount = 0
|
||||
|
||||
private val openHandle = DelegatedSpellcaster(handle)
|
||||
|
||||
override fun canUse(): Boolean {
|
||||
val entityliving: LivingEntity = handle.target ?: return false
|
||||
return if (entityliving.isAlive) if (handle.isCastingSpell) false else handle.tickCount >= nextAttackTickCount else false
|
||||
}
|
||||
|
||||
override fun canContinueToUse(): Boolean {
|
||||
val entityliving: LivingEntity = handle.target ?: return false
|
||||
return entityliving.isAlive && attackWarmupDelay > 0
|
||||
}
|
||||
|
||||
override fun start() {
|
||||
attackWarmupDelay = castWarmupTime
|
||||
openHandle.openSpellCastingTickCount = castingTime
|
||||
nextAttackTickCount = handle.tickCount + castingInterval
|
||||
val soundeffect = spellPrepareSound
|
||||
if (soundeffect != null) {
|
||||
handle.playSound(soundeffect, 1.0f, 1.0f)
|
||||
}
|
||||
handle.setIsCastingSpell(spell)
|
||||
}
|
||||
|
||||
override fun tick() {
|
||||
--attackWarmupDelay
|
||||
if (attackWarmupDelay == 0) {
|
||||
performSpellCasting()
|
||||
handle.playSound(openHandle.openCastingSoundEvent, 1.0f, 1.0f)
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract fun performSpellCasting()
|
||||
protected abstract val castingTime: Int
|
||||
protected abstract val castingInterval: Int
|
||||
protected abstract val spellPrepareSound: SoundEvent?
|
||||
protected abstract val spell: SpellcasterIllager.IllagerSpell?
|
||||
protected open val castWarmupTime: Int = 60
|
||||
}
|
||||
Reference in New Issue
Block a user