Search in sources :

Example 21 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project SpeedRunIGT by RedLime.

the class TimerPacketHandler method sendCompleteS2C.

public static void sendCompleteS2C(List<ServerPlayerEntity> players, long endTime) {
    PacketByteBuf passedData = new PacketByteBuf(Unpooled.buffer());
    passedData.writeLong(endTime);
    CustomPayloadS2CPacket s2CPacket = new CustomPayloadS2CPacket(PACKET_TIMER_COMPLETE_ID, passedData);
    for (ServerPlayerEntity player : players) {
        player.networkHandler.sendPacket(s2CPacket);
    }
}
Also used : CustomPayloadS2CPacket(net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket) PacketByteBuf(net.minecraft.network.PacketByteBuf) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 22 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf 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 23 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project BlockMeter by ModProg.

the class ClientMeasureBoxTest method testPacketByteBuf.

@ParameterizedTest
@JSONSource(classes = { ParseBlockPos.class, ParseBlockPos.class, ParseIdentifier.class, ParseDyeColor.class, Boolean.class }, jsons = { "(1|2|0), (0|0|0), overworld, red, true", "(-1020|30|10), (-1000|100|20), end, blue, false", "(1|2|0), (0|256|0), overworld, red, true", "(1400|2|-6000), (1200|32|-5000), nether, red, true" })
void testPacketByteBuf(final BlockPos bp0, final BlockPos bp1, final Identifier dimension, final DyeColor color, final boolean finished) {
    final PacketByteBuf expectedBuf = new PacketByteBuf(Unpooled.buffer());
    expectedBuf.writeBlockPos(bp0);
    expectedBuf.writeBlockPos(bp1);
    expectedBuf.writeIdentifier(dimension);
    expectedBuf.writeInt(color.getId());
    expectedBuf.writeBoolean(finished);
    expectedBuf.writeInt(0);
    expectedBuf.writeInt(0);
    final ClientMeasureBox mb = ClientMeasureBox.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) ClientMeasureBox(win.baruna.blockmeter.measurebox.ClientMeasureBox) JSONSource(de.modprog.blockmeter.util.JSONSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project FabricWaystones by LordDeatHunter.

the class WaystonesEventManager method registerEvents.

public static void registerEvents() {
    ServerLifecycleEvents.SERVER_STARTED.register((server) -> {
        if (Waystones.WAYSTONE_STORAGE == null) {
            Waystones.WAYSTONE_STORAGE = new WaystoneStorage(server);
        }
    });
    ServerLifecycleEvents.SERVER_STOPPED.register((server) -> {
        Waystones.WAYSTONE_STORAGE.loadOrSaveWaystones(true);
        Waystones.WAYSTONE_STORAGE = null;
    });
    ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
        PacketByteBuf data = PacketByteBufs.create();
        data.writeNbt(Config.getInstance().toNbtCompound());
        ServerPlayNetworking.send(handler.player, Utils.ID("waystone_config_update"), data);
        Waystones.WAYSTONE_STORAGE.sendToPlayer(handler.player);
        Waystones.WAYSTONE_STORAGE.sendCompatData(handler.player);
    });
    ServerLifecycleEvents.SERVER_STARTING.register(WaystonesWorldgen::registerVanillaVillageWorldgen);
    ServerPlayerEvents.AFTER_RESPAWN.register((oldPlayer, newPlayer, alive) -> ((PlayerEntityMixinAccess) newPlayer).syncData());
    CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(CommandManager.literal("waystones").then(CommandManager.literal("reload").requires(source -> source.hasPermissionLevel(1)).executes(context -> {
        Config.getInstance().loadConfig();
        PacketByteBuf data = PacketByteBufs.create();
        data.writeNbt(Config.getInstance().toNbtCompound());
        for (ServerPlayerEntity player : context.getSource().getServer().getPlayerManager().getPlayerList()) {
            ServerPlayNetworking.send(player, Utils.ID("waystone_config_update"), data);
        }
        ServerPlayerEntity player = context.getSource().getPlayer();
        if (player != null) {
            player.sendMessage(new LiteralText("§6[§eWaystones§6] §3has successfully reloaded!"), false);
        }
        return 1;
    })).then(CommandManager.literal("display").executes(context -> {
        ServerPlayerEntity player = context.getSource().getPlayer();
        if (player == null) {
            return 1;
        }
        Config.getInstance().print(player);
        return 1;
    }))));
}
Also used : LiteralText(net.minecraft.text.LiteralText) Waystones(wraith.waystones.Waystones) PlayerEntityMixinAccess(wraith.waystones.access.PlayerEntityMixinAccess) ServerPlayConnectionEvents(net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerPlayerEvents(net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents) CommandRegistrationCallback(net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback) ServerPlayNetworking(net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking) PacketByteBuf(net.minecraft.network.PacketByteBuf) ServerLifecycleEvents(net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents) PacketByteBufs(net.fabricmc.fabric.api.networking.v1.PacketByteBufs) CommandManager(net.minecraft.server.command.CommandManager) PacketByteBuf(net.minecraft.network.PacketByteBuf) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) LiteralText(net.minecraft.text.LiteralText)

Example 25 with PacketByteBuf

use of net.minecraft.network.PacketByteBuf in project FallingAttackFabric by hamusuke0323.

the class ClientPlayerEntityMixin method sendFallingAttackPacket.

public void sendFallingAttackPacket(boolean start) {
    PacketByteBuf packetByteBuf = PacketByteBufs.create();
    packetByteBuf.writeBoolean(start);
    this.networkHandler.sendPacket(new CustomPayloadC2SPacket(NetworkManager.FALLING_ATTACK_C2S_PACKET_ID, packetByteBuf));
}
Also used : PacketByteBuf(net.minecraft.network.PacketByteBuf) CustomPayloadC2SPacket(net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket)

Aggregations

PacketByteBuf (net.minecraft.network.PacketByteBuf)117 PlayerEntity (net.minecraft.entity.player.PlayerEntity)21 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)14 Identifier (net.minecraft.util.Identifier)8 NbtCompound (net.minecraft.nbt.NbtCompound)7 Environment (net.fabricmc.api.Environment)5 CustomPayloadC2SPacket (net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket)5 CustomPayloadS2CPacket (net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket)4 Nullable (org.jetbrains.annotations.Nullable)4 Inject (org.spongepowered.asm.mixin.injection.Inject)4 ArrayList (java.util.ArrayList)3 UUID (java.util.UUID)3 JSONSource (de.modprog.blockmeter.util.JSONSource)2 Map (java.util.Map)2 ServerPlayNetworking (net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking)2 LivingEntity (net.minecraft.entity.LivingEntity)2 CompoundTag (net.minecraft.nbt.CompoundTag)2 ListTag (net.minecraft.nbt.ListTag)2 ParticleType (net.minecraft.particle.ParticleType)2 LiteralText (net.minecraft.text.LiteralText)2