use of win.baruna.blockmeter.measurebox.MeasureBox in project BlockMeter by ModProg.
the class BlockMeterServer method buildS2CPacket.
/**
* Builds a S2CPacket containing the BoxList
*
* @return S2CPacket containing the BoxList
*/
private PacketByteBuf buildS2CPacket() {
PacketByteBuf data = new PacketByteBuf(Unpooled.buffer());
synchronized (playerBoxes) {
data.writeInt(playerBoxes.size());
Set<Map.Entry<UUID, List<MeasureBox>>> knownPlayers = playerBoxes.entrySet();
for (Map.Entry<UUID, List<MeasureBox>> playerBoxEntry : knownPlayers) {
ServerPlayerEntity player = server.getPlayerManager().getPlayer(playerBoxEntry.getKey());
data.writeText(player.getDisplayName());
data.writeInt(playerBoxEntry.getValue().size());
for (int i = 0; i < playerBoxEntry.getValue().size(); i++) {
playerBoxEntry.getValue().get(i).writePacketBuf(data);
}
}
}
return data;
}
use of win.baruna.blockmeter.measurebox.MeasureBox in project BlockMeter by ModProg.
the class MeasureBoxTest method testPacketByteBuf.
@ParameterizedTest
@JSONSource(classes = { ParseBlockPos.class, ParseBlockPos.class, ParseIdentifier.class, ParseDyeColor.class, Boolean.class }, jsons = { "(11|2|-50), (0|0|0), overworld, red, true", "(10020|45|130), (10000|99|203), end, blue, false", "(17|0|40), (40|256|70), overworld, red, true", "(-1455|2|-6000), (-1455|32|-5000), overworld, red, true" })
void testPacketByteBuf(BlockPos bp1, BlockPos bp2, Identifier dimension, DyeColor color, boolean finished) {
final PacketByteBuf expectedBuf = new PacketByteBuf(Unpooled.buffer());
expectedBuf.writeBlockPos(bp1);
expectedBuf.writeBlockPos(bp2);
expectedBuf.writeIdentifier(dimension);
expectedBuf.writeInt(color.getId());
expectedBuf.writeBoolean(finished);
expectedBuf.writeInt(0);
expectedBuf.writeInt(0);
final MeasureBox mb = MeasureBox.fromPacketByteBuf(expectedBuf);
final PacketByteBuf actualBuf = new PacketByteBuf(Unpooled.buffer());
mb.writePacketBuf(actualBuf);
expectedBuf.resetReaderIndex();
assertThat(expectedBuf).isEqualTo(actualBuf);
}
Aggregations