Search in sources :

Example 1 with MeasureBox

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;
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf) ArrayList(java.util.ArrayList) List(java.util.List) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) MeasureBox(win.baruna.blockmeter.measurebox.MeasureBox) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with MeasureBox

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);
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf) MeasureBox(win.baruna.blockmeter.measurebox.MeasureBox) JSONSource(de.modprog.blockmeter.util.JSONSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

PacketByteBuf (net.minecraft.network.PacketByteBuf)2 MeasureBox (win.baruna.blockmeter.measurebox.MeasureBox)2 JSONSource (de.modprog.blockmeter.util.JSONSource)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1