*screaming*
This commit is contained in:
parent
f8714bc7d1
commit
fd0113cd03
3 changed files with 32 additions and 4 deletions
|
@ -17,6 +17,7 @@ import at.petrak.hexcasting.common.items.HexItems
|
|||
import at.petrak.hexcasting.common.lib.HexCapabilityHandler
|
||||
import at.petrak.hexcasting.common.lib.HexSounds
|
||||
import at.petrak.hexcasting.common.misc.Brainsweeping
|
||||
import at.petrak.hexcasting.common.misc.PlayerPositionRecorder
|
||||
import at.petrak.hexcasting.common.network.HexMessages
|
||||
import at.petrak.hexcasting.common.particles.HexParticles
|
||||
import at.petrak.hexcasting.common.recipe.HexComposting
|
||||
|
@ -85,6 +86,7 @@ object HexMod {
|
|||
|
||||
modBus.register(HexComposting::class.java)
|
||||
|
||||
evBus.register(PlayerPositionRecorder::class.java)
|
||||
evBus.register(HexCommands::class.java)
|
||||
evBus.register(TickScheduler)
|
||||
evBus.register(HexCapabilityHandler::class.java)
|
||||
|
|
|
@ -5,9 +5,9 @@ import at.petrak.hexcasting.api.spell.Operator.Companion.getChecked
|
|||
import at.petrak.hexcasting.api.spell.Operator.Companion.spellListOf
|
||||
import at.petrak.hexcasting.api.spell.SpellDatum
|
||||
import at.petrak.hexcasting.api.spell.casting.CastingContext
|
||||
import at.petrak.hexcasting.common.misc.PlayerPositionRecorder
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
import net.minecraft.world.entity.Entity
|
||||
import net.minecraft.world.entity.player.Player
|
||||
import net.minecraft.world.phys.Vec3
|
||||
|
||||
object OpEntityVelocity : ConstManaOperator {
|
||||
override val argc = 1
|
||||
|
@ -17,8 +17,8 @@ object OpEntityVelocity : ConstManaOperator {
|
|||
ctx.assertEntityInRange(e)
|
||||
|
||||
// Player velocity is jank. Really jank. This is the best we can do.
|
||||
if (e is Player) {
|
||||
val prevPosition = Vec3(e.xOld, e.yOld, e.zOld)
|
||||
if (e is ServerPlayer) {
|
||||
val prevPosition = PlayerPositionRecorder.getLastPosition(e)
|
||||
return spellListOf(e.position().subtract(prevPosition))
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
package at.petrak.hexcasting.common.misc;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public final class PlayerPositionRecorder {
|
||||
private static final Map<Player, Vec3> LAST_POSITION_MAP = new WeakHashMap<>();
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onEntityUpdate(LivingEvent.LivingUpdateEvent evt) {
|
||||
if (evt.getEntityLiving() instanceof ServerPlayer player) {
|
||||
LAST_POSITION_MAP.put(player, player.position());
|
||||
}
|
||||
}
|
||||
|
||||
public static Vec3 getLastPosition(ServerPlayer player) {
|
||||
Vec3 vec = LAST_POSITION_MAP.get(player);
|
||||
return vec == null ? player.position() : vec;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue