Search in sources :

Example 11 with PacketByteBuf

use of net.minecraft.util.PacketByteBuf in project tweed-api by Siphalor.

the class ConfigFile method syncToClient.

public void syncToClient(ServerPlayerEntity playerEntity, ConfigEnvironment environment, ConfigScope scope, ConfigOrigin origin) {
    PacketByteBuf packetByteBuf = new PacketByteBuf(Unpooled.buffer());
    packetByteBuf.writeEnumConstant(origin);
    packetByteBuf.writeString(name);
    write(packetByteBuf, environment, scope, origin);
    ServerSidePacketRegistry.INSTANCE.sendToPlayer(playerEntity, Tweed.CONFIG_SYNC_S2C_PACKET, packetByteBuf);
}
Also used : PacketByteBuf(net.minecraft.util.PacketByteBuf)

Example 12 with PacketByteBuf

use of net.minecraft.util.PacketByteBuf in project tweed-api by Siphalor.

the class ConfigFile method syncToServer.

public void syncToServer(ConfigEnvironment environment, ConfigScope scope) {
    PacketByteBuf packetByteBuf = new PacketByteBuf(Unpooled.buffer());
    packetByteBuf.writeString(name);
    packetByteBuf.writeEnumConstant(environment);
    packetByteBuf.writeEnumConstant(scope);
    write(packetByteBuf, environment, scope, ConfigOrigin.MAIN);
    ClientSidePacketRegistry.INSTANCE.sendToServer(Tweed.TWEED_CLOTH_SYNC_C2S_PACKET, packetByteBuf);
}
Also used : PacketByteBuf(net.minecraft.util.PacketByteBuf)

Example 13 with PacketByteBuf

use of net.minecraft.util.PacketByteBuf in project ImmersivePortalsMod by qouteall.

the class MyNetwork method createCustomPacketStc.

// you can input a lambda expression and it will be invoked remotely
// but java serialization is not stable
@Deprecated
public static CustomPayloadS2CPacket createCustomPacketStc(ICustomStcPacket serializable) {
    // it copies the data twice but as the packet is small it's of no problem
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    ObjectOutputStream stream = null;
    try {
        stream = new ObjectOutputStream(byteArrayOutputStream);
        stream.writeObject(serializable);
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
    ByteBuf buffer = Unpooled.buffer();
    buffer.writeBytes(byteArrayOutputStream.toByteArray());
    PacketByteBuf buf = new PacketByteBuf(buffer);
    return new CustomPayloadS2CPacket(id_stcCustom, buf);
}
Also used : CustomPayloadS2CPacket(net.minecraft.client.network.packet.CustomPayloadS2CPacket) PacketByteBuf(net.minecraft.util.PacketByteBuf) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) ByteBuf(io.netty.buffer.ByteBuf) PacketByteBuf(net.minecraft.util.PacketByteBuf)

Example 14 with PacketByteBuf

use of net.minecraft.util.PacketByteBuf in project ImmersivePortalsMod by qouteall.

the class MyNetwork method createStcDimensionConfirm.

public static CustomPayloadS2CPacket createStcDimensionConfirm(DimensionType dimensionType, Vec3d pos) {
    PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
    buf.writeInt(dimensionType.getRawId());
    buf.writeDouble(pos.x);
    buf.writeDouble(pos.y);
    buf.writeDouble(pos.z);
    return new CustomPayloadS2CPacket(id_stcDimensionConfirm, buf);
}
Also used : CustomPayloadS2CPacket(net.minecraft.client.network.packet.CustomPayloadS2CPacket) PacketByteBuf(net.minecraft.util.PacketByteBuf)

Example 15 with PacketByteBuf

use of net.minecraft.util.PacketByteBuf in project ImmersivePortalsMod by qouteall.

the class MyNetwork method createRedirectedMessage.

public static CustomPayloadS2CPacket createRedirectedMessage(DimensionType dimension, Packet packet) {
    int messageType = 0;
    try {
        messageType = NetworkState.PLAY.getPacketId(NetworkSide.CLIENTBOUND, packet);
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
    PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
    buf.writeInt(dimension.getRawId());
    buf.writeInt(messageType);
    try {
        packet.write(buf);
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    }
    return new CustomPayloadS2CPacket(id_stcRedirected, buf);
}
Also used : CustomPayloadS2CPacket(net.minecraft.client.network.packet.CustomPayloadS2CPacket) PacketByteBuf(net.minecraft.util.PacketByteBuf) IOException(java.io.IOException) IOException(java.io.IOException)

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