Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 16:40:10 +01:00
Fix view distance update packet in 1.13->1.14
The client world is initialized during the join packet, but the view distance packet was created during/before the join handling. Fixes #2502
Dieser Commit ist enthalten in:
Ursprung
8beedffea2
Commit
0d31054903
@ -20,6 +20,7 @@ package com.viaversion.viaversion.protocols.protocol1_14to1_13_2.packets;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockFace;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||
@ -246,7 +247,7 @@ public class WorldPackets {
|
||||
if (entityTracker.isForceSendCenterChunk()
|
||||
|| diffX >= SERVERSIDE_VIEW_DISTANCE
|
||||
|| diffZ >= SERVERSIDE_VIEW_DISTANCE) {
|
||||
PacketWrapper fakePosLook = wrapper.create(0x40); // Set center chunk
|
||||
PacketWrapper fakePosLook = wrapper.create(ClientboundPackets1_14.UPDATE_VIEW_POSITION); // Set center chunk
|
||||
fakePosLook.write(Type.VAR_INT, chunk.getX());
|
||||
fakePosLook.write(Type.VAR_INT, chunk.getZ());
|
||||
fakePosLook.send(Protocol1_14To1_13_2.class, true, true);
|
||||
@ -302,7 +303,6 @@ public class WorldPackets {
|
||||
map(Type.INT); // 0 - Entity ID
|
||||
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
|
||||
map(Type.INT); // 2 - Dimension
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
@ -320,12 +320,11 @@ public class WorldPackets {
|
||||
tracker.setClientEntityId(entityId);
|
||||
}
|
||||
});
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
short difficulty = wrapper.read(Type.UNSIGNED_BYTE); // 19w11a removed difficulty from join game
|
||||
PacketWrapper difficultyPacket = wrapper.create(0x0D);
|
||||
PacketWrapper difficultyPacket = wrapper.create(ClientboundPackets1_14.SERVER_DIFFICULTY);
|
||||
difficultyPacket.write(Type.UNSIGNED_BYTE, difficulty);
|
||||
difficultyPacket.write(Type.BOOLEAN, false); // Unknown value added in 19w11a
|
||||
difficultyPacket.send(protocol.getClass());
|
||||
@ -336,6 +335,14 @@ public class WorldPackets {
|
||||
wrapper.write(Type.VAR_INT, SERVERSIDE_VIEW_DISTANCE); // Serverside view distance, added in 19w13a
|
||||
}
|
||||
});
|
||||
handler(wrapper -> {
|
||||
// Manually send the packet
|
||||
wrapper.send(Protocol1_14To1_13_2.class, true, true);
|
||||
wrapper.cancel();
|
||||
|
||||
// View distance has to be sent after the join packet
|
||||
sendViewDistancePacket(wrapper.user());
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -373,12 +380,18 @@ public class WorldPackets {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
short difficulty = wrapper.read(Type.UNSIGNED_BYTE); // 19w11a removed difficulty from respawn
|
||||
PacketWrapper difficultyPacket = wrapper.create(0x0D);
|
||||
PacketWrapper difficultyPacket = wrapper.create(ClientboundPackets1_14.SERVER_DIFFICULTY);
|
||||
difficultyPacket.write(Type.UNSIGNED_BYTE, difficulty);
|
||||
difficultyPacket.write(Type.BOOLEAN, false); // Unknown value added in 19w11a
|
||||
difficultyPacket.send(protocol.getClass());
|
||||
}
|
||||
});
|
||||
handler(wrapper -> {
|
||||
// Manually send the packet and update the viewdistance after
|
||||
wrapper.send(Protocol1_14To1_13_2.class, true, true);
|
||||
wrapper.cancel();
|
||||
sendViewDistancePacket(wrapper.user());
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -390,6 +403,12 @@ public class WorldPackets {
|
||||
});
|
||||
}
|
||||
|
||||
private static void sendViewDistancePacket(UserConnection connection) throws Exception {
|
||||
PacketWrapper setViewDistance = PacketWrapper.create(ClientboundPackets1_14.UPDATE_VIEW_DISTANCE, null, connection);
|
||||
setViewDistance.write(Type.VAR_INT, WorldPackets.SERVERSIDE_VIEW_DISTANCE);
|
||||
setViewDistance.send(Protocol1_14To1_13_2.class, true, true);
|
||||
}
|
||||
|
||||
private static long[] encodeHeightMap(int[] heightMap) {
|
||||
return CompactArrayUtil.createCompactArray(9, heightMap.length, i -> heightMap[i]);
|
||||
}
|
||||
|
@ -19,11 +19,7 @@ package com.viaversion.viaversion.protocols.protocol1_14to1_13_2.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.Entity1_14Types;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.Protocol1_14To1_13_2;
|
||||
import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.packets.WorldPackets;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@ -90,19 +86,6 @@ public class EntityTracker1_14 extends EntityTrackerBase {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClientEntityId(int playerEntityId) {
|
||||
super.setClientEntityId(playerEntityId);
|
||||
|
||||
PacketWrapper setViewDistance = PacketWrapper.create(0x41, null, user());
|
||||
setViewDistance.write(Type.VAR_INT, WorldPackets.SERVERSIDE_VIEW_DISTANCE);
|
||||
try {
|
||||
setViewDistance.send(Protocol1_14To1_13_2.class, true, true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public byte getEntityFlags(int player) {
|
||||
return zeroIfNull(playerEntityFlags.get(player));
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ package com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage;
|
||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.Environment;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* Stored up until 1.14 to be used in chunk sending.
|
||||
@ -31,7 +32,7 @@ public class ClientWorld extends StoredObject {
|
||||
super(connection);
|
||||
}
|
||||
|
||||
public Environment getEnvironment() {
|
||||
public @Nullable Environment getEnvironment() {
|
||||
return environment;
|
||||
}
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren