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