Skip to content

Commit

Permalink
Various little tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
miyucomics committed Jul 10, 2024
1 parent 031519b commit 78266c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import at.petrak.hexcasting.api.spell.SpellAction
import at.petrak.hexcasting.api.spell.casting.CastingContext
import at.petrak.hexcasting.api.spell.getVec3
import at.petrak.hexcasting.api.spell.iota.Iota
import at.petrak.hexcasting.api.spell.mishaps.MishapInvalidIota
import miyucomics.hexical.entities.MagicMissileEntity
import miyucomics.hexical.registry.HexicalEntities
import net.minecraft.util.math.MathHelper
Expand Down Expand Up @@ -41,12 +42,9 @@ class OpMagicMissile : SpellAction {

private data class Spell(val position: Vec3d, val velocity: Vec3d) : RenderedSpell {
override fun cast(ctx: CastingContext) {
if (velocity == Vec3d.ZERO)
return
val missile = MagicMissileEntity(HexicalEntities.MAGIC_MISSILE_ENTITY, ctx.world)
missile.setPos(position.x, position.y, position.z)
val newVelocity = velocity.normalize().multiply(3.0)
missile.setVelocity(newVelocity.x, newVelocity.y, newVelocity.z)
missile.setVelocity(velocity.x, velocity.y, velocity.z)
missile.owner = ctx.caster
ctx.world.spawnEntity(missile)
}
Expand Down
35 changes: 6 additions & 29 deletions src/main/java/miyucomics/hexical/entities/MagicMissileEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ import net.minecraft.server.world.ServerWorld
import net.minecraft.sound.SoundCategory
import net.minecraft.sound.SoundEvent
import net.minecraft.sound.SoundEvents
import net.minecraft.util.hit.EntityHitResult
import net.minecraft.util.hit.HitResult
import net.minecraft.world.World

class MagicMissileEntity(entityType: EntityType<out MagicMissileEntity?>?, world: World?) : PersistentProjectileEntity(entityType, world) {
override fun getDamage() = 2.0
override fun asItemStack() = null
override fun hasNoGravity() = true
override fun getDragInWater() = 1f
Expand All @@ -44,32 +42,11 @@ class MagicMissileEntity(entityType: EntityType<out MagicMissileEntity?>?, world
shatter()
}

override fun onEntityHit(entityHitResult: EntityHitResult) {
val target = entityHitResult.entity
if (target.isInvulnerable)
return
if (target.type === EntityType.ENDERMAN)
return

val damageSource = if (owner == null) {
DamageSource.arrow(this, this)
} else {
if (owner is LivingEntity)
(owner as LivingEntity).onAttacking(target)
DamageSource.arrow(this, owner)
}

if (target.damage(damageSource, damage.toFloat())) {
if (target is LivingEntity) {
val vector = velocity.multiply(1.0, 0.0, 1.0).normalize().multiply(0.6)
if (vector.lengthSquared() > 0.0)
target.addVelocity(vector.x, 0.1, vector.z)
this.onHit(target)
}
} else {
this.velocity = velocity.multiply(-1.0)
this.yaw += 180.0f
this.prevYaw += 180.0f
}
override fun onHit(target: LivingEntity) {
super.onHit(target)
target.damage(DamageSource.thrownProjectile(this, this.owner), 2f)
val vector = velocity.multiply(1.0, 0.0, 1.0).normalize().multiply(0.6)
if (vector.lengthSquared() > 0.0)
target.addVelocity(vector.x, 0.1, vector.z)
}
}

0 comments on commit 78266c5

Please sign in to comment.