Search in sources :

Example 1 with MultiBlockChangeMessage

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;
}
Also used : MultiBlockChangeMessage(net.glowstone.net.message.play.game.MultiBlockChangeMessage) BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage)

Example 2 with MultiBlockChangeMessage

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);
}
Also used : TitleMessage(net.glowstone.net.message.play.game.TitleMessage) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage) OpenWindowMessage(net.glowstone.net.message.play.inv.OpenWindowMessage) BlockBreakAnimationMessage(net.glowstone.net.message.play.game.BlockBreakAnimationMessage) WindowPropertyMessage(net.glowstone.net.message.play.inv.WindowPropertyMessage) UpdateBlockEntityMessage(net.glowstone.net.message.play.game.UpdateBlockEntityMessage) RespawnMessage(net.glowstone.net.message.play.game.RespawnMessage) EntityVelocityMessage(net.glowstone.net.message.play.entity.EntityVelocityMessage) PositionRotationMessage(net.glowstone.net.message.play.game.PositionRotationMessage) HealthMessage(net.glowstone.net.message.play.game.HealthMessage) PluginMessage(net.glowstone.net.message.play.game.PluginMessage) SetWindowSlotMessage(net.glowstone.net.message.play.inv.SetWindowSlotMessage) PlayEffectMessage(net.glowstone.net.message.play.game.PlayEffectMessage) BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage) MultiBlockChangeMessage(net.glowstone.net.message.play.game.MultiBlockChangeMessage) UnloadChunkMessage(net.glowstone.net.message.play.game.UnloadChunkMessage) StateChangeMessage(net.glowstone.net.message.play.game.StateChangeMessage) SpawnPositionMessage(net.glowstone.net.message.play.game.SpawnPositionMessage) ExperienceMessage(net.glowstone.net.message.play.game.ExperienceMessage) NamedSoundEffectMessage(net.glowstone.net.message.play.game.NamedSoundEffectMessage) UserListHeaderFooterMessage(net.glowstone.net.message.play.game.UserListHeaderFooterMessage) HeldItemMessage(net.glowstone.net.message.play.inv.HeldItemMessage) MapDataMessage(net.glowstone.net.message.play.game.MapDataMessage) StopSoundMessage(net.glowstone.net.message.play.game.StopSoundMessage) CloseWindowMessage(net.glowstone.net.message.play.inv.CloseWindowMessage) ChunkDataMessage(net.glowstone.net.message.play.game.ChunkDataMessage) TimeMessage(net.glowstone.net.message.play.game.TimeMessage) Message(com.flowpowered.network.Message) SetWindowContentsMessage(net.glowstone.net.message.play.inv.SetWindowContentsMessage) PlayParticleMessage(net.glowstone.net.message.play.game.PlayParticleMessage) ResourcePackSendMessage(net.glowstone.net.message.play.player.ResourcePackSendMessage) DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) JoinGameMessage(net.glowstone.net.message.play.game.JoinGameMessage) SignEditorMessage(net.glowstone.net.message.play.game.SignEditorMessage) SetPassengerMessage(net.glowstone.net.message.play.entity.SetPassengerMessage) EntityAnimationMessage(net.glowstone.net.message.play.entity.EntityAnimationMessage) TextMessage(net.glowstone.util.TextMessage) UpdateSignMessage(net.glowstone.net.message.play.game.UpdateSignMessage) UserListItemMessage(net.glowstone.net.message.play.game.UserListItemMessage) ChatMessage(net.glowstone.net.message.play.game.ChatMessage) ArrayList(java.util.ArrayList) MultiBlockChangeMessage(net.glowstone.net.message.play.game.MultiBlockChangeMessage) BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage) MultiBlockChangeMessage(net.glowstone.net.message.play.game.MultiBlockChangeMessage) Key(net.glowstone.chunk.GlowChunk.Key) NamespacedKey(org.bukkit.NamespacedKey)

Example 3 with MultiBlockChangeMessage

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));
        }
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MultiBlockChangeMessage(net.glowstone.net.message.play.game.MultiBlockChangeMessage) BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage) MultiBlockChangeMessage(net.glowstone.net.message.play.game.MultiBlockChangeMessage) BlockVector(org.bukkit.util.BlockVector) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StatisticMap(net.glowstone.util.StatisticMap) MetadataMap(net.glowstone.entity.meta.MetadataMap) HashMap(java.util.HashMap) Key(net.glowstone.chunk.GlowChunk.Key) NamespacedKey(org.bukkit.NamespacedKey)

Example 4 with MultiBlockChangeMessage

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 };
}
Also used : PEPacket(org.dragonet.net.packet.minecraft.PEPacket) MultiBlockChangeMessage(net.glowstone.net.message.play.game.MultiBlockChangeMessage) BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage) UpdateBlockPacket(org.dragonet.net.packet.minecraft.UpdateBlockPacket)

Aggregations

BlockChangeMessage (net.glowstone.net.message.play.game.BlockChangeMessage)4 MultiBlockChangeMessage (net.glowstone.net.message.play.game.MultiBlockChangeMessage)4 ArrayList (java.util.ArrayList)2 Key (net.glowstone.chunk.GlowChunk.Key)2 NamespacedKey (org.bukkit.NamespacedKey)2 Message (com.flowpowered.network.Message)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 MetadataMap (net.glowstone.entity.meta.MetadataMap)1 DestroyEntitiesMessage (net.glowstone.net.message.play.entity.DestroyEntitiesMessage)1 EntityAnimationMessage (net.glowstone.net.message.play.entity.EntityAnimationMessage)1 EntityMetadataMessage (net.glowstone.net.message.play.entity.EntityMetadataMessage)1 EntityVelocityMessage (net.glowstone.net.message.play.entity.EntityVelocityMessage)1 SetPassengerMessage (net.glowstone.net.message.play.entity.SetPassengerMessage)1 BlockBreakAnimationMessage (net.glowstone.net.message.play.game.BlockBreakAnimationMessage)1 ChatMessage (net.glowstone.net.message.play.game.ChatMessage)1 ChunkDataMessage (net.glowstone.net.message.play.game.ChunkDataMessage)1 ExperienceMessage (net.glowstone.net.message.play.game.ExperienceMessage)1 HealthMessage (net.glowstone.net.message.play.game.HealthMessage)1