From a17ed327b3f8c9241f1883a2bed23e8e1e61d0d8 Mon Sep 17 00:00:00 2001 From: Brody Beckwith Date: Fri, 14 Jan 2022 00:41:11 -0500 Subject: [PATCH] Multi Block Change API Implementation --- ...tboundSectionBlocksUpdatePacket.java.patch | 15 +++++++++++ .../craftbukkit/entity/CraftPlayer.java | 26 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/paper-server/patches/sources/net/minecraft/network/protocol/game/ClientboundSectionBlocksUpdatePacket.java.patch b/paper-server/patches/sources/net/minecraft/network/protocol/game/ClientboundSectionBlocksUpdatePacket.java.patch index 414f6fe6a7..372b4afd93 100644 --- a/paper-server/patches/sources/net/minecraft/network/protocol/game/ClientboundSectionBlocksUpdatePacket.java.patch +++ b/paper-server/patches/sources/net/minecraft/network/protocol/game/ClientboundSectionBlocksUpdatePacket.java.patch @@ -21,3 +21,18 @@ private ClientboundSectionBlocksUpdatePacket(FriendlyByteBuf buf) { this.sectionPos = SectionPos.of(buf.readLong()); int i = buf.readVarInt(); +@@ -54,6 +62,14 @@ + + } + ++ // Paper start - Multi Block Change API ++ public ClientboundSectionBlocksUpdatePacket(SectionPos sectionPos, it.unimi.dsi.fastutil.shorts.Short2ObjectMap blockChanges) { ++ this.sectionPos = sectionPos; ++ this.positions = blockChanges.keySet().toShortArray(); ++ this.states = blockChanges.values().toArray(new BlockState[0]); ++ } ++ // Paper end - Multi Block Change API ++ + private void write(FriendlyByteBuf buf) { + buf.writeLong(this.sectionPos.asLong()); + buf.writeVarInt(this.positions.length); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index f363f885b3..eb48efa038 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -937,6 +937,32 @@ public class CraftPlayer extends CraftHumanEntity implements Player { this.getHandle().connection.send(packet); } + // Paper start + @Override + public void sendMultiBlockChange(final Map blockChanges) { + if (this.getHandle().connection == null) return; + + Map> sectionMap = new HashMap<>(); + + for (Map.Entry entry : blockChanges.entrySet()) { + BlockData blockData = entry.getValue(); + BlockPos blockPos = io.papermc.paper.util.MCUtil.toBlockPos(entry.getKey()); + SectionPos sectionPos = SectionPos.of(blockPos); + + it.unimi.dsi.fastutil.shorts.Short2ObjectMap sectionData = sectionMap.computeIfAbsent(sectionPos, key -> new it.unimi.dsi.fastutil.shorts.Short2ObjectArrayMap<>()); + sectionData.put(SectionPos.sectionRelativePos(blockPos), ((CraftBlockData) blockData).getState()); + } + + for (Map.Entry> entry : sectionMap.entrySet()) { + SectionPos sectionPos = entry.getKey(); + it.unimi.dsi.fastutil.shorts.Short2ObjectMap blockData = entry.getValue(); + + net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket packet = new net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket(sectionPos, blockData); + this.getHandle().connection.send(packet); + } + } + // Paper end + @Override public void sendBlockChanges(Collection blocks) { Preconditions.checkArgument(blocks != null, "blocks must not be null");