class AstralStrikerBetaMoveControl(private val ghast: AstralStrikerEntityBeta) : MoveControl(ghast) {
private var collisionCheckCooldown = 0
override fun tick() {
if (this.state == State.MOVE_TO) {
if (collisionCheckCooldown-- <= 0) {
this.collisionCheckCooldown += ghast.random.nextInt(5) + 2
var vec3d = Vec3d(this.targetX - ghast.x, this.targetY - ghast.y, this.targetZ - ghast.z)
val d = vec3d.length()
vec3d = vec3d.normalize()
if (this.willCollide(vec3d, MathHelper.ceil(d))) {
ghast.velocity = ghast.velocity.add(vec3d.multiply(0.1))
ghast.velocityDirty
} else {
this.state = State.WAIT
}
}
}
}
private fun willCollide(direction: Vec3d, steps: Int): Boolean {
var box = ghast.bounds
for (i in 1 until steps) {
box = box.offset(direction)
if (!ghast.world.isSpaceEmpty(this.ghast, box)) {
return false
}
}
return true
}
}```
#Entity not moving
4 messages · Page 1 of 1 (latest)
class HoverRandomlyGoal(private val entity: AstralStrikerEntityBeta) : Goal() {
init {
this.controls = EnumSet.of(Control.MOVE)
}
override fun canStart(): Boolean {
val moveControl = entity.moveControl
if (!moveControl.isMoving) {
return true
} else {
val d = moveControl.targetX - entity.x
val e = moveControl.targetY - entity.y
val f = moveControl.targetZ - entity.z
val g = d * d + e * e + f * f
return g < 1.0 || g > 3600.0
}
}
override fun shouldContinue(): Boolean {
return false
}
override fun start() {
val randomGenerator = entity.random
var maxX = 16f
var minX = -16f
var maxY = 16f
var minY = -16f
var maxZ = 16f
var minZ = -16f
if (entity.target != null) {
val distanceX = (entity.x - entity.target!!.x).toFloat()
if((distanceX < 10 && distanceX > 0) || distanceX < -30) minX = 0f
if(distanceX > 30 || (distanceX > -10 && distanceX < 0)) maxX = 0f
val distanceY = (entity.y - entity.target!!.y).toFloat()
if((distanceY < 10 && distanceY > 0) || distanceY < -30) minY = 0f
if(distanceY > 30 || (distanceY > -10 && distanceY < 0)) maxY = 0f
val distanceZ = (entity.z - entity.target!!.z).toFloat()
if((distanceZ < 10 && distanceZ > 0) || distanceZ < -30) minY = 0f
if(distanceZ > 30 || (distanceZ > -10 && distanceZ < 0)) maxY = 0f
}
val d = entity.x + clamp(maxX, minX, (randomGenerator.nextFloat() * 2f - 1f) * 16f).toDouble()```
val e = entity.y + clamp(maxY, minY, (randomGenerator.nextFloat() * 2f - 1f) * 16f).toDouble()
val f = entity.z + clamp(maxZ, minZ, (randomGenerator.nextFloat() * 2f - 1f) * 16f).toDouble()
entity.moveControl.moveTo(d, e, f, 5.0)
}
}```
(had to split the second function in two because discord)
the entity kinda just sits there and does nothing, even when it has a target. i don't know why