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);
}
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);
}
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;
}
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);
}
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);
}
Aggregations