Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
retrooper committed 2021-12-01 17:25:32 +01:00
commit df56ea0aa6
3 files changed
+39 -30

No files matched your search

@@ -399,8 +399,12 @@ public class PacketTypeClasses {
SET_SUBTITLE_TEXT = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundSetSubtitleTextPacket");
SET_TITLES_ANIMATION = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundSetTitlesAnimationPacket");
SET_TITLE_TEXT = Reflection.getClassByNameWithoutException(PREFIX + "ClientboundSetTitleTextPacket");
// 1.18+ only, doesn't follow the naming convention
if (MAP_CHUNK == null) {
MAP_CHUNK = Reflection.getClassByNameWithoutException("net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket");
}
}
}
}
}
@@ -21,6 +21,7 @@ package io.github.retrooper.packetevents.packetwrappers.play.out.mapchunk;
import io.github.retrooper.packetevents.packettype.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.NMSPacket;
import io.github.retrooper.packetevents.packetwrappers.WrappedPacket;
import io.github.retrooper.packetevents.utils.reflection.Reflection;
import io.github.retrooper.packetevents.utils.reflection.SubclassUtil;
import io.github.retrooper.packetevents.utils.server.ServerVersion;
@@ -31,8 +32,8 @@ import java.util.Optional;
//TODO finish wrapper
public class WrappedPacketOutMapChunk extends WrappedPacket {
private static boolean v_1_8_x, v_1_17;
private static Class<?> chunkMapClass;
private static boolean v_1_8_x, v_1_17, v_1_18;
private static Class<?> chunkMapClass, chunkPacketDataClass;
private Constructor<?> chunkMapConstructor;
private Object nmsChunkMap;
@@ -44,6 +45,7 @@ public class WrappedPacketOutMapChunk extends WrappedPacket {
protected void load() {
v_1_8_x = version.isNewerThan(ServerVersion.v_1_7_10) && version.isOlderThan(ServerVersion.v_1_9);
v_1_17 = version.isNewerThanOrEquals(ServerVersion.v_1_17);
v_1_18 = version.isNewerThanOrEquals(ServerVersion.v_1_18);
if (v_1_8_x) {
chunkMapClass = SubclassUtil.getSubClass(PacketTypeClasses.Play.Server.MAP_CHUNK, 0);
try {
@@ -52,77 +54,68 @@ public class WrappedPacketOutMapChunk extends WrappedPacket {
e.printStackTrace();
}
}
chunkPacketDataClass = Reflection.getClassByNameWithoutException("net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData");
}
public int getChunkX() {
return readInt(v_1_17 ? 1 : 0);
return readInt(v_1_17 && !v_1_18 ? 1 : 0);
}
public void setChunkX(int chunkX) {
writeInt(v_1_17 ? 1: 0, chunkX);
writeInt(v_1_17 && !v_1_18 ? 1 : 0, chunkX);
}
public int getChunkZ() {
return readInt(v_1_17 ? 2: 1);
return readInt(v_1_17 && !v_1_18 ? 2 : 1);
}
public void setChunkZ(int chunkZ) {
writeInt(v_1_17 ? 2: 1, chunkZ);
writeInt(v_1_17 && !v_1_18 ? 2 : 1, chunkZ);
}
public BitSet getBitSet() {
public Optional<BitSet> getBitSet() {
if (v_1_18) { // Bitsets were removed in 1.18
return Optional.empty();
}
if (v_1_17) {
return readObject(0, BitSet.class);
return Optional.of(readObject(0, BitSet.class));
}
return BitSet.valueOf(new long[]{getPrimaryBitMask()});
}
@Deprecated
public void setPrimaryBitMap(int primaryBitMask) {
setPrimaryBitMask(primaryBitMask);
}
@Deprecated
public Integer getPrimaryBitMask() {
if (v_1_17) { // Possible lossy conversion
long[] bitset = readObject(0, BitSet.class).toLongArray();
return bitset.length == 0 ? 0 : (int) bitset[0];
}
if (v_1_8_x) {
if (nmsChunkMap == null) {
nmsChunkMap = readObject(0, chunkMapClass);
}
WrappedPacket nmsChunkMapWrapper = new WrappedPacket(new NMSPacket(nmsChunkMap));
return nmsChunkMapWrapper.readInt(0);
return Optional.of(BitSet.valueOf(new long[]{nmsChunkMapWrapper.readInt(0)}));
} else {
return readInt(2);
return Optional.of(BitSet.valueOf(new long[]{readInt(2)}));
}
}
/**
*
* @param bitSet Bitset that can hold multiple integer values to support the expanded world height on
* 1.17 and newer servers. This is due to 1.17 needing to support up to 127 chunk sections
* (2032 blocks) and an integer only being able to hold 32 bits to represent 32 chunk sections
*/
public void setPrimaryBitMask(BitSet bitSet) {
if (v_1_18) return; // Bitsets were removed in 1.18
if (v_1_17) {
writeObject(0, bitSet);
return;
}
setPrimaryBitMask((int) bitSet.toLongArray()[0]);
}
/**
*
* @param primaryBitMask Integer that determines which chunk sections the server is sending
*
* @deprecated Possible lossy conversion on 1.17 servers that could result in the client only reading 32
* out of the total possible 127 chunk sections. Safe to use on 1.16 and below servers
*/
@Deprecated
public void setPrimaryBitMask(int primaryBitMask) {
if (v_1_18) return; // Bitsets were removed in 1.18
if (v_1_17) {
writeObject(0, BitSet.valueOf(new long[] {primaryBitMask}));
writeObject(0, BitSet.valueOf(new long[]{primaryBitMask}));
return;
}
if (v_1_8_x) {
@@ -143,7 +136,6 @@ public class WrappedPacketOutMapChunk extends WrappedPacket {
}
/**
*
* @return Whether the packet overwrites the entire chunk column or just the sections being sent
*/
public Optional<Boolean> isGroundUpContinuous() {
@@ -154,7 +146,6 @@ public class WrappedPacketOutMapChunk extends WrappedPacket {
}
/**
*
* @param groundUpContinuous Whether the packet overwrites the entire chunk column or just the sections being sent
*/
public void setGroundUpContinuous(boolean groundUpContinuous) {
@@ -171,6 +162,8 @@ public class WrappedPacketOutMapChunk extends WrappedPacket {
}
WrappedPacket nmsChunkMapWrapper = new WrappedPacket(new NMSPacket(nmsChunkMap));
return nmsChunkMapWrapper.readByteArray(0);
} else if (v_1_18) {
return new WrappedPacket(new NMSPacket(readObject(0, chunkPacketDataClass))).readByteArray(0);
} else {
return readByteArray(0);
}
@@ -188,6 +181,8 @@ public class WrappedPacketOutMapChunk extends WrappedPacket {
WrappedPacket nmsChunkMapWrapper = new WrappedPacket(new NMSPacket(nmsChunkMap));
nmsChunkMapWrapper.writeByteArray(0, data);
write(chunkMapClass, 0, nmsChunkMap);
} else if (v_1_18) {
new WrappedPacket(new NMSPacket(readObject(0, chunkPacketDataClass))).writeByteArray(0, data);
} else {
writeByteArray(0, data);
}
@@ -340,6 +340,16 @@ public final class NMSUtils {
getBlockPosX = Reflection.getMethod(NMSUtils.blockPosClass.getSuperclass(), "getX", 0);
getBlockPosY = Reflection.getMethod(NMSUtils.blockPosClass.getSuperclass(), "getY", 0);
getBlockPosZ = Reflection.getMethod(NMSUtils.blockPosClass.getSuperclass(), "getZ", 0);
// Mappings changed with 1.18
if (getBlockPosX == null) {
getBlockPosX = Reflection.getMethod(NMSUtils.blockPosClass.getSuperclass(), "u", 0);
}
if (getBlockPosY == null) {
getBlockPosY = Reflection.getMethod(NMSUtils.blockPosClass.getSuperclass(), "v", 0);
}
if (getBlockPosZ == null) {
getBlockPosZ = Reflection.getMethod(NMSUtils.blockPosClass.getSuperclass(), "w", 0);
}
}
worldSettingsClass = NMSUtils.getNMSClassWithoutException("WorldSettings");
if (worldServerClass == null) {