mirror of
https://github.com/darksaid98/Flashback.git
synced 2026-12-01 22:16:01 +00:00
Add workaround for mods that use non-standard entity spawn packets
This commit is contained in:
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;
|
||||
|
||||
|
||||
@@ -93,8 +93,8 @@ public class ReplayReader {
|
||||
RegistryFriendlyByteBuf registryFriendlyByteBuf = new RegistryFriendlyByteBuf(slice, this.registryAccess);
|
||||
action.handle(replayServer, registryFriendlyByteBuf);
|
||||
|
||||
if (slice.readerIndex() < size) {
|
||||
throw new RuntimeException("Action " + this.lastActionName + " failed to fully read. Had " + size + " bytes available, only read " + slice.readerIndex());
|
||||
if (slice.readerIndex() < slice.writerIndex()) {
|
||||
throw new RuntimeException("Action " + this.lastActionName + " failed to fully read. Had " + slice.writerIndex() + " bytes available, only read " + slice.readerIndex());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,8 +127,8 @@ public class ReplayReader {
|
||||
RegistryFriendlyByteBuf registryFriendlyByteBuf = new RegistryFriendlyByteBuf(slice, this.registryAccess);
|
||||
action.handle(replayServer, registryFriendlyByteBuf);
|
||||
|
||||
if (slice.readerIndex() < size) {
|
||||
throw new RuntimeException("Action " + this.lastActionName + " failed to fully read. Had " + size + " bytes available, only read " + slice.readerIndex());
|
||||
if (slice.readerIndex() < slice.writerIndex()) {
|
||||
throw new RuntimeException("Action " + this.lastActionName + " failed to fully read. Had " + slice.writerIndex() + " bytes available, only read " + slice.readerIndex());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -959,7 +959,12 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
||||
@Override
|
||||
public void handleRotateMob(ClientboundRotateHeadPacket clientboundRotateHeadPacket) {
|
||||
Entity entity = this.getEntityOrPending(clientboundRotateHeadPacket.entityId);
|
||||
if (entity == null || entity.getId() == this.localPlayerId) {
|
||||
if (entity == null) {
|
||||
forward(clientboundRotateHeadPacket);
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity.getId() == this.localPlayerId) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1002,6 +1007,7 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
||||
public void handleSetEntityData(ClientboundSetEntityDataPacket clientboundSetEntityDataPacket) {
|
||||
Entity entity = this.getEntityOrPending(clientboundSetEntityDataPacket.id());
|
||||
if (entity == null) {
|
||||
forward(clientboundSetEntityDataPacket);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1022,6 +1028,7 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
||||
public void handleSetEntityMotion(ClientboundSetEntityMotionPacket clientboundSetEntityMotionPacket) {
|
||||
Entity entity = this.getEntityOrPending(clientboundSetEntityMotionPacket.getId());
|
||||
if (entity == null) {
|
||||
forward(clientboundSetEntityMotionPacket);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1035,6 +1042,10 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
||||
@Override
|
||||
public void handleSetEquipment(ClientboundSetEquipmentPacket clientboundSetEquipmentPacket) {
|
||||
Entity entity = this.getEntityOrPending(clientboundSetEquipmentPacket.getEntity());
|
||||
if (entity == null) {
|
||||
forward(clientboundSetEquipmentPacket);
|
||||
return;
|
||||
}
|
||||
if (entity instanceof LivingEntity livingEntity) {
|
||||
clientboundSetEquipmentPacket.getSlots().forEach((pair) -> {
|
||||
livingEntity.setItemSlot(pair.getFirst(), pair.getSecond());
|
||||
@@ -1189,6 +1200,7 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
||||
public void handleTeleportEntity(ClientboundTeleportEntityPacket clientboundTeleportEntityPacket) {
|
||||
Entity entity = this.getEntityOrPending(clientboundTeleportEntityPacket.id());
|
||||
if (entity == null) {
|
||||
forward(clientboundTeleportEntityPacket);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1217,6 +1229,10 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
||||
@Override
|
||||
public void handleUpdateAttributes(ClientboundUpdateAttributesPacket clientboundUpdateAttributesPacket) {
|
||||
Entity entity = this.getEntityOrPending(clientboundUpdateAttributesPacket.getEntityId());
|
||||
if (entity == null) {
|
||||
forward(clientboundUpdateAttributesPacket);
|
||||
return;
|
||||
}
|
||||
if (entity instanceof LivingEntity livingEntity) {
|
||||
AttributeMap attributeMap = livingEntity.getAttributes();
|
||||
for (ClientboundUpdateAttributesPacket.AttributeSnapshot snapshot : clientboundUpdateAttributesPacket.getValues()) {
|
||||
@@ -1237,6 +1253,10 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
||||
@Override
|
||||
public void handleUpdateMobEffect(ClientboundUpdateMobEffectPacket clientboundUpdateMobEffectPacket) {
|
||||
Entity entity = this.getEntityOrPending(clientboundUpdateMobEffectPacket.getEntityId());
|
||||
if (entity == null) {
|
||||
forward(clientboundUpdateMobEffectPacket);
|
||||
return;
|
||||
}
|
||||
if (entity instanceof LivingEntity livingEntity) {
|
||||
Holder<MobEffect> holder = clientboundUpdateMobEffectPacket.getEffect();
|
||||
MobEffectInstance mobEffectInstance = new MobEffectInstance(holder, clientboundUpdateMobEffectPacket.getEffectDurationTicks(), clientboundUpdateMobEffectPacket.getEffectAmplifier(),
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.PacketHelper;
|
||||
import com.moulberry.flashback.SneakyThrow;
|
||||
import com.moulberry.flashback.ext.LevelChunkExt;
|
||||
import com.moulberry.flashback.TempFolderProvider;
|
||||
@@ -643,6 +644,10 @@ public class ReplayServer extends IntegratedServer {
|
||||
}
|
||||
|
||||
positionUpdateSet.add(id);
|
||||
} else {
|
||||
byte yRot = (byte) Mth.floor(yaw * 256.0F / 360.0F);
|
||||
byte xRot = (byte) Mth.floor(pitch * 256.0F / 360.0F);
|
||||
this.getPlayerList().broadcastAll(PacketHelper.createTeleportForUnknown(id, x, y, z, yRot, xRot, onGround));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,3 +161,18 @@ accessible field com/mojang/blaze3d/audio/Library currentDevice J
|
||||
accessible field com/mojang/blaze3d/audio/Library context J
|
||||
accessible field net/minecraft/client/sounds/SoundEngine executor Lnet/minecraft/client/sounds/SoundEngineExecutor;
|
||||
accessible field net/minecraft/client/sounds/SoundEngineExecutor thread Ljava/lang/Thread;
|
||||
|
||||
accessible field net/minecraft/network/protocol/game/ClientboundTeleportEntityPacket id I
|
||||
mutable field net/minecraft/network/protocol/game/ClientboundTeleportEntityPacket id I
|
||||
accessible field net/minecraft/network/protocol/game/ClientboundTeleportEntityPacket x D
|
||||
mutable field net/minecraft/network/protocol/game/ClientboundTeleportEntityPacket x D
|
||||
accessible field net/minecraft/network/protocol/game/ClientboundTeleportEntityPacket y D
|
||||
mutable field net/minecraft/network/protocol/game/ClientboundTeleportEntityPacket y D
|
||||
accessible field net/minecraft/network/protocol/game/ClientboundTeleportEntityPacket z D
|
||||
mutable field net/minecraft/network/protocol/game/ClientboundTeleportEntityPacket z D
|
||||
accessible field net/minecraft/network/protocol/game/ClientboundTeleportEntityPacket yRot B
|
||||
mutable field net/minecraft/network/protocol/game/ClientboundTeleportEntityPacket yRot B
|
||||
accessible field net/minecraft/network/protocol/game/ClientboundTeleportEntityPacket xRot B
|
||||
mutable field net/minecraft/network/protocol/game/ClientboundTeleportEntityPacket xRot B
|
||||
accessible field net/minecraft/network/protocol/game/ClientboundTeleportEntityPacket onGround Z
|
||||
mutable field net/minecraft/network/protocol/game/ClientboundTeleportEntityPacket onGround Z
|
||||
Reference in new issue
Block a user