mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
Multi Block Change API Implementation
This commit is contained in:
parent
1476dea76f
commit
a17ed327b3
@ -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<BlockState> 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);
|
||||
|
@ -937,6 +937,32 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
this.getHandle().connection.send(packet);
|
||||
}
|
||||
|
||||
// Paper start
|
||||
@Override
|
||||
public void sendMultiBlockChange(final Map<? extends io.papermc.paper.math.Position, BlockData> blockChanges) {
|
||||
if (this.getHandle().connection == null) return;
|
||||
|
||||
Map<SectionPos, it.unimi.dsi.fastutil.shorts.Short2ObjectMap<net.minecraft.world.level.block.state.BlockState>> sectionMap = new HashMap<>();
|
||||
|
||||
for (Map.Entry<? extends io.papermc.paper.math.Position, BlockData> 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<net.minecraft.world.level.block.state.BlockState> sectionData = sectionMap.computeIfAbsent(sectionPos, key -> new it.unimi.dsi.fastutil.shorts.Short2ObjectArrayMap<>());
|
||||
sectionData.put(SectionPos.sectionRelativePos(blockPos), ((CraftBlockData) blockData).getState());
|
||||
}
|
||||
|
||||
for (Map.Entry<SectionPos, it.unimi.dsi.fastutil.shorts.Short2ObjectMap<net.minecraft.world.level.block.state.BlockState>> entry : sectionMap.entrySet()) {
|
||||
SectionPos sectionPos = entry.getKey();
|
||||
it.unimi.dsi.fastutil.shorts.Short2ObjectMap<net.minecraft.world.level.block.state.BlockState> 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<BlockState> blocks) {
|
||||
Preconditions.checkArgument(blocks != null, "blocks must not be null");
|
||||
|
Loading…
Reference in New Issue
Block a user