diff --git a/common/src/main/java/org/valkyrienskies/mod/mixin/feature/entity_collision/MixinLivingEntity.java b/common/src/main/java/org/valkyrienskies/mod/mixin/feature/entity_collision/MixinLivingEntity.java index 5dab64e3..ae41a4b9 100644 --- a/common/src/main/java/org/valkyrienskies/mod/mixin/feature/entity_collision/MixinLivingEntity.java +++ b/common/src/main/java/org/valkyrienskies/mod/mixin/feature/entity_collision/MixinLivingEntity.java @@ -1,7 +1,7 @@ package org.valkyrienskies.mod.mixin.feature.entity_collision; -import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.client.player.LocalPlayer; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -28,13 +28,13 @@ public MixinLivingEntity(EntityType entityType, Level level) { * @reason Adjusted lerping for entities being dragged by ships. */ @Inject( - method = "aiStep", - at = @At(value = "HEAD") + method = "tick", + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;aiStep()V", shift = At.Shift.BEFORE) ) private void preAiStep(CallbackInfo ci) { // fake lerp movement gaming if (this.level != null && this.level.isClientSide() && !firstTick) { - if (this.isControlledByLocalInstance() || (Minecraft.getInstance().player != null && Minecraft.getInstance().player.is(this))) return; + if (this.isControlledByLocalInstance() || ((Entity) this instanceof LocalPlayer)) return; EntityDraggingInformation dragInfo = ((IEntityDraggingInformationProvider) this).getDraggingInformation(); if (dragInfo != null && dragInfo.getLastShipStoodOn() != null) { final ClientShip ship = VSGameUtilsKt.getShipObjectWorld((ClientLevel) level).getAllShips().getById(dragInfo.getLastShipStoodOn()); diff --git a/common/src/main/java/org/valkyrienskies/mod/mixin/feature/entity_collision/MixinLocalPlayer.java b/common/src/main/java/org/valkyrienskies/mod/mixin/feature/entity_collision/MixinLocalPlayer.java index a829dae3..73730d79 100644 --- a/common/src/main/java/org/valkyrienskies/mod/mixin/feature/entity_collision/MixinLocalPlayer.java +++ b/common/src/main/java/org/valkyrienskies/mod/mixin/feature/entity_collision/MixinLocalPlayer.java @@ -55,7 +55,7 @@ private void wrapSendPosition(ClientPacketListener instance, Packet arg, Oper } } if (realArg instanceof ServerboundMovePlayerPacket movePacket) { - final boolean isOnGround = movePacket.isOnGround() || getDraggingInformation().getTicksSinceStoodOnShip() < 4; + final boolean isOnGround = movePacket.isOnGround() || getDraggingInformation().isEntityBeingDraggedByAShip(); if (movePacket.hasPosition() && movePacket.hasRotation()) { //posrot realArg = new ServerboundMovePlayerPacket.PosRot(movePacket.getX(0.0), movePacket.getY(0.0), movePacket.getZ(0.0), movePacket.getYRot(0.0f), movePacket.getXRot(0.0f), isOnGround); diff --git a/common/src/main/java/org/valkyrienskies/mod/mixin/feature/entity_collision/MixinServerEntity.java b/common/src/main/java/org/valkyrienskies/mod/mixin/feature/entity_collision/MixinServerEntity.java index 296c7151..b38d7e8b 100644 --- a/common/src/main/java/org/valkyrienskies/mod/mixin/feature/entity_collision/MixinServerEntity.java +++ b/common/src/main/java/org/valkyrienskies/mod/mixin/feature/entity_collision/MixinServerEntity.java @@ -11,7 +11,6 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; import org.joml.Vector3d; -import org.slf4j.Logger; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -37,10 +36,6 @@ public class MixinServerEntity { @Final private ServerLevel level; - @Shadow - @Final - private static Logger LOGGER; - /** * @author Tomato * @reason Intercept entity motion packets to send our own data, then cancel the original packet. @@ -59,9 +54,11 @@ private void wrapBroadcastAccept(Consumer instance, Object t, Operation or if (dragInfo != null && dragInfo.isEntityBeingDraggedByAShip() && dragInfo.getLastShipStoodOn() != null) { ServerShip ship = VSGameUtilsKt.getShipObjectWorld(level).getAllShips().getById(dragInfo.getLastShipStoodOn()); if (ship != null) { -// if (!(entity instanceof Player)) LOGGER.info("Entity is rotated {}", entity.getYRot()); Vector3d position = ship.getWorldToShip().transformPosition(new Vector3d(entity.getX(), entity.getY(), entity.getZ())); + if (dragInfo.getServerRelativePlayerPosition() != null) { + position = new Vector3d(dragInfo.getServerRelativePlayerPosition()); + } Vector3d motion = ship.getTransform().transformDirectionNoScalingFromWorldToShip(new Vector3d(entity.getDeltaMovement().x(), entity.getDeltaMovement().y(), entity.getDeltaMovement().z()), new Vector3d()); double yaw; @@ -78,7 +75,7 @@ private void wrapBroadcastAccept(Consumer instance, Object t, Operation or motion.x, motion.y, motion.z, yaw, pitch); } else { - vsPacket = new PacketMobShipRotation(entity.getId(), ship.getId(), yaw); + vsPacket = new PacketMobShipRotation(entity.getId(), ship.getId(), yaw, pitch); } ValkyrienSkiesMod.getVsCore().getSimplePacketNetworking().sendToAllClients(vsPacket); diff --git a/common/src/main/kotlin/org/valkyrienskies/mod/common/networking/PacketMobShipRotation.kt b/common/src/main/kotlin/org/valkyrienskies/mod/common/networking/PacketMobShipRotation.kt index 1baed879..1b50eb66 100644 --- a/common/src/main/kotlin/org/valkyrienskies/mod/common/networking/PacketMobShipRotation.kt +++ b/common/src/main/kotlin/org/valkyrienskies/mod/common/networking/PacketMobShipRotation.kt @@ -5,4 +5,4 @@ import org.valkyrienskies.core.impl.networking.simple.SimplePacket /** * This packet is used in place of [net.minecraft.network.protocol.game.ClientboundRotateHeadPacket] to update the head rotation of a mob being dragged by a ship. */ -data class PacketMobShipRotation(val entityID: Int, val shipID: Long, val yaw: Double): SimplePacket +data class PacketMobShipRotation(val entityID: Int, val shipID: Long, val yaw: Double, val pitch: Double): SimplePacket diff --git a/common/src/main/kotlin/org/valkyrienskies/mod/common/networking/VSGamePackets.kt b/common/src/main/kotlin/org/valkyrienskies/mod/common/networking/VSGamePackets.kt index e0a69269..e7f384d9 100644 --- a/common/src/main/kotlin/org/valkyrienskies/mod/common/networking/VSGamePackets.kt +++ b/common/src/main/kotlin/org/valkyrienskies/mod/common/networking/VSGamePackets.kt @@ -1,6 +1,7 @@ package org.valkyrienskies.mod.common.networking import net.minecraft.client.Minecraft +import net.minecraft.client.player.LocalPlayer import net.minecraft.core.Registry import net.minecraft.resources.ResourceLocation import net.minecraft.server.level.ServerLevel @@ -72,7 +73,7 @@ object VSGamePackets { val level = mc.level ?: return@registerClientHandler val entity = level.getEntity(setMotion.entityID) ?: return@registerClientHandler - if (entity.isControlledByLocalInstance || (mc.player != null && mc.player!!.`is`(entity))) return@registerClientHandler + if (entity.isControlledByLocalInstance || mc.player?.id == entity.id) return@registerClientHandler val ship = level.shipObjectWorld.allShips.getById(setMotion.shipID) ?: return@registerClientHandler @@ -102,7 +103,6 @@ object VSGamePackets { entity.setPacketCoordinates(worldPosition.x, worldPosition.y, worldPosition.z) val worldVelocity = ship.renderTransform.shipToWorld.transformDirection(Vector3d(setMotion.xVel, setMotion.yVel, setMotion.zVel)) entity.setDeltaMovement(worldVelocity.x, worldVelocity.y, worldVelocity.z) - entity.xRot = setMotion.xRot.toFloat() entity.draggingInformation.lerpSteps = 3 // entity.setPos(previousWorldPosition.x, previousWorldPosition.y, previousWorldPosition.z) @@ -115,7 +115,7 @@ object VSGamePackets { val level = mc.level ?: return@registerClientHandler val entity = level.getEntity(setRotation.entityID) ?: return@registerClientHandler - if (entity.isControlledByLocalInstance || (entity is Player && entity.isLocalPlayer)) return@registerClientHandler + if (entity.isControlledByLocalInstance || entity is LocalPlayer) return@registerClientHandler val ship = level.shipObjectWorld.allShips.getById(setRotation.shipID) ?: return@registerClientHandler @@ -127,6 +127,8 @@ object VSGamePackets { } entity.draggingInformation.relativeHeadYawOnShip = EntityLerper.yawToShip(ship, entity.yHeadRot.toDouble()) entity.draggingInformation.lerpHeadYawOnShip = setRotation.yaw + entity.draggingInformation.relativePitchOnShip = entity.xRot.toDouble() + entity.draggingInformation.lerpPitchOnShip = setRotation.pitch entity.draggingInformation.headLerpSteps = 3 } } diff --git a/common/src/main/kotlin/org/valkyrienskies/mod/common/util/EntityDragger.kt b/common/src/main/kotlin/org/valkyrienskies/mod/common/util/EntityDragger.kt index ce15a241..c5cb860b 100644 --- a/common/src/main/kotlin/org/valkyrienskies/mod/common/util/EntityDragger.kt +++ b/common/src/main/kotlin/org/valkyrienskies/mod/common/util/EntityDragger.kt @@ -1,6 +1,7 @@ package org.valkyrienskies.mod.common.util import net.minecraft.client.Minecraft +import net.minecraft.client.player.LocalPlayer import net.minecraft.server.level.ServerPlayer import net.minecraft.util.Mth import net.minecraft.world.entity.Entity @@ -123,7 +124,7 @@ object EntityDragger { entity.yHeadRot = Mth.wrapDegrees(entity.yHeadRot + addedYRot.toFloat()) } } else { - if (!entity.isControlledByLocalInstance && !(Minecraft.getInstance().player != null && Minecraft.getInstance().player!!.`is`(entity))) { + if (!entity.isControlledByLocalInstance && entity !is LocalPlayer) { entity.yRot = Mth.wrapDegrees(entity.yRot + addedYRot.toFloat()) entity.yHeadRot = Mth.wrapDegrees(entity.yHeadRot + addedYRot.toFloat()) } else { diff --git a/common/src/main/kotlin/org/valkyrienskies/mod/common/util/EntityDraggingInformation.kt b/common/src/main/kotlin/org/valkyrienskies/mod/common/util/EntityDraggingInformation.kt index e5045e71..e7d60b25 100644 --- a/common/src/main/kotlin/org/valkyrienskies/mod/common/util/EntityDraggingInformation.kt +++ b/common/src/main/kotlin/org/valkyrienskies/mod/common/util/EntityDraggingInformation.kt @@ -23,11 +23,13 @@ class EntityDraggingInformation { var relativeVelocityOnShip: Vector3dc? = null var lerpYawOnShip: Double? = null var lerpHeadYawOnShip: Double? = null + var lerpPitchOnShip: Double? = null var relativePositionOnShip: Vector3dc? = null var previousRelativeVelocityOnShip: Vector3dc? = null var relativeYawOnShip: Double? = null var relativeHeadYawOnShip: Double? = null + var relativePitchOnShip: Double? = null var lerpSteps: Int = 0 var headLerpSteps: Int = 0 diff --git a/common/src/main/kotlin/org/valkyrienskies/mod/common/util/EntityLerper.kt b/common/src/main/kotlin/org/valkyrienskies/mod/common/util/EntityLerper.kt index 2cab51aa..facb37bb 100644 --- a/common/src/main/kotlin/org/valkyrienskies/mod/common/util/EntityLerper.kt +++ b/common/src/main/kotlin/org/valkyrienskies/mod/common/util/EntityLerper.kt @@ -62,8 +62,8 @@ object EntityLerper { val currentHeadYawWorld = yawToWorld(ship, currentHeadYaw) val lerpHeadYawWorld = yawToWorld(ship, lerpHeadYaw) - val newHeadYaw = currentHeadYawWorld + Mth.wrapDegrees(lerpHeadYawWorld - currentHeadYawWorld) / dragInfo.headLerpSteps - + val newHeadYaw = currentHeadYawWorld + Mth.wrapDegrees(lerpHeadYawWorld - currentHeadYawWorld) / dragInfo.headLerpSteps.toFloat() + entity.xRot += (dragInfo.lerpPitchOnShip!!.toFloat() - entity.xRot) / dragInfo.headLerpSteps.toFloat() entity.yHeadRot = newHeadYaw.toFloat() dragInfo.relativeHeadYawOnShip = yawToShip(ship, newHeadYaw.toDouble())