Search in sources :

Example 1 with BlockChangeMessage

use of net.glowstone.net.message.play.game.BlockChangeMessage in project Glowstone by GlowstoneMC.

the class BlockRedstone method receivePulse.

@Override
public void receivePulse(GlowBlock me) {
    GlowChunk.Key key = GlowChunk.Key.of(me.getX() >> 4, me.getZ() >> 4);
    BlockDataManager blockDataManager = ((GlowServer) Bukkit.getServer()).getBlockDataManager();
    BlockChangeMessage bcmsg = new BlockChangeMessage(me.getX(), me.getY(), me.getZ(), blockDataManager.convertToBlockId(blockDataManager.createBlockData(me.getType())), me.getData());
    me.getWorld().broadcastBlockChangeInRange(key, bcmsg);
}
Also used : BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage) GlowServer(net.glowstone.GlowServer) BlockDataManager(net.glowstone.block.data.BlockDataManager) GlowChunk(net.glowstone.chunk.GlowChunk)

Example 2 with BlockChangeMessage

use of net.glowstone.net.message.play.game.BlockChangeMessage in project Glowstone by GlowstoneMC.

the class BlockChangeCodec method decode.

@Override
public BlockChangeMessage decode(ByteBuf buffer) throws IOException {
    BlockVector pos = GlowBufUtils.readBlockPosition(buffer);
    int type = ByteBufUtils.readVarInt(buffer);
    return new BlockChangeMessage(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), type);
}
Also used : BlockVector(org.bukkit.util.BlockVector) BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage)

Example 3 with BlockChangeMessage

use of net.glowstone.net.message.play.game.BlockChangeMessage 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 4 with BlockChangeMessage

use of net.glowstone.net.message.play.game.BlockChangeMessage in project Glowstone by GlowstoneMC.

the class GlowBlock method setData.

public void setData(byte data, boolean applyPhysics) {
    byte oldData = getData();
    ((GlowChunk) world.getChunkAt(this)).setMetaData(x & 0xf, z & 0xf, y, data);
    if (applyPhysics) {
        applyPhysics(getType(), getType(), oldData, data);
    }
    GlowChunk.Key key = GlowChunk.Key.of(x >> 4, z >> 4);
    BlockDataManager blockDataManager = ((GlowServer) Bukkit.getServer()).getBlockDataManager();
    StatefulBlockData blockData = blockDataManager.createBlockData(getType());
    BlockChangeMessage bcmsg = new BlockChangeMessage(x, y, z, blockDataManager.convertToBlockId(blockData), data);
    world.broadcastBlockChangeInRange(key, bcmsg);
}
Also used : BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage) GlowServer(net.glowstone.GlowServer) BlockDataManager(net.glowstone.block.data.BlockDataManager) GlowChunk(net.glowstone.chunk.GlowChunk) StatefulBlockData(net.glowstone.block.data.states.StatefulBlockData)

Example 5 with BlockChangeMessage

use of net.glowstone.net.message.play.game.BlockChangeMessage 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)

Aggregations

BlockChangeMessage (net.glowstone.net.message.play.game.BlockChangeMessage)9 MultiBlockChangeMessage (net.glowstone.net.message.play.game.MultiBlockChangeMessage)5 GlowServer (net.glowstone.GlowServer)3 GlowChunk (net.glowstone.chunk.GlowChunk)3 ArrayList (java.util.ArrayList)2 BlockDataManager (net.glowstone.block.data.BlockDataManager)2 Key (net.glowstone.chunk.GlowChunk.Key)2 NamespacedKey (org.bukkit.NamespacedKey)2 BlockVector (org.bukkit.util.BlockVector)2 Message (com.flowpowered.network.Message)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 StatefulBlockData (net.glowstone.block.data.states.StatefulBlockData)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