Search in sources :

Example 16 with PacketByteBuf

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

the class MyNetwork method createGlobalPortalUpdate.

public static CustomPayloadS2CPacket createGlobalPortalUpdate(GlobalPortalStorage storage) {
    PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
    buf.writeInt(storage.world.get().dimension.getType().getRawId());
    buf.writeCompoundTag(storage.toTag(new CompoundTag()));
    return new CustomPayloadS2CPacket(id_stcUpdateGlobalPortal, buf);
}
Also used : CustomPayloadS2CPacket(net.minecraft.client.network.packet.CustomPayloadS2CPacket) PacketByteBuf(net.minecraft.util.PacketByteBuf) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 17 with PacketByteBuf

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

the class MyNetworkClient method createCtsTeleport.

public static CustomPayloadC2SPacket createCtsTeleport(DimensionType dimensionBefore, Vec3d posBefore, UUID portalEntityId) {
    PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
    buf.writeInt(dimensionBefore.getRawId());
    buf.writeDouble(posBefore.x);
    buf.writeDouble(posBefore.y);
    buf.writeDouble(posBefore.z);
    buf.writeUuid(portalEntityId);
    return new CustomPayloadC2SPacket(MyNetwork.id_ctsTeleport, buf);
}
Also used : PacketByteBuf(net.minecraft.util.PacketByteBuf) CustomPayloadC2SPacket(net.minecraft.server.network.packet.CustomPayloadC2SPacket)

Example 18 with PacketByteBuf

use of net.minecraft.util.PacketByteBuf in project FastAsyncWorldEdit by IntellectualSites.

the class FabricPlayer method dispatchCUIEvent.

@Override
public void dispatchCUIEvent(CUIEvent event) {
    String[] params = event.getParameters();
    String send = event.getTypeId();
    if (params.length > 0) {
        send = send + "|" + StringUtil.joinString(params, "|");
    }
    ServerPlayNetworking.send(this.player, WECUIPacketHandler.CUI_IDENTIFIER, new PacketByteBuf(Unpooled.copiedBuffer(send, StandardCharsets.UTF_8)));
}
Also used : PacketByteBuf(net.minecraft.util.PacketByteBuf)

Example 19 with PacketByteBuf

use of net.minecraft.util.PacketByteBuf in project FastAsyncWorldEdit by IntellectualSites.

the class FabricPlayer method sendFakeBlock.

@Override
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
    World world = getWorld();
    if (!(world instanceof FabricWorld)) {
        return;
    }
    BlockPos loc = FabricAdapter.toBlockPos(pos);
    if (block == null) {
        final BlockUpdateS2CPacket packetOut = new BlockUpdateS2CPacket(((FabricWorld) world).getWorld(), loc);
        player.networkHandler.sendPacket(packetOut);
    } else {
        final BlockUpdateS2CPacket packetOut = new BlockUpdateS2CPacket();
        PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
        buf.writeBlockPos(loc);
        buf.writeVarInt(Block.getRawIdFromState(FabricAdapter.adapt(block.toImmutableState())));
        try {
            packetOut.read(buf);
        } catch (IOException e) {
            return;
        }
        player.networkHandler.sendPacket(packetOut);
        if (block instanceof BaseBlock && block.getBlockType().equals(BlockTypes.STRUCTURE_BLOCK)) {
            final BaseBlock baseBlock = (BaseBlock) block;
            final CompoundTag nbtData = baseBlock.getNbtData();
            if (nbtData != null) {
                player.networkHandler.sendPacket(new BlockEntityUpdateS2CPacket(new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), STRUCTURE_BLOCK_PACKET_ID, NBTConverter.toNative(nbtData)));
            }
        }
    }
}
Also used : BlockUpdateS2CPacket(net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket) BlockEntityUpdateS2CPacket(net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket) PacketByteBuf(net.minecraft.util.PacketByteBuf) BlockPos(net.minecraft.util.math.BlockPos) IOException(java.io.IOException) World(com.sk89q.worldedit.world.World) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) CompoundTag(com.sk89q.jnbt.CompoundTag)

Example 20 with PacketByteBuf

use of net.minecraft.util.PacketByteBuf in project nbt-crafting by Siphalor.

the class NbtCrafting method onInitialize.

@Override
public void onInitialize() {
    ServerLoginConnectionEvents.QUERY_START.register((handler, server, sender, synchronizer) -> {
        sender.sendPacket(PRESENCE_CHANNEL, new PacketByteBuf(Unpooled.buffer()));
    });
    ServerLoginConnectionEvents.DISCONNECT.register((handler, server) -> {
        hasModClientConnectionHashes.remove(handler.client.hashCode());
    });
    ServerLoginNetworking.registerGlobalReceiver(PRESENCE_CHANNEL, (server, handler, understood, buf, synchronizer, responseSender) -> {
        if (understood) {
            hasModClientConnectionHashes.add(handler.client.hashCode());
        }
    });
    ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
        if (hasModClientConnectionHashes.contains(handler.client.hashCode())) {
            ((IServerPlayerEntity) handler.player).nbtCrafting$setClientModPresent(true);
            hasModClientConnectionHashes.remove(handler.client.hashCode());
        }
    });
}
Also used : IServerPlayerEntity(de.siphalor.nbtcrafting.util.duck.IServerPlayerEntity) 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