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 b8335b20..09ede0e4 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,6 @@ package org.valkyrienskies.mod.mixin.feature.entity_collision; 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; @@ -34,7 +33,7 @@ public MixinLivingEntity(EntityType entityType, Level level) { private void preAiStep(CallbackInfo ci) { // fake lerp movement gaming if (this.level != null && this.level.isClientSide() && !firstTick) { - if (((Object) this) instanceof LocalPlayer) return; + if (this.isControlledByLocalInstance()) 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 a43fbe49..a829dae3 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 @@ -7,6 +7,7 @@ import net.minecraft.client.player.LocalPlayer; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket; +import net.minecraft.network.protocol.game.ServerboundMoveVehiclePacket; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.level.Level; @@ -18,6 +19,7 @@ import org.valkyrienskies.core.api.ships.ClientShip; import org.valkyrienskies.mod.common.VSGameUtilsKt; import org.valkyrienskies.mod.common.ValkyrienSkiesMod; +import org.valkyrienskies.mod.common.networking.PacketEntityShipMotion; import org.valkyrienskies.mod.common.networking.PacketPlayerShipMotion; import org.valkyrienskies.mod.common.util.EntityLerper; import org.valkyrienskies.mod.common.util.IEntityDraggingInformationProvider; @@ -71,4 +73,27 @@ private void wrapSendPosition(ClientPacketListener instance, Packet arg, Oper } original.call(instance, realArg); } + + @WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/ClientPacketListener;send(Lnet/minecraft/network/protocol/Packet;)V")) + private void wrapSendVehiclePosition(ClientPacketListener instance, Packet arg, Operation original) { + if (arg instanceof ServerboundMoveVehiclePacket vehiclePacket && getRootVehicle() instanceof IEntityDraggingInformationProvider dragProvider) { + if (dragProvider.getDraggingInformation().isEntityBeingDraggedByAShip()) { + if (dragProvider.getDraggingInformation().getLastShipStoodOn() != null) { + ClientShip ship = VSGameUtilsKt.getShipObjectWorld(Minecraft.getInstance().level).getAllShips().getById( + getDraggingInformation().getLastShipStoodOn()); + if (ship != null) { + Vector3dc relativePosition = ship.getWorldToShip().transformPosition( + VectorConversionsMCKt.toJOML(getRootVehicle().getPosition(1f)), new Vector3d()); + + double relativeYaw = EntityLerper.INSTANCE.yawToShip(ship, getRootVehicle().getYRot()); + + PacketEntityShipMotion packet = new PacketEntityShipMotion(getRootVehicle().getId(), ship.getId(), relativePosition.x(), relativePosition.y(), relativePosition.z(), 0.0, 0.0, 0.0, relativeYaw, 0.0); + ValkyrienSkiesMod.getVsCore().getSimplePacketNetworking().sendToServer(packet); + } + } + } + } + original.call(instance, arg); + } + } 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 9f00666e..e17745a6 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,11 +1,11 @@ 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 import net.minecraft.server.level.ServerPlayer +import net.minecraft.world.phys.Vec3 import org.joml.Vector3d import org.valkyrienskies.core.api.ships.LoadedServerShip import org.valkyrienskies.core.api.ships.getAttachment @@ -15,6 +15,7 @@ import org.valkyrienskies.mod.common.entity.ShipMountingEntity import org.valkyrienskies.mod.common.entity.handling.VSEntityManager import org.valkyrienskies.mod.common.getShipObjectManagingPos import org.valkyrienskies.mod.common.shipObjectWorld +import org.valkyrienskies.mod.common.toWorldCoordinates import org.valkyrienskies.mod.common.util.EntityLerper import org.valkyrienskies.mod.common.util.IEntityDraggingInformationProvider import org.valkyrienskies.mod.common.util.MinecraftPlayer @@ -70,7 +71,7 @@ object VSGamePackets { val level = mc.level ?: return@registerClientHandler val entity = level.getEntity(setMotion.entityID) ?: return@registerClientHandler - if (entity is LocalPlayer && entity.isLocalPlayer) return@registerClientHandler + if (entity.isControlledByLocalInstance) return@registerClientHandler val ship = level.shipObjectWorld.allShips.getById(setMotion.shipID) ?: return@registerClientHandler @@ -113,7 +114,7 @@ object VSGamePackets { val level = mc.level ?: return@registerClientHandler val entity = level.getEntity(setRotation.entityID) ?: return@registerClientHandler - if (entity is LocalPlayer && entity.isLocalPlayer) return@registerClientHandler + if (entity.isControlledByLocalInstance) return@registerClientHandler val ship = level.shipObjectWorld.allShips.getById(setRotation.shipID) ?: return@registerClientHandler @@ -153,5 +154,24 @@ object VSGamePackets { player.draggingInformation.serverRelativePlayerYaw = motion.yRot } } + + PacketEntityShipMotion::class.registerServerHandler { motion, iPlayer -> + val player = (iPlayer as MinecraftPlayer).player as ServerPlayer + val entity = player.level.getEntity(motion.entityID) ?: return@registerServerHandler + + if (entity is IEntityDraggingInformationProvider) { + if (entity.draggingInformation.lastShipStoodOn == null || entity.draggingInformation.lastShipStoodOn != motion.shipID) { + entity.draggingInformation.lastShipStoodOn = motion.shipID + entity.draggingInformation.ignoreNextGroundStand = true + } + + entity.draggingInformation.relativePositionOnShip = Vector3d(motion.x, motion.y, motion.z) + entity.draggingInformation.relativeYawOnShip = motion.yRot + + if ((player.level as ServerLevel).shipObjectWorld.allShips.getById(motion.shipID) != null) { + entity.setPos(player.level.toWorldCoordinates(Vec3(motion.x, motion.y, motion.z))) + } + } + } } } 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 78990a4e..8e57bc92 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,18 +1,13 @@ package org.valkyrienskies.mod.common.util -import net.minecraft.client.player.LocalPlayer import net.minecraft.server.level.ServerPlayer import net.minecraft.util.Mth import net.minecraft.world.entity.Entity -import net.minecraft.world.entity.player.Player import net.minecraft.world.phys.Vec3 import org.joml.Vector3d import org.joml.Vector3dc import org.valkyrienskies.core.api.ships.ClientShip -import org.valkyrienskies.mod.common.getShipMountedTo -import org.valkyrienskies.mod.common.getShipObjectManagingPos import org.valkyrienskies.mod.common.shipObjectWorld -import kotlin.math.abs import kotlin.math.asin import kotlin.math.atan2 import kotlin.math.cos @@ -126,7 +121,7 @@ object EntityDragger { entity.yHeadRot = Mth.wrapDegrees(entity.yHeadRot + addedYRot.toFloat()) } } else { - if (entity !is LocalPlayer) { + if (!entity.isControlledByLocalInstance) { entity.yRot = Mth.wrapDegrees(entity.yRot + addedYRot.toFloat()) entity.yHeadRot = Mth.wrapDegrees(entity.yHeadRot + addedYRot.toFloat()) } else {