Add workaround for mods that use non-standard entity spawn packets

This commit is contained in:
Moulberry committed 2024-11-18 23:43:50 +08:00
1 parent 193b6ef058
commit fe33b55fc2
5 files changed
+62 -5

No files matched your search

@@ -3,6 +3,7 @@ package com.moulberry.flashback;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
import net.minecraft.network.protocol.game.VecDeltaCodec;
import net.minecraft.server.level.ServerEntity;
import net.minecraft.util.Mth;
@@ -25,6 +26,22 @@ public class PacketHelper {
return entity == null || entity.isRemoved() || entity instanceof EnderDragonPart || entity.getType().clientTrackingRange() <= 0;
}
public static ClientboundTeleportEntityPacket createTeleportForUnknown(int id, double x, double y, double z, byte yRot, byte xRot, boolean onGround) {
try {
ClientboundTeleportEntityPacket packet = (ClientboundTeleportEntityPacket) UnsafeWrapper.UNSAFE.allocateInstance(ClientboundTeleportEntityPacket.class);
packet.id = id;
packet.x = x;
packet.y = y;
packet.z = z;
packet.yRot = yRot;
packet.xRot = xRot;
packet.onGround = onGround;
return packet;
} catch (Exception e) {
throw SneakyThrow.sneakyThrow(e);
}
}
public static Packet<ClientGamePacketListener> createAddEntity(Entity entity) {
ServerEntity serverEntity = null;