Skip to content

Commit

Permalink
Fixed incorrect reference, also fixed vehicles supposedly
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePlasticPotato committed Dec 18, 2024
1 parent 39187dc commit 71e6c06
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<Void> 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);
}

}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)))
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 71e6c06

Please sign in to comment.