use of net.glowstone.net.message.play.game.BlockChangeMessage 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.BlockChangeMessage 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 };
}
use of net.glowstone.net.message.play.game.BlockChangeMessage in project Glowstone by GlowstoneMC.
the class GlowBlock method setTypeIdAndData.
@Deprecated
public boolean setTypeIdAndData(int type, byte data, boolean applyPhysics) {
Material oldTypeId = getType();
byte oldData = getData();
GlowChunk chunk = (GlowChunk) world.getChunkAt(this);
Material material = ((GlowServer) Bukkit.getServer()).getBlockDataManager().convertToBlockData(type).getMaterial();
chunk.setType(x & 0xf, z & 0xf, y, material);
chunk.setMetaData(x & 0xf, z & 0xf, y, data);
if (applyPhysics) {
applyPhysics(oldTypeId, material, oldData, data);
}
GlowChunk.Key key = GlowChunk.Key.of(x >> 4, z >> 4);
BlockChangeMessage bcmsg = new BlockChangeMessage(x, y, z, type, data);
world.broadcastBlockChangeInRange(key, bcmsg);
return true;
}
use of net.glowstone.net.message.play.game.BlockChangeMessage in project Glowstone by GlowstoneMC.
the class GlowPlayer method pulseDigging.
private void pulseDigging() {
if (++diggingTicks <= totalDiggingTicks) {
// diggingTicks starts at 1 and progresses to totalDiggingTicks, but animation stages
// are 0 through 9, so subtract 1 from the current tick
int stage = (int) (10.0 * ((double) (diggingTicks - 1)) / totalDiggingTicks);
broadcastBlockBreakAnimation(digging, stage);
return;
}
ItemStack tool = getItemInHand();
short durability = tool.getDurability();
short maxDurability = tool.getType().getMaxDurability();
if (!InventoryUtil.isEmpty(tool) && maxDurability != 0 && durability != maxDurability) {
// Before applying unbreaking enchantment
int baseDamage;
switch(digging.getType()) {
case GRASS_BLOCK:
case DIRT:
case SAND:
case GRAVEL:
case MYCELIUM:
case SOUL_SAND:
baseDamage = ToolType.SHOVEL.matches(tool.getType()) ? 1 : 2;
break;
case OAK_LOG:
case DARK_OAK_LOG:
case ACACIA_LOG:
case BIRCH_LOG:
case JUNGLE_LOG:
case SPRUCE_LOG:
case OAK_WOOD:
case DARK_OAK_WOOD:
case ACACIA_WOOD:
case BIRCH_WOOD:
case JUNGLE_WOOD:
case SPRUCE_WOOD:
case CHEST:
baseDamage = ToolType.AXE.matches(tool.getType()) ? 1 : 2;
break;
case STONE:
case COBBLESTONE:
baseDamage = ToolType.PICKAXE.matches(tool.getType()) ? 1 : 2;
break;
default:
baseDamage = 2;
break;
}
for (int i = 0; i < baseDamage; i++) {
tool = InventoryUtil.damageItem(this, tool);
}
}
// Force-update item
setItemInHand(tool);
// Break the block
digging.breakNaturally(tool);
// Send block status to clients
int blockX = digging.getX();
int blockY = digging.getY();
int blockZ = digging.getZ();
// Tell the whole chunk
world.broadcastBlockChangeInRange(Key.of(blockX >> 4, blockZ >> 4), new BlockChangeMessage(blockX, blockY, blockZ, Material.AIR.getId(), 0));
setDigging(null);
}
Aggregations