Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Common/src/main/java/at/petrak/hexcasting/api/HexAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ default Component getRawHookI18n(ResourceLocation name) {
return Component.translatable(getRawHookI18nKey(name)).withStyle(ChatFormatting.LIGHT_PURPLE);
}

/**
* If the entity has a special getter return that, otherwise return its normal look angle
*/
default Vec3 getEntityLookDirSpecial(Entity entity) {
return entity.getLookAngle();
}

/**
* Register an entity with the given ID to have its velocity as perceived by OpEntityVelocity be different
* than it's "normal" velocity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import at.petrak.hexcasting.api.casting.castables.ConstMediaAction
import at.petrak.hexcasting.api.casting.eval.CastingEnvironment
import at.petrak.hexcasting.api.casting.getEntity
import at.petrak.hexcasting.api.casting.iota.Iota
import at.petrak.hexcasting.api.HexAPI

object OpEntityLook : ConstMediaAction {
override val argc = 1

override fun execute(args: List<Iota>, env: CastingEnvironment): List<Iota> {
val e = args.getEntity(0, argc)
env.assertEntityInRange(e)
return e.lookAngle.asActionResult

val lookDir = HexAPI.instance().getEntityLookDirSpecial(e)
return lookDir.asActionResult
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.petrak.hexcasting.common.casting.actions.spells

import at.petrak.hexcasting.api.HexAPI
import at.petrak.hexcasting.api.casting.ParticleSpray
import at.petrak.hexcasting.api.casting.RenderedSpell
import at.petrak.hexcasting.api.casting.castables.SpellAction
Expand All @@ -14,6 +15,7 @@ import at.petrak.hexcasting.api.mod.HexConfig
import at.petrak.hexcasting.api.mod.HexTags
import at.petrak.hexcasting.common.casting.actions.spells.great.OpTeleport
import net.minecraft.world.entity.Entity
import net.minecraft.world.phys.Vec3
import kotlin.math.absoluteValue
import kotlin.math.roundToLong

Expand All @@ -36,7 +38,7 @@ object OpBlink : SpellAction {
throw MishapImmuneEntity(immunePassengers.get(0))
}

val dvec = target.lookAngle.scale(delta)
val dvec = HexAPI.instance().getEntityLookDirSpecial(target).scale(delta)
val endPos = target.position().add(dvec)

if (!HexConfig.server().canTeleportInThisDimension(env.world.dimension()))
Expand All @@ -51,7 +53,7 @@ object OpBlink : SpellAction {
val targetMiddlePos = target.position().add(0.0, target.eyeHeight / 2.0, 0.0)

return SpellAction.Result(
Spell(target, delta),
Spell(target, dvec),
(MediaConstants.SHARD_UNIT * delta.absoluteValue * 0.5).roundToLong(),
listOf(
ParticleSpray.cloud(targetMiddlePos, 2.0, 50),
Expand All @@ -60,13 +62,12 @@ object OpBlink : SpellAction {
)
}

private data class Spell(val target: Entity, val delta: Double) : RenderedSpell {
private data class Spell(val target: Entity, val dvec: Vec3) : RenderedSpell {
override fun cast(env: CastingEnvironment) {
if (!HexConfig.server().canTeleportInThisDimension(env.world.dimension()))
return

val delta = target.lookAngle.scale(delta)
OpTeleport.teleportRespectSticky(target, delta, env.world)
OpTeleport.teleportRespectSticky(target, dvec, env.world)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.monster.Phantom;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.AbstractHurtingProjectile;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.entity.projectile.ShulkerBullet;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ArmorMaterial;
import net.minecraft.world.item.ItemStack;
Expand All @@ -31,6 +35,21 @@ public class HexAPIImpl implements HexAPI {
private static final ConcurrentMap<EntityType<?>, Consumer<?>> SPECIAL_BRAINSWEEPS
= new ConcurrentHashMap<>();

@Override public Vec3 getEntityLookDirSpecial(Entity entity) {
var lookDir = entity.getLookAngle();
if (entity instanceof AbstractHurtingProjectile || entity instanceof ShulkerBullet) {
// couldn't find a report but these are bugged differently than other projectiles
lookDir = new Vec3(-1 * lookDir.x, lookDir.y, -1 * lookDir.z);
} else if (entity instanceof Projectile) {
// https://bugs.mojang.com/browse/MC/issues/MC-112474
lookDir = new Vec3(-1 * lookDir.x, -1 * lookDir.y, lookDir.z);
} else if (entity instanceof Phantom) {
// https://bugs.mojang.com/browse/MC/issues/MC-134707
lookDir = new Vec3(lookDir.x, -1 * lookDir.y, lookDir.z);
}
return lookDir;
}

public <T extends Entity> void registerSpecialVelocityGetter(EntityType<T> key,
EntityVelocityGetter<T> getter) {
if (SPECIAL_VELOCITIES.containsKey(key)) {
Expand Down
Loading