use of net.glowstone.net.message.play.game.MultiBlockChangeMessage in project Glowstone by GlowstoneMC.
the class MultiBlockChangeCodec method encode.
@Override
public ByteBuf encode(ByteBuf buf, MultiBlockChangeMessage message) throws IOException {
List<BlockChangeMessage> records = message.getRecords();
buf.writeInt(message.getChunkX());
buf.writeInt(message.getChunkZ());
int size = records.size();
ByteBufUtils.writeVarInt(buf, size);
for (int i = 0; i < size; i++) {
BlockChangeMessage record = records.get(i);
// XZY
int pos = (record.getX() & 0xF) << 12 | (record.getZ() & 0xF) << 8 | record.getY() & 0xFF;
buf.writeShort(pos);
ByteBufUtils.writeVarInt(buf, record.getType());
}
return buf;
}
use of net.glowstone.net.message.play.game.MultiBlockChangeMessage in project Glowstone by GlowstoneMC.
the class GlowPlayer method processBlockChanges.
/**
* Process and send pending BlockChangeMessages.
*/
private void processBlockChanges() {
for (Key key : knownChunks) {
List<BlockChangeMessage> messages = world.getChunkManager().getBlockChanges(key);
int size = messages.size();
if (size == 1) {
session.send(messages.get(0));
} else if (size > 1) {
session.send(new MultiBlockChangeMessage(key.getX(), key.getZ(), messages));
}
}
processPersonalBlockChanges();
// now send post-block-change messages
List<Message> postMessages = new ArrayList<>(afterBlockChanges);
afterBlockChanges.clear();
postMessages.forEach(session::send);
}
use of net.glowstone.net.message.play.game.MultiBlockChangeMessage in project Glowstone by GlowstoneMC.
the class GlowPlayer method processPersonalBlockChanges.
/**
* Process and send packets sent specifically to us.
*/
private void processPersonalBlockChanges() {
if (blockChanges.isEmpty()) {
return;
}
// separate messages by chunk
// inner map is used to only send one entry for same coordinates
Map<Key, Map<BlockVector, BlockChangeMessage>> chunks = new HashMap<>();
BlockChangeMessage message;
while ((message = blockChanges.poll()) != null) {
Key key = GlowChunk.Key.of(message.getX() >> 4, message.getZ() >> 4);
if (canSeeChunk(key)) {
Map<BlockVector, BlockChangeMessage> map = chunks.computeIfAbsent(key, k -> new HashMap<>());
map.put(new BlockVector(message.getX(), message.getY(), message.getZ()), message);
}
}
// send away
for (Map.Entry<Key, Map<BlockVector, BlockChangeMessage>> entry : chunks.entrySet()) {
Key key = entry.getKey();
List<BlockChangeMessage> value = new ArrayList<>(entry.getValue().values());
if (value.size() == 1) {
session.send(value.get(0));
} else if (value.size() > 1) {
session.send(new MultiBlockChangeMessage(key.getX(), key.getZ(), value));
}
}
}
use of net.glowstone.net.message.play.game.MultiBlockChangeMessage in project Dragonet-Legacy by DragonetMC.
the class MultiBlockChangeMessageTranslator method handleSpecific.
@Override
public PEPacket[] handleSpecific(MultiBlockChangeMessage packet) {
UpdateBlockPacket pkBC = new UpdateBlockPacket();
pkBC.records = new UpdateBlockPacket.UpdateBlockRecord[packet.records.size()];
// PEPacket[] packets = new PEPacket[msgMBC.records.size()];
int i = 0;
for (BlockChangeMessage msgBC : packet.records) {
// packets[i] = this.translateToPE(msgBC)[0];
pkBC.records[i] = new UpdateBlockPacket.UpdateBlockRecord();
pkBC.records[i].x = msgBC.x;
pkBC.records[i].z = msgBC.z;
pkBC.records[i].y = (byte) (msgBC.y & 0xFF);
pkBC.records[i].block = (byte) (this.getTranslator().getItemTranslator().translateToPE(msgBC.type >> 4) & 0xFF);
pkBC.records[i].meta = UpdateBlockPacket.FLAG_ALL_PRIORITY;
i++;
}
return new PEPacket[] { pkBC };
}
Aggregations