Search in sources :

Example 21 with PacketByteBuf

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!");
    }
}
Also used : PacketByteBuf(net.minecraft.util.PacketByteBuf) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 22 with PacketByteBuf

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());
    }
}
Also used : PacketByteBuf(net.minecraft.util.PacketByteBuf) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 23 with PacketByteBuf

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);
}
Also used : Container(net.minecraft.container.Container) CustomPayloadS2CPacket(net.minecraft.client.network.packet.CustomPayloadS2CPacket) PacketByteBuf(net.minecraft.util.PacketByteBuf) ServerPlayerEntityAccessor(net.fabricmc.fabric.mixin.container.ServerPlayerEntityAccessor)

Example 24 with PacketByteBuf

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));
}
Also used : Identifier(net.minecraft.util.Identifier) PacketByteBuf(net.minecraft.util.PacketByteBuf)

Example 25 with PacketByteBuf

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));
}
Also used : PacketByteBuf(net.minecraft.util.PacketByteBuf)

Aggregations

PacketByteBuf (net.minecraft.util.PacketByteBuf)25 CustomPayloadS2CPacket (net.minecraft.client.network.packet.CustomPayloadS2CPacket)7 IOException (java.io.IOException)4 CompoundTag (net.minecraft.nbt.CompoundTag)4 Inject (org.spongepowered.asm.mixin.injection.Inject)4 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)3 Identifier (net.minecraft.util.Identifier)3 IServerPlayerEntity (de.siphalor.nbtcrafting.util.duck.IServerPlayerEntity)2 Unpooled (io.netty.buffer.Unpooled)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 EntityType (net.minecraft.entity.EntityType)2 Registry (net.minecraft.util.registry.Registry)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 CacheLoader (com.google.common.cache.CacheLoader)1 LoadingCache (com.google.common.cache.LoadingCache)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Pair (com.mojang.datafixers.util.Pair)1 MyClientChunkManager (com.qouteall.immersive_portals.chunk_loading.MyClientChunkManager)1 IEClientPlayNetworkHandler (com.qouteall.immersive_portals.ducks.IEClientPlayNetworkHandler)1