use of net.minecraft.util.PacketByteBuf in project nbt-crafting by Siphalor.
the class MixinPlayerManager method onDataPacksReloaded.
@Inject(method = "onDataPacksReloaded", at = @At("RETURN"))
public void onDataPacksReloaded(CallbackInfo ci) {
List<ServerPlayerEntity> nbtcPlayers = players.stream().filter(NbtCrafting::hasClientMod).collect(Collectors.toList());
if (!nbtcPlayers.isEmpty()) {
NbtCrafting.logInfo("Syncing advanced recipe data to " + nbtcPlayers.size() + " players");
PacketByteBuf buf = NbtCrafting.createAdvancedRecipeSyncPacket(server.getRecipeManager());
for (ServerPlayerEntity player : nbtcPlayers) {
NbtCrafting.logInfo("Syncing to player " + player.getEntityName());
ServerPlayNetworking.send(player, NbtCrafting.UPDATE_ADVANCED_RECIPES_PACKET_ID, buf);
}
} else {
NbtCrafting.logInfo("No advanced recipe data needs to be synced!");
}
}
use of net.minecraft.util.PacketByteBuf in project nbt-crafting by Siphalor.
the class MixinPlayerManager method afterRecipeSync.
@Inject(method = "onPlayerConnect", at = @At(value = "RETURN"))
public void afterRecipeSync(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) {
if (NbtCrafting.hasClientMod(player)) {
NbtCrafting.logInfo("Syncing advanced recipe data to player " + player.getEntityName());
PacketByteBuf buf = NbtCrafting.createAdvancedRecipeSyncPacket(server.getRecipeManager());
ServerPlayNetworking.send(player, NbtCrafting.UPDATE_ADVANCED_RECIPES_PACKET_ID, buf);
} else {
NbtCrafting.logInfo("Skipping advanced recipe data synchronization for vanillish player " + player.getEntityName());
}
}
use of net.minecraft.util.PacketByteBuf in project fabric by FabricMC.
the class ContainerProviderImpl method openContainer.
@Override
public void openContainer(Identifier identifier, ServerPlayerEntity player, Consumer<PacketByteBuf> writer) {
int syncId;
if (player instanceof ServerPlayerEntitySyncHook) {
ServerPlayerEntitySyncHook serverPlayerEntitySyncHook = (ServerPlayerEntitySyncHook) player;
syncId = serverPlayerEntitySyncHook.fabric_incrementSyncId();
} else if (player instanceof ServerPlayerEntityAccessor) {
if (!emittedNoSyncHookWarning) {
LOGGER.warn("ServerPlayerEntitySyncHook could not be applied - fabric-containers is using a hack!");
emittedNoSyncHookWarning = true;
}
syncId = (((ServerPlayerEntityAccessor) player).getContainerSyncId() + 1) % 100;
((ServerPlayerEntityAccessor) player).setContainerSyncId(syncId);
} else {
throw new RuntimeException("Neither ServerPlayerEntitySyncHook nor Accessor present! This should not happen!");
}
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
buf.writeIdentifier(identifier);
buf.writeByte(syncId);
writer.accept(buf);
player.networkHandler.sendPacket(new CustomPayloadS2CPacket(PacketTypes.OPEN_CONTAINER, buf));
PacketByteBuf clonedBuf = new PacketByteBuf(buf.duplicate());
clonedBuf.readIdentifier();
clonedBuf.readUnsignedByte();
Container container = createContainer(syncId, identifier, player, clonedBuf);
if (container == null) {
return;
}
player.container = container;
player.container.addListener(player);
}
use of net.minecraft.util.PacketByteBuf in project fabric by FabricMC.
the class PacketRegistryImpl method createRegisterTypePacket.
protected Optional<Packet<?>> createRegisterTypePacket(Identifier id, Collection<Identifier> ids) {
if (ids.isEmpty()) {
return Optional.empty();
}
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
boolean first = true;
for (Identifier a : ids) {
if (!first) {
buf.writeByte(0);
} else {
first = false;
}
buf.writeBytes(a.toString().getBytes(StandardCharsets.US_ASCII));
}
return Optional.of(toPacket(id, buf));
}
use of net.minecraft.util.PacketByteBuf in project tweed-api by Siphalor.
the class ConfigFile method syncToClients.
public void syncToClients(ConfigEnvironment environment, ConfigScope scope, ConfigOrigin origin) {
PacketByteBuf packetByteBuf = new PacketByteBuf(Unpooled.buffer());
packetByteBuf.writeEnumConstant(origin);
packetByteBuf.writeString(name);
write(packetByteBuf, environment, scope, origin);
PlayerStream.all(Tweed.getMinecraftServer()).forEach(serverPlayerEntity -> ServerSidePacketRegistry.INSTANCE.sendToPlayer(serverPlayerEntity, Tweed.CONFIG_SYNC_S2C_PACKET, packetByteBuf));
}
Aggregations