2021-11-29 12:55:13 +01:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: stonar96 <minecraft.stonar96@gmail.com>
Date: Thu, 25 Nov 2021 13:27:51 +0100
Subject: [PATCH] Anti-Xray
2024-12-16 15:13:42 +01:00
diff --git a/io/papermc/paper/FeatureHooks.java b/io/papermc/paper/FeatureHooks.java
2024-12-23 10:28:19 +01:00
index 81ff677e970ffbe7ad5381e56852e33cf7a8ea45..184e6c6fe2ba522d0ea0774604839320c4152371 100644
2024-12-16 15:13:42 +01:00
--- a/io/papermc/paper/FeatureHooks.java
+++ b/io/papermc/paper/FeatureHooks.java
2024-12-23 10:28:19 +01:00
@@ -37,20 +37,25 @@ public final class FeatureHooks {
2024-12-05 14:44:50 +01:00
}
public static LevelChunkSection createSection(final Registry<Biome> biomeRegistry, final Level level, final ChunkPos chunkPos, final int chunkSection) {
- return new LevelChunkSection(biomeRegistry);
+ return new LevelChunkSection(biomeRegistry, level, chunkPos, chunkSection); // Paper - Anti-Xray - Add parameters
}
public static void sendChunkRefreshPackets(final List<ServerPlayer> playersInRange, final LevelChunk chunk) {
- final ClientboundLevelChunkWithLightPacket refreshPacket = new ClientboundLevelChunkWithLightPacket(chunk, chunk.level.getLightEngine(), null, null);
+ // Paper start - Anti-Xray
+ final Map<Object, ClientboundLevelChunkWithLightPacket> refreshPackets = new HashMap<>();
for (final ServerPlayer player : playersInRange) {
if (player.connection == null) continue;
- player.connection.send(refreshPacket);
+ final Boolean shouldModify = chunk.getLevel().chunkPacketBlockController.shouldModify(player, chunk);
+ player.connection.send(refreshPackets.computeIfAbsent(shouldModify, s -> { // Use connection to prevent creating firing event
+ return new ClientboundLevelChunkWithLightPacket(chunk, chunk.level.getLightEngine(), null, null, (Boolean) s);
+ }));
}
+ // Paper end - Anti-Xray
}
public static PalettedContainer<BlockState> emptyPalettedBlockContainer() {
- return new PalettedContainer<>(Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), PalettedContainer.Strategy.SECTION_STATES);
+ return new PalettedContainer<>(Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), PalettedContainer.Strategy.SECTION_STATES, null); // Paper - Anti-Xray - Add preset block states
}
public static Set<Long> getSentChunkKeys(final ServerPlayer player) {
2024-12-16 15:13:42 +01:00
diff --git a/net/minecraft/network/protocol/game/ClientboundChunksBiomesPacket.java b/net/minecraft/network/protocol/game/ClientboundChunksBiomesPacket.java
index d4872b7f4e9591b3b1c67406312905851303f521..cb41460e94161675e2ab43f4b1b5286ee38e2e13 100644
--- a/net/minecraft/network/protocol/game/ClientboundChunksBiomesPacket.java
+++ b/net/minecraft/network/protocol/game/ClientboundChunksBiomesPacket.java
@@ -70,8 +70,10 @@ public record ClientboundChunksBiomesPacket(List<ClientboundChunksBiomesPacket.C
2023-06-09 06:29:58 +02:00
}
2023-03-15 01:21:35 +01:00
2024-12-16 15:13:42 +01:00
public static void extractChunkData(FriendlyByteBuf buffer, LevelChunk chunk) {
2023-06-09 06:29:58 +02:00
+ int chunkSectionIndex = 0; // Paper - Anti-Xray
2024-04-12 21:14:06 +02:00
for (LevelChunkSection levelChunkSection : chunk.getSections()) {
2024-12-16 15:13:42 +01:00
- levelChunkSection.getBiomes().write(buffer);
+ levelChunkSection.getBiomes().write(buffer, null, chunkSectionIndex); // Paper - Anti-Xray
2023-06-09 06:29:58 +02:00
+ chunkSectionIndex++; // Paper - Anti-Xray
2023-03-15 01:21:35 +01:00
}
}
2024-04-12 21:14:06 +02:00
2024-12-16 15:13:42 +01:00
diff --git a/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java b/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
index 5d1943d37dfad0c12e77179f0866851532d983e9..3aea76690bc3e35758d3bf274777130af17d8a0f 100644
--- a/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
+++ b/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
@@ -28,7 +28,13 @@ public class ClientboundLevelChunkPacketData {
2024-01-23 18:01:39 +01:00
private final byte[] buffer;
private final List<ClientboundLevelChunkPacketData.BlockEntityInfo> blockEntitiesData;
2021-11-29 12:55:13 +01:00
+ // Paper start - Anti-Xray - Add chunk packet info
2024-12-16 15:13:42 +01:00
+ @Deprecated @io.papermc.paper.annotation.DoNotUse
public ClientboundLevelChunkPacketData(LevelChunk levelChunk) {
+ this(levelChunk, null);
+ }
+ public ClientboundLevelChunkPacketData(LevelChunk levelChunk, io.papermc.paper.antixray.ChunkPacketInfo<net.minecraft.world.level.block.state.BlockState> chunkPacketInfo) {
2021-11-29 12:55:13 +01:00
+ // Paper end
this.heightmaps = new CompoundTag();
2024-12-16 15:13:42 +01:00
for (Entry<Heightmap.Types, Heightmap> entry : levelChunk.getHeightmaps()) {
@@ -38,7 +44,11 @@ public class ClientboundLevelChunkPacketData {
2021-11-29 12:55:13 +01:00
}
2024-12-16 15:13:42 +01:00
this.buffer = new byte[calculateChunkSize(levelChunk)];
- extractChunkData(new FriendlyByteBuf(this.getWriteBuffer()), levelChunk);
2021-11-29 12:55:13 +01:00
+ // Paper start - Anti-Xray - Add chunk packet info
+ if (chunkPacketInfo != null) {
+ chunkPacketInfo.setBuffer(this.buffer);
+ }
2024-12-16 15:13:42 +01:00
+ extractChunkData(new FriendlyByteBuf(this.getWriteBuffer()), levelChunk, chunkPacketInfo);
2021-11-29 12:55:13 +01:00
this.blockEntitiesData = Lists.newArrayList();
2024-12-16 15:13:42 +01:00
for (Entry<BlockPos, BlockEntity> entryx : levelChunk.getBlockEntities().entrySet()) {
@@ -85,9 +95,17 @@ public class ClientboundLevelChunkPacketData {
2021-11-29 12:55:13 +01:00
return byteBuf;
}
+ // Paper start - Anti-Xray - Add chunk packet info
2024-12-16 15:13:42 +01:00
+ @Deprecated @io.papermc.paper.annotation.DoNotUse
public static void extractChunkData(FriendlyByteBuf buffer, LevelChunk chunk) {
+ ClientboundLevelChunkPacketData.extractChunkData(buffer, chunk, null);
+ }
+ public static void extractChunkData(FriendlyByteBuf buffer, LevelChunk chunk, io.papermc.paper.antixray.ChunkPacketInfo<net.minecraft.world.level.block.state.BlockState> chunkPacketInfo) {
2023-06-09 06:29:58 +02:00
+ int chunkSectionIndex = 0;
2024-04-12 21:14:06 +02:00
for (LevelChunkSection levelChunkSection : chunk.getSections()) {
2024-12-16 15:13:42 +01:00
- levelChunkSection.write(buffer);
+ levelChunkSection.write(buffer, chunkPacketInfo, chunkSectionIndex);
2023-06-09 06:29:58 +02:00
+ chunkSectionIndex++;
2024-12-16 15:13:42 +01:00
+ // Paper end - Anti-Xray - Add chunk packet info
2021-11-29 12:55:13 +01:00
}
}
2024-04-12 21:14:06 +02:00
2024-12-16 15:13:42 +01:00
diff --git a/net/minecraft/network/protocol/game/ClientboundLevelChunkWithLightPacket.java b/net/minecraft/network/protocol/game/ClientboundLevelChunkWithLightPacket.java
2024-12-16 15:44:33 +01:00
index 3a384175f8e7f204234bbaf3081bdc20c47a0d4b..5699bc15eba92e22433a20cb8326b59f2ebd3036 100644
2024-12-16 15:13:42 +01:00
--- a/net/minecraft/network/protocol/game/ClientboundLevelChunkWithLightPacket.java
+++ b/net/minecraft/network/protocol/game/ClientboundLevelChunkWithLightPacket.java
2024-12-16 15:44:33 +01:00
@@ -18,18 +18,31 @@ public class ClientboundLevelChunkWithLightPacket implements Packet<ClientGamePa
2021-11-29 12:55:13 +01:00
private final int z;
private final ClientboundLevelChunkPacketData chunkData;
private final ClientboundLightUpdatePacketData lightData;
2024-12-16 15:44:33 +01:00
- // Paper start - Anti-Xray
2024-12-16 15:13:42 +01:00
+ // Paper start - Async-Anti-Xray - Ready flag for the connection, add chunk packet info
2021-11-29 12:55:13 +01:00
+ private volatile boolean ready;
2024-12-16 15:44:33 +01:00
+
2021-11-29 12:55:13 +01:00
+ @Override
+ public boolean isReady() {
+ return this.ready;
+ }
+
2024-12-16 15:44:33 +01:00
public void setReady(final boolean ready) {
- // Empty hook, updated by feature patch
2021-11-29 12:55:13 +01:00
+ this.ready = ready;
2024-12-16 15:44:33 +01:00
}
- // Paper end - Anti-Xray
2024-12-16 15:13:42 +01:00
+ @Deprecated @io.papermc.paper.annotation.DoNotUse
public ClientboundLevelChunkWithLightPacket(LevelChunk chunk, LevelLightEngine lightEngine, @Nullable BitSet skyLight, @Nullable BitSet blockLight) {
+ this(chunk, lightEngine, skyLight, blockLight, true);
+ }
+ public ClientboundLevelChunkWithLightPacket(LevelChunk chunk, LevelLightEngine lightEngine, @Nullable BitSet skyLight, @Nullable BitSet blockLight, boolean modifyBlocks) {
+ // Paper end - Anti-Xray
ChunkPos pos = chunk.getPos();
this.x = pos.x;
this.z = pos.z;
2021-11-29 12:55:13 +01:00
- this.chunkData = new ClientboundLevelChunkPacketData(chunk);
2024-12-16 15:13:42 +01:00
+ io.papermc.paper.antixray.ChunkPacketInfo<net.minecraft.world.level.block.state.BlockState> chunkPacketInfo = modifyBlocks ? chunk.getLevel().chunkPacketBlockController.getChunkPacketInfo(this, chunk) : null; // Paper - Ant-Xray
+ this.chunkData = new ClientboundLevelChunkPacketData(chunk, chunkPacketInfo); // Paper - Anti-Xray
this.lightData = new ClientboundLightUpdatePacketData(pos, lightEngine, skyLight, blockLight);
2021-11-29 12:55:13 +01:00
+ chunk.getLevel().chunkPacketBlockController.modifyBlocks(this, chunkPacketInfo); // Paper - Anti-Xray - Modify blocks
}
2024-12-16 15:13:42 +01:00
private ClientboundLevelChunkWithLightPacket(RegistryFriendlyByteBuf buffer) {
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
2024-12-21 13:45:04 +01:00
index da8848e2a3e3745949eb2356a049451d30f763a7..192977dd661ee795ada13db895db770293e9b402 100644
2024-12-16 15:13:42 +01:00
--- a/net/minecraft/server/level/ServerLevel.java
+++ b/net/minecraft/server/level/ServerLevel.java
@@ -348,7 +348,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
org.bukkit.generator.BiomeProvider biomeProvider // CraftBukkit
) {
// CraftBukkit start
- super(serverLevelData, dimension, server.registryAccess(), levelStem.type(), false, isDebug, biomeZoomSeed, server.getMaxChainedNeighborUpdates(), gen, biomeProvider, env, spigotConfig -> server.paperConfigurations.createWorldConfig(io.papermc.paper.configuration.PaperConfigurations.createWorldContextMap(levelStorageAccess.levelDirectory.path(), serverLevelData.getLevelName(), dimension.location(), spigotConfig, server.registryAccess(), serverLevelData.getGameRules()))); // Paper - create paper world configs
+ super(serverLevelData, dimension, server.registryAccess(), levelStem.type(), false, isDebug, biomeZoomSeed, server.getMaxChainedNeighborUpdates(), gen, biomeProvider, env, spigotConfig -> server.paperConfigurations.createWorldConfig(io.papermc.paper.configuration.PaperConfigurations.createWorldContextMap(levelStorageAccess.levelDirectory.path(), serverLevelData.getLevelName(), dimension.location(), spigotConfig, server.registryAccess(), serverLevelData.getGameRules())), dispatcher); // Paper - create paper world configs; Async-Anti-Xray: Pass executor
this.pvpMode = server.isPvpAllowed();
this.levelStorageAccess = levelStorageAccess;
this.uuid = org.bukkit.craftbukkit.util.WorldUUID.getUUID(levelStorageAccess.levelDirectory.path().toFile());
diff --git a/net/minecraft/server/level/ServerPlayerGameMode.java b/net/minecraft/server/level/ServerPlayerGameMode.java
2024-12-21 13:45:04 +01:00
index 47ed3ad5c0b4753f58e0bafff5e5e70b2f0bb40b..623c069f1fe079e020c6391a3db1a3d95cd3dbf5 100644
2024-12-16 15:13:42 +01:00
--- a/net/minecraft/server/level/ServerPlayerGameMode.java
+++ b/net/minecraft/server/level/ServerPlayerGameMode.java
2024-12-21 13:45:04 +01:00
@@ -299,6 +299,7 @@ public class ServerPlayerGameMode {
2024-12-16 15:13:42 +01:00
org.bukkit.craftbukkit.event.CraftEventFactory.callBlockDamageAbortEvent(this.player, pos, this.player.getInventory().getSelected()); // CraftBukkit
2021-11-29 12:55:13 +01:00
}
}
2024-12-16 15:13:42 +01:00
+ this.level.chunkPacketBlockController.onPlayerLeftClickBlock(this, pos, action, face, maxBuildHeight, sequence); // Paper - Anti-Xray
2021-11-29 12:55:13 +01:00
}
2024-12-16 15:13:42 +01:00
public void destroyAndAck(BlockPos pos, int sequence, String message) {
diff --git a/net/minecraft/server/network/PlayerChunkSender.java b/net/minecraft/server/network/PlayerChunkSender.java
index 342bc843c384761e883de861044f4f8930ae8763..14878690a88fd4de3e2c127086607e6c819c636c 100644
--- a/net/minecraft/server/network/PlayerChunkSender.java
+++ b/net/minecraft/server/network/PlayerChunkSender.java
@@ -78,8 +78,11 @@ public class PlayerChunkSender {
2024-10-24 21:10:38 +02:00
}
2024-06-15 14:12:22 +02:00
}
2023-09-24 04:35:16 +02:00
2024-12-16 15:13:42 +01:00
- private static void sendChunk(ServerGamePacketListenerImpl packetListener, ServerLevel level, LevelChunk chunk) {
- packetListener.send(new ClientboundLevelChunkWithLightPacket(chunk, level.getLightEngine(), null, null));
+ // Paper start - Anti-Xray
+ public static void sendChunk(ServerGamePacketListenerImpl packetListener, ServerLevel level, LevelChunk chunk) {
+ final boolean shouldModify = level.chunkPacketBlockController.shouldModify(packetListener.player, chunk);
+ packetListener.send(new ClientboundLevelChunkWithLightPacket(chunk, level.getLightEngine(), null, null, shouldModify));
2023-09-24 04:35:16 +02:00
+ // Paper end - Anti-Xray
2024-01-23 15:43:48 +01:00
// Paper start - PlayerChunkLoadEvent
if (io.papermc.paper.event.packet.PlayerChunkLoadEvent.getHandlerList().getRegisteredListeners().length > 0) {
2024-12-16 15:13:42 +01:00
new io.papermc.paper.event.packet.PlayerChunkLoadEvent(new org.bukkit.craftbukkit.CraftChunk(chunk), packetListener.getPlayer().getBukkitEntity()).callEvent();
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
2024-12-23 10:28:19 +01:00
index 600a08d6b45cb19dbe551cefbf726e68684a0837..ff0315cffdb282fdc0a1ffd15e2954caa76835c9 100644
2024-12-16 15:13:42 +01:00
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
2024-12-21 12:15:25 +01:00
@@ -403,7 +403,7 @@ public abstract class PlayerList {
2024-10-25 13:52:04 +02:00
.getOrThrow(net.minecraft.world.level.biome.Biomes.PLAINS);
2024-01-23 18:01:39 +01:00
player.connection.send(new net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket(
2024-12-16 15:13:42 +01:00
new net.minecraft.world.level.chunk.EmptyLevelChunk(serverLevel, player.chunkPosition(), plains),
- serverLevel.getLightEngine(), (java.util.BitSet)null, (java.util.BitSet) null)
+ serverLevel.getLightEngine(), (java.util.BitSet)null, (java.util.BitSet) null, true) // Paper - Anti-Xray
2024-01-23 18:01:39 +01:00
);
}
// Paper end - Send empty chunk
2024-12-16 15:13:42 +01:00
diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java
2024-12-21 13:45:04 +01:00
index 0f346faa82b988e86834c38837f6f11bea7f31c6..771d6ed6a7c889c09efd4ff6e20298c851eaa79f 100644
2024-12-16 15:13:42 +01:00
--- a/net/minecraft/world/level/Level.java
+++ b/net/minecraft/world/level/Level.java
@@ -168,6 +168,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2022-06-09 10:51:45 +02:00
}
2024-01-13 21:31:02 +01:00
// Paper end - add paper world config
2021-11-29 12:55:13 +01:00
2024-12-16 15:13:42 +01:00
+ public final io.papermc.paper.antixray.ChunkPacketBlockController chunkPacketBlockController; // Paper - Anti-Xray
2021-11-29 12:55:13 +01:00
public static BlockPos lastPhysicsProblem; // Spigot
2022-06-09 10:51:45 +02:00
private org.spigotmc.TickLimiter entityLimiter;
2024-10-27 18:11:15 +01:00
private org.spigotmc.TickLimiter tileLimiter;
2024-12-16 15:13:42 +01:00
@@ -214,7 +215,8 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
org.bukkit.generator.BiomeProvider biomeProvider, // CraftBukkit
org.bukkit.World.Environment env, // CraftBukkit
java.util.function.Function<org.spigotmc.SpigotWorldConfig, // Spigot - create per world config
- io.papermc.paper.configuration.WorldConfiguration> paperWorldConfigCreator // Paper - create paper world config
+ io.papermc.paper.configuration.WorldConfiguration> paperWorldConfigCreator, // Paper - create paper world config
+ java.util.concurrent.Executor executor // Paper - Anti-Xray
) {
this.spigotConfig = new org.spigotmc.SpigotWorldConfig(((net.minecraft.world.level.storage.PrimaryLevelData) levelData).getLevelName()); // Spigot
2024-01-13 21:31:02 +01:00
this.paperConfig = paperWorldConfigCreator.apply(this.spigotConfig); // Paper - create paper world config
2024-12-16 15:13:42 +01:00
@@ -295,6 +297,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2024-10-27 18:11:15 +01:00
// CraftBukkit end
2024-10-24 21:10:38 +02:00
this.entityLimiter = new org.spigotmc.TickLimiter(this.spigotConfig.entityMaxTickTime);
this.tileLimiter = new org.spigotmc.TickLimiter(this.spigotConfig.tileMaxTickTime);
2024-12-16 15:13:42 +01:00
+ this.chunkPacketBlockController = this.paperConfig().anticheat.antiXray.enabled ? new io.papermc.paper.antixray.ChunkPacketBlockControllerAntiXray(this, executor) : io.papermc.paper.antixray.ChunkPacketBlockController.NO_OPERATION_INSTANCE; // Paper - Anti-Xray
2021-11-29 12:55:13 +01:00
}
2024-01-21 17:39:05 +01:00
// Paper start - Cancel hit for vanished players
2024-12-16 15:13:42 +01:00
@@ -495,6 +498,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {
2021-11-29 12:55:13 +01:00
// CraftBukkit end
2024-12-16 15:13:42 +01:00
BlockState blockState = chunkAt.setBlockState(pos, state, (flags & 64) != 0, (flags & 1024) == 0); // CraftBukkit custom NO_PLACE flag
+ this.chunkPacketBlockController.onBlockChange(this, pos, state, blockState, flags, recursionLeft); // Paper - Anti-Xray
2021-11-29 12:55:13 +01:00
2024-12-16 15:13:42 +01:00
if (blockState == null) {
2021-11-29 12:55:13 +01:00
// CraftBukkit start - remove blockstate if failed (or the same)
2024-12-16 15:13:42 +01:00
diff --git a/net/minecraft/world/level/chunk/ChunkAccess.java b/net/minecraft/world/level/chunk/ChunkAccess.java
2024-12-27 13:45:04 +01:00
index c82780db7fe5b1557a7802d3111f38099be55ac1..d63d745a0220963a297cfedf1e8983aeb471a045 100644
2024-12-16 15:13:42 +01:00
--- a/net/minecraft/world/level/chunk/ChunkAccess.java
+++ b/net/minecraft/world/level/chunk/ChunkAccess.java
@@ -114,14 +114,14 @@ public abstract class ChunkAccess implements BiomeManager.NoiseBiomeSource, Ligh
2022-07-18 12:30:31 +02:00
}
}
2024-12-16 15:13:42 +01:00
- replaceMissingSections(biomeRegistry, this.sections);
2023-06-09 06:29:58 +02:00
+ this.replaceMissingSections(biomeRegistry, this.sections); // Paper - Anti-Xray - make it a non-static method
2024-12-18 19:09:46 +01:00
this.biomeRegistry = biomeRegistry; // CraftBukkit
2024-10-24 21:10:38 +02:00
}
2022-07-18 12:30:31 +02:00
2024-12-16 15:13:42 +01:00
- private static void replaceMissingSections(Registry<Biome> biomeRegistry, LevelChunkSection[] sections) {
+ private void replaceMissingSections(Registry<Biome> biomeRegistry, LevelChunkSection[] sections) { // Paper - Anti-Xray - make it a non-static method
for (int i = 0; i < sections.length; i++) {
if (sections[i] == null) {
- sections[i] = new LevelChunkSection(biomeRegistry);
+ sections[i] = new LevelChunkSection(biomeRegistry, this.levelHeightAccessor instanceof net.minecraft.world.level.Level ? (net.minecraft.world.level.Level) this.levelHeightAccessor : null, this.chunkPos, this.levelHeightAccessor.getSectionYFromSectionIndex(i)); // Paper - Anti-Xray - Add parameters
2021-11-29 12:55:13 +01:00
}
}
}
2024-12-16 15:13:42 +01:00
diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java
2024-12-27 13:45:04 +01:00
index ce781ba2c8b3f9f051201d3809a9cb041036f93a..cad71ac79fc52225a192aa5c5d07b13c831fc2c1 100644
2024-12-16 15:13:42 +01:00
--- a/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/net/minecraft/world/level/chunk/LevelChunk.java
@@ -109,7 +109,7 @@ public class LevelChunk extends ChunkAccess {
@Nullable LevelChunk.PostLoadProcessor postLoad,
@Nullable BlendingData blendingData
) {
- super(pos, data, level, level.registryAccess().lookupOrThrow(Registries.BIOME), inhabitedTime, sections, blendingData);
+ super(pos, data, level, net.minecraft.server.MinecraftServer.getServer().registryAccess().lookupOrThrow(Registries.BIOME), inhabitedTime, sections, blendingData); // Paper - Anti-Xray - The world isn't ready yet, use server singleton for registry
2024-12-27 13:45:04 +01:00
this.level = (ServerLevel) level; // CraftBukkit - type
2024-12-16 15:13:42 +01:00
this.gameEventListenerRegistrySections = new Int2ObjectOpenHashMap<>();
diff --git a/net/minecraft/world/level/chunk/LevelChunkSection.java b/net/minecraft/world/level/chunk/LevelChunkSection.java
2024-12-27 13:45:04 +01:00
index b3d600b0d6deaf44f232dfc86e1456c867e1c07f..a7fabde0f32f09d7f7bed65576ce469f069a21fa 100644
2024-12-16 15:13:42 +01:00
--- a/net/minecraft/world/level/chunk/LevelChunkSection.java
+++ b/net/minecraft/world/level/chunk/LevelChunkSection.java
@@ -38,9 +38,15 @@ public class LevelChunkSection {
2021-11-29 12:55:13 +01:00
this.recalcBlockCounts();
}
2024-12-16 15:13:42 +01:00
+ // Paper start - Anti-Xray - Add parameters
+ @Deprecated @io.papermc.paper.annotation.DoNotUse
public LevelChunkSection(Registry<Biome> biomeRegistry) {
2021-11-29 12:55:13 +01:00
- this.states = new PalettedContainer<>(Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), PalettedContainer.Strategy.SECTION_STATES);
2024-10-24 21:10:38 +02:00
- this.biomes = new PalettedContainer<>(biomeRegistry.asHolderIdMap(), biomeRegistry.getOrThrow(Biomes.PLAINS), PalettedContainer.Strategy.SECTION_BIOMES);
2024-12-16 15:13:42 +01:00
+ this(biomeRegistry, null, null, 0);
+ }
2023-06-09 06:29:58 +02:00
+ public LevelChunkSection(Registry<Biome> biomeRegistry, net.minecraft.world.level.Level level, net.minecraft.world.level.ChunkPos chunkPos, int chunkSectionY) {
2024-12-16 15:13:42 +01:00
+ // Paper end - Anti-Xray
2023-06-09 06:29:58 +02:00
+ this.states = new PalettedContainer<>(Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), PalettedContainer.Strategy.SECTION_STATES, level == null || level.chunkPacketBlockController == null ? null : level.chunkPacketBlockController.getPresetBlockStates(level, chunkPos, chunkSectionY)); // Paper - Anti-Xray - Add preset block states
2024-10-24 21:10:38 +02:00
+ this.biomes = new PalettedContainer<>(biomeRegistry.asHolderIdMap(), biomeRegistry.getOrThrow(Biomes.PLAINS), PalettedContainer.Strategy.SECTION_BIOMES, null); // Paper - Anti-Xray - Add preset biomes
2021-11-29 12:55:13 +01:00
}
2023-06-09 06:29:58 +02:00
public BlockState getBlockState(int x, int y, int z) {
2024-12-16 15:13:42 +01:00
@@ -168,10 +174,16 @@ public class LevelChunkSection {
this.biomes = palettedContainer;
2021-11-29 12:55:13 +01:00
}
+ // Paper start - Anti-Xray - Add chunk packet info
2024-12-16 15:13:42 +01:00
+ @Deprecated @io.papermc.paper.annotation.DoNotUse
public void write(FriendlyByteBuf buffer) {
+ this.write(buffer, null, 0);
+ }
+ public void write(FriendlyByteBuf buffer, io.papermc.paper.antixray.ChunkPacketInfo<BlockState> chunkPacketInfo, int chunkSectionIndex) {
buffer.writeShort(this.nonEmptyBlockCount);
- this.states.write(buffer);
- this.biomes.write(buffer);
+ this.states.write(buffer, chunkPacketInfo, chunkSectionIndex);
+ this.biomes.write(buffer, null, chunkSectionIndex);
+ // Paper end - Anti-Xray
2021-11-29 12:55:13 +01:00
}
public int getSerializedSize() {
2024-12-16 15:13:42 +01:00
diff --git a/net/minecraft/world/level/chunk/PalettedContainer.java b/net/minecraft/world/level/chunk/PalettedContainer.java
index e8ec28ce3fe13561b45c4654e174776d9d2d7b71..a6028a54c75de068515e95913b21160ab4326985 100644
--- a/net/minecraft/world/level/chunk/PalettedContainer.java
+++ b/net/minecraft/world/level/chunk/PalettedContainer.java
@@ -28,6 +28,7 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
2024-04-12 21:14:06 +02:00
private static final int MIN_PALETTE_BITS = 0;
2024-12-16 15:13:42 +01:00
private final PaletteResize<T> dummyPaletteResize = (bits, objectAdded) -> 0;
2021-11-29 12:55:13 +01:00
public final IdMap<T> registry;
2022-03-01 04:25:13 +01:00
+ private final T @org.jetbrains.annotations.Nullable [] presetValues; // Paper - Anti-Xray - Add preset values
2024-10-24 21:10:38 +02:00
private volatile PalettedContainer.Data<T> data;
2021-11-29 12:55:13 +01:00
private final PalettedContainer.Strategy strategy;
2024-12-16 15:13:42 +01:00
//private final ThreadingDetector threadingDetector = new ThreadingDetector("PalettedContainer"); // Paper - unused
@@ -40,13 +41,21 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
// this.threadingDetector.checkAndUnlock(); // Paper - disable this - use proper synchronization
2021-11-29 12:55:13 +01:00
}
2022-07-18 12:30:31 +02:00
+ // Paper start - Anti-Xray - Add preset values
2024-12-16 15:13:42 +01:00
+ @Deprecated @io.papermc.paper.annotation.DoNotUse
public static <T> Codec<PalettedContainer<T>> codecRW(IdMap<T> registry, Codec<T> codec, PalettedContainer.Strategy strategy, T value) {
- PalettedContainerRO.Unpacker<T, PalettedContainer<T>> unpacker = PalettedContainer::unpack;
+ return PalettedContainer.codecRW(registry, codec, strategy, value, null);
+ }
+ public static <T> Codec<PalettedContainer<T>> codecRW(IdMap<T> registry, Codec<T> codec, PalettedContainer.Strategy strategy, T value, T @org.jetbrains.annotations.Nullable [] presetValues) {
2022-07-28 10:30:32 +02:00
+ PalettedContainerRO.Unpacker<T, PalettedContainer<T>> unpacker = (idListx, paletteProviderx, serialized) -> {
2024-12-16 15:13:42 +01:00
+ return unpack(idListx, paletteProviderx, serialized, value, presetValues);
2022-07-18 12:30:31 +02:00
+ };
+ // Paper end
2024-12-16 15:13:42 +01:00
return codec(registry, codec, strategy, value, unpacker);
2022-06-08 05:40:53 +02:00
}
2022-07-27 22:46:05 +02:00
2024-12-16 15:13:42 +01:00
public static <T> Codec<PalettedContainerRO<T>> codecRO(IdMap<T> registry, Codec<T> codec, PalettedContainer.Strategy strategy, T value) {
- PalettedContainerRO.Unpacker<T, PalettedContainerRO<T>> unpacker = (registry1, strategy1, packedData) -> unpack(registry1, strategy1, packedData)
+ PalettedContainerRO.Unpacker<T, PalettedContainerRO<T>> unpacker = (registry1, strategy1, packedData) -> unpack(registry1, strategy1, packedData, value, null) // Paper - Anti-Xray - Add preset values
.map(container -> (PalettedContainerRO<T>)container);
return codec(registry, codec, strategy, value, unpacker);
}
@@ -66,27 +75,66 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
2024-04-12 21:14:06 +02:00
);
2021-11-29 12:55:13 +01:00
}
+ // Paper start - Anti-Xray - Add preset values
2024-12-16 15:13:42 +01:00
+ @Deprecated @io.papermc.paper.annotation.DoNotUse
+ public PalettedContainer(IdMap<T> registry, PalettedContainer.Strategy strategy, PalettedContainer.Configuration<T> configuration, BitStorage storage, List<T> values) {
+ this(registry, strategy, configuration, storage, values, null, null);
+ }
2024-04-12 21:14:06 +02:00
public PalettedContainer(
2024-12-16 15:13:42 +01:00
- IdMap<T> registry, PalettedContainer.Strategy strategy, PalettedContainer.Configuration<T> configuration, BitStorage storage, List<T> values
+ IdMap<T> registry, PalettedContainer.Strategy strategy, PalettedContainer.Configuration<T> configuration, BitStorage storage, List<T> values, T defaultValue, T @org.jetbrains.annotations.Nullable [] presetValues
2024-04-12 21:14:06 +02:00
) {
2021-11-29 12:55:13 +01:00
+ this.presetValues = presetValues;
2024-12-16 15:13:42 +01:00
this.registry = registry;
this.strategy = strategy;
this.data = new PalettedContainer.Data<>(configuration, storage, configuration.factory().create(configuration.bits(), registry, this, values));
+ if (presetValues != null && (configuration.factory() == PalettedContainer.Strategy.SINGLE_VALUE_PALETTE_FACTORY ? this.data.palette.valueFor(0) != defaultValue : configuration.factory() != PalettedContainer.Strategy.GLOBAL_PALETTE_FACTORY)) {
2021-11-29 12:55:13 +01:00
+ // In 1.18 Mojang unfortunately removed code that already handled possible resize operations on read from disk for us
+ // We readd this here but in a smarter way than it was before
2024-12-16 15:13:42 +01:00
+ int maxSize = 1 << configuration.bits();
2021-11-29 12:55:13 +01:00
+
+ for (T presetValue : presetValues) {
+ if (this.data.palette.getSize() >= maxSize) {
2024-12-16 15:13:42 +01:00
+ java.util.Set<T> allValues = new java.util.HashSet<>(values);
2021-11-29 12:55:13 +01:00
+ allValues.addAll(Arrays.asList(presetValues));
+ int newBits = Mth.ceillog2(allValues.size());
+
2024-12-16 15:13:42 +01:00
+ if (newBits > configuration.bits()) {
2021-11-29 12:55:13 +01:00
+ this.onResize(newBits, null);
+ }
+
+ break;
+ }
+
+ this.data.palette.idFor(presetValue);
+ }
+ }
+ // Paper end
}
2024-12-16 15:13:42 +01:00
- private PalettedContainer(IdMap<T> registry, PalettedContainer.Strategy strategy, PalettedContainer.Data<T> data) {
2021-11-29 12:55:13 +01:00
+ // Paper start - Anti-Xray - Add preset values
2024-12-16 15:13:42 +01:00
+ private PalettedContainer(IdMap<T> registry, PalettedContainer.Strategy strategy, PalettedContainer.Data<T> data, T @org.jetbrains.annotations.Nullable [] presetValues) {
2021-11-29 12:55:13 +01:00
+ this.presetValues = presetValues;
2024-12-16 15:13:42 +01:00
+ // Paper end - Anti-Xray
this.registry = registry;
this.strategy = strategy;
2021-11-29 12:55:13 +01:00
this.data = data;
}
2024-12-16 15:13:42 +01:00
- private PalettedContainer(PalettedContainer<T> other) {
+ private PalettedContainer(PalettedContainer<T> other, T @org.jetbrains.annotations.Nullable [] presetValues) { // Paper - Anti-Xray - Add preset values
2024-10-24 21:10:38 +02:00
+ this.presetValues = presetValues; // Paper - Anti-Xray - Add preset values
2024-12-16 15:13:42 +01:00
this.registry = other.registry;
this.strategy = other.strategy;
this.data = other.data.copy(this);
2024-10-24 21:10:38 +02:00
}
2021-11-29 12:55:13 +01:00
+ // Paper start - Anti-Xray - Add preset values
2024-12-16 15:13:42 +01:00
+ @Deprecated @io.papermc.paper.annotation.DoNotUse
public PalettedContainer(IdMap<T> registry, T palette, PalettedContainer.Strategy strategy) {
+ this(registry, palette, strategy, null);
+ }
+ public PalettedContainer(IdMap<T> registry, T palette, PalettedContainer.Strategy strategy, T @org.jetbrains.annotations.Nullable [] presetValues) {
2021-11-29 12:55:13 +01:00
+ this.presetValues = presetValues;
2024-12-16 15:13:42 +01:00
+ // Paper end - Anti-Xray
this.strategy = strategy;
this.registry = registry;
2024-04-12 21:14:06 +02:00
this.data = this.createOrReuseData(null, 0);
2024-12-16 15:13:42 +01:00
@@ -101,11 +149,30 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
2021-11-29 12:55:13 +01:00
@Override
2024-12-16 15:13:42 +01:00
public synchronized int onResize(int bits, T objectAdded) { // Paper - synchronize
2021-11-29 12:55:13 +01:00
PalettedContainer.Data<T> data = this.data;
+ // Paper start - Anti-Xray - Add preset values
2024-12-16 15:13:42 +01:00
+ if (this.presetValues != null && objectAdded != null && data.configuration().factory() == PalettedContainer.Strategy.SINGLE_VALUE_PALETTE_FACTORY) {
2021-11-29 12:55:13 +01:00
+ int duplicates = 0;
+ List<T> presetValues = Arrays.asList(this.presetValues);
2024-12-16 15:13:42 +01:00
+ duplicates += presetValues.contains(objectAdded) ? 1 : 0;
2021-11-29 12:55:13 +01:00
+ duplicates += presetValues.contains(data.palette.valueFor(0)) ? 1 : 0;
2024-12-16 15:13:42 +01:00
+ bits = Mth.ceillog2((1 << this.strategy.calculateBitsForSerialization(this.registry, 1 << bits)) + presetValues.size() - duplicates);
2021-11-29 12:55:13 +01:00
+ }
2024-12-16 15:13:42 +01:00
+ // Paper end - Anti-Xray
PalettedContainer.Data<T> data1 = this.createOrReuseData(data, bits);
data1.copyFrom(data.palette, data.storage);
this.data = data1;
- return data1.palette.idFor(objectAdded);
+ // Paper start - Anti-Xray
2021-11-29 12:55:13 +01:00
+ this.addPresetValues();
2024-12-16 15:13:42 +01:00
+ return objectAdded == null ? -1 : data1.palette.idFor(objectAdded);
2023-03-23 22:57:03 +01:00
+ }
2021-11-29 12:55:13 +01:00
+ private void addPresetValues() {
+ if (this.presetValues != null && this.data.configuration().factory() != PalettedContainer.Strategy.GLOBAL_PALETTE_FACTORY) {
+ for (T presetValue : this.presetValues) {
+ this.data.palette.idFor(presetValue);
+ }
+ }
2023-03-23 22:57:03 +01:00
}
2024-12-16 15:13:42 +01:00
+ // Paper end - Anti-Xray
2023-03-23 22:57:03 +01:00
2024-12-16 15:13:42 +01:00
public synchronized T getAndSet(int x, int y, int z, T state) { // Paper - synchronize
2021-11-29 12:55:13 +01:00
this.acquire();
2024-12-16 15:13:42 +01:00
@@ -172,24 +239,35 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
data.palette.read(buffer);
buffer.readLongArray(data.storage.getRaw());
2021-11-29 12:55:13 +01:00
this.data = data;
2022-07-18 12:30:31 +02:00
+ this.addPresetValues(); // Paper - Anti-Xray - Add preset values (inefficient, but this isn't used by the server)
2021-11-29 12:55:13 +01:00
} finally {
this.release();
}
}
2024-01-23 15:43:48 +01:00
+ // Paper start - Anti-Xray; Add chunk packet info
2022-07-18 12:30:31 +02:00
@Override
2024-12-16 15:13:42 +01:00
- public synchronized void write(FriendlyByteBuf buffer) { // Paper - synchronize
+ @Deprecated @io.papermc.paper.annotation.DoNotUse
+ public void write(FriendlyByteBuf buffer) {
+ this.write(buffer, null, 0);
+ }
+ @Override
+ public synchronized void write(FriendlyByteBuf buffer, @Nullable io.papermc.paper.antixray.ChunkPacketInfo<T> chunkPacketInfo, int chunkSectionIndex) { // Paper - Synchronize
2021-11-29 12:55:13 +01:00
this.acquire();
try {
2024-12-16 15:13:42 +01:00
- this.data.write(buffer);
+ this.data.write(buffer, chunkPacketInfo, chunkSectionIndex);
2021-11-29 12:55:13 +01:00
+ if (chunkPacketInfo != null) {
+ chunkPacketInfo.setPresetValues(chunkSectionIndex, this.presetValues);
+ }
2024-12-16 15:13:42 +01:00
+ // Paper end - Anti-Xray
2021-11-29 12:55:13 +01:00
} finally {
this.release();
}
}
2024-04-12 21:14:06 +02:00
private static <T> DataResult<PalettedContainer<T>> unpack(
2024-12-16 15:13:42 +01:00
- IdMap<T> registry, PalettedContainer.Strategy strategy, PalettedContainerRO.PackedData<T> packedData
+ IdMap<T> registry, PalettedContainer.Strategy strategy, PalettedContainerRO.PackedData<T> packedData, T defaultValue, T @org.jetbrains.annotations.Nullable [] presetValues // Paper - Anti-Xray - Add preset values
2024-04-12 21:14:06 +02:00
) {
2024-12-16 15:13:42 +01:00
List<T> list = packedData.paletteEntries();
int size = strategy.size();
@@ -222,7 +300,7 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
2021-11-29 12:55:13 +01:00
}
}
2024-12-16 15:13:42 +01:00
- return DataResult.success(new PalettedContainer<>(registry, strategy, configuration, bitStorage, list));
+ return DataResult.success(new PalettedContainer<>(registry, strategy, configuration, bitStorage, list, defaultValue, presetValues)); // Paper - Anti-Xray - Add preset values
2021-11-29 12:55:13 +01:00
}
2022-06-08 05:40:53 +02:00
@Override
2024-12-16 15:13:42 +01:00
@@ -280,12 +358,12 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
2021-11-29 12:55:13 +01:00
2024-10-24 21:10:38 +02:00
@Override
2021-11-29 12:55:13 +01:00
public PalettedContainer<T> copy() {
2024-10-24 21:10:38 +02:00
- return new PalettedContainer<>(this);
+ return new PalettedContainer<>(this, this.presetValues); // Paper - Anti-Xray - Add preset values
2021-11-29 12:55:13 +01:00
}
2022-07-18 12:30:31 +02:00
@Override
public PalettedContainer<T> recreate() {
- return new PalettedContainer<>(this.registry, this.data.palette.valueFor(0), this.strategy);
+ return new PalettedContainer<>(this.registry, this.data.palette.valueFor(0), this.strategy, this.presetValues); // Paper - Anti-Xray - Add preset values
}
2022-06-08 05:40:53 +02:00
@Override
2024-12-16 15:13:42 +01:00
@@ -324,9 +402,16 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
2023-09-24 04:35:16 +02:00
return 1 + this.palette.getSerializedSize() + VarInt.getByteSize(this.storage.getRaw().length) + this.storage.getRaw().length * 8;
2021-11-29 12:55:13 +01:00
}
2024-12-16 15:13:42 +01:00
- public void write(FriendlyByteBuf buffer) {
2021-11-29 12:55:13 +01:00
+ // Paper start - Anti-Xray - Add chunk packet info
2024-12-16 15:13:42 +01:00
+ public void write(FriendlyByteBuf buffer, @Nullable io.papermc.paper.antixray.ChunkPacketInfo<T> chunkPacketInfo, int chunkSectionIndex) {
buffer.writeByte(this.storage.getBits());
this.palette.write(buffer);
2021-11-29 12:55:13 +01:00
+ if (chunkPacketInfo != null) {
+ chunkPacketInfo.setBits(chunkSectionIndex, this.configuration.bits());
+ chunkPacketInfo.setPalette(chunkSectionIndex, this.palette);
2024-12-16 15:13:42 +01:00
+ chunkPacketInfo.setIndex(chunkSectionIndex, buffer.writerIndex() + VarInt.getByteSize(this.storage.getRaw().length));
2021-11-29 12:55:13 +01:00
+ }
+ // Paper end
2024-12-16 15:13:42 +01:00
buffer.writeLongArray(this.storage.getRaw());
2021-11-29 12:55:13 +01:00
}
2022-06-08 05:40:53 +02:00
2024-12-16 15:13:42 +01:00
diff --git a/net/minecraft/world/level/chunk/PalettedContainerRO.java b/net/minecraft/world/level/chunk/PalettedContainerRO.java
index bfbb1a2bb4abbb369a24f2f01439e9ea3e16794b..8d6ed8be4d93f7d4e6ea80c351020d88ee98aa4d 100644
--- a/net/minecraft/world/level/chunk/PalettedContainerRO.java
+++ b/net/minecraft/world/level/chunk/PalettedContainerRO.java
@@ -14,7 +14,10 @@ public interface PalettedContainerRO<T> {
2022-07-18 12:30:31 +02:00
2024-12-16 15:13:42 +01:00
void getAll(Consumer<T> consumer);
2022-07-18 12:30:31 +02:00
2024-12-16 15:13:42 +01:00
- void write(FriendlyByteBuf buffer);
2022-07-18 12:30:31 +02:00
+ // Paper start - Anti-Xray - Add chunk packet info
2024-12-16 15:13:42 +01:00
+ @Deprecated @io.papermc.paper.annotation.DoNotUse void write(FriendlyByteBuf buffer);
+ void write(FriendlyByteBuf buffer, @javax.annotation.Nullable io.papermc.paper.antixray.ChunkPacketInfo<T> chunkPacketInfo, int chunkSectionIndex);
2022-07-18 12:30:31 +02:00
+ // Paper end
int getSerializedSize();
2024-12-16 15:13:42 +01:00
diff --git a/net/minecraft/world/level/chunk/storage/SerializableChunkData.java b/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
2024-12-27 13:45:04 +01:00
index c7c87bc8df86ceeef3e15a8f23fc252d4cee1984..3b55e7fb27d680204b8621666ae9200870def3eb 100644
2024-12-16 15:13:42 +01:00
--- a/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
+++ b/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
@@ -94,7 +94,7 @@ public record SerializableChunkData(
, @Nullable net.minecraft.nbt.Tag persistentDataContainer // CraftBukkit - persistentDataContainer
) {
public static final Codec<PalettedContainer<BlockState>> BLOCK_STATE_CODEC = PalettedContainer.codecRW(
- Block.BLOCK_STATE_REGISTRY, BlockState.CODEC, PalettedContainer.Strategy.SECTION_STATES, Blocks.AIR.defaultBlockState()
+ Block.BLOCK_STATE_REGISTRY, BlockState.CODEC, PalettedContainer.Strategy.SECTION_STATES, Blocks.AIR.defaultBlockState(), null // Paper - Anti-Xray
);
2024-10-25 19:15:40 +02:00
private static final Logger LOGGER = LogUtils.getLogger();
private static final String TAG_UPGRADE_DATA = "UpgradeData";
2024-12-16 15:13:42 +01:00
@@ -128,6 +128,7 @@ public record SerializableChunkData(
2021-11-29 12:55:13 +01:00
2024-10-24 21:10:38 +02:00
@Nullable
2024-12-16 15:13:42 +01:00
public static SerializableChunkData parse(LevelHeightAccessor levelHeightAccessor, RegistryAccess registries, CompoundTag tag) {
+ net.minecraft.server.level.ServerLevel serverLevel = (net.minecraft.server.level.ServerLevel) levelHeightAccessor; // Paper - Anti-Xray This is is seemingly only called from ChunkMap, where, we have a server level. We'll fight this later if needed.
if (!tag.contains("Status", 8)) {
2024-10-24 21:10:38 +02:00
return null;
} else {
2024-12-16 15:13:42 +01:00
@@ -212,18 +213,21 @@ public record SerializableChunkData(
Codec<PalettedContainer<Holder<Biome>>> codec = makeBiomeCodecRW(registry); // CraftBukkit - read/write
for (int i2 = 0; i2 < list7.size(); i2++) {
- CompoundTag compound2 = list7.getCompound(i2);
+ CompoundTag compound2 = list7.getCompound(i2); final CompoundTag sectionData = compound2; // Paper - Anti-Xray - OBFHELPER
int _byte = compound2.getByte("Y");
LevelChunkSection levelChunkSection;
if (_byte >= levelHeightAccessor.getMinSectionY() && _byte <= levelHeightAccessor.getMaxSectionY()) {
2024-10-24 21:10:38 +02:00
+ // Paper start - Anti-Xray - Add preset block states
2024-12-16 15:13:42 +01:00
+ BlockState[] presetBlockStates = serverLevel.chunkPacketBlockController.getPresetBlockStates(serverLevel, chunkPos, _byte);
PalettedContainer<BlockState> palettedContainer;
if (compound2.contains("block_states", 10)) {
- palettedContainer = BLOCK_STATE_CODEC.parse(NbtOps.INSTANCE, compound2.getCompound("block_states"))
2024-10-25 14:55:49 +02:00
+ Codec<PalettedContainer<BlockState>> blockStateCodec = presetBlockStates == null ? BLOCK_STATE_CODEC : PalettedContainer.codecRW(Block.BLOCK_STATE_REGISTRY, BlockState.CODEC, PalettedContainer.Strategy.SECTION_STATES, Blocks.AIR.defaultBlockState(), presetBlockStates); // Paper - Anti-Xray
2024-12-16 15:13:42 +01:00
+ palettedContainer = blockStateCodec.parse(NbtOps.INSTANCE, sectionData.getCompound("block_states")) // Paper - Anti-Xray
.promotePartial(string -> logErrors(chunkPos, _byte, string))
.getOrThrow(SerializableChunkData.ChunkReadException::new);
2024-10-24 21:10:38 +02:00
} else {
2024-12-16 15:13:42 +01:00
palettedContainer = new PalettedContainer<>(
- Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), PalettedContainer.Strategy.SECTION_STATES
+ Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), PalettedContainer.Strategy.SECTION_STATES, presetBlockStates // Paper - Anti-Xray
);
2024-10-24 21:10:38 +02:00
}
2021-11-29 12:55:13 +01:00
2024-12-16 15:13:42 +01:00
@@ -234,7 +238,7 @@ public record SerializableChunkData(
.getOrThrow(SerializableChunkData.ChunkReadException::new);
2024-10-24 21:10:38 +02:00
} else {
2024-12-16 15:13:42 +01:00
palettedContainerRo = new PalettedContainer<>(
- registry.asHolderIdMap(), registry.getOrThrow(Biomes.PLAINS), PalettedContainer.Strategy.SECTION_BIOMES
+ registry.asHolderIdMap(), registry.getOrThrow(Biomes.PLAINS), PalettedContainer.Strategy.SECTION_BIOMES, null // Paper - Anti-Xray - Add preset biomes
);
2024-10-24 21:10:38 +02:00
}
2021-11-29 12:55:13 +01:00
2024-12-16 15:13:42 +01:00
@@ -414,7 +418,7 @@ public record SerializableChunkData(
2021-11-29 12:55:13 +01:00
2022-06-08 05:40:53 +02:00
// CraftBukkit start - read/write
2024-12-27 13:45:04 +01:00
private static Codec<PalettedContainer<Holder<Biome>>> makeBiomeCodecRW(Registry<Biome> biomeRegistry) {
- return PalettedContainer.codecRW(biomeRegistry.asHolderIdMap(), biomeRegistry.holderByNameCodec(), PalettedContainer.Strategy.SECTION_BIOMES, biomeRegistry.getOrThrow(Biomes.PLAINS));
+ return PalettedContainer.codecRW(biomeRegistry.asHolderIdMap(), biomeRegistry.holderByNameCodec(), PalettedContainer.Strategy.SECTION_BIOMES, biomeRegistry.getOrThrow(Biomes.PLAINS), null); // Paper - Anti-Xray - Add preset biomes
2021-11-29 12:55:13 +01:00
}
2022-06-08 05:40:53 +02:00
// CraftBukkit end
2021-11-29 12:55:13 +01:00