Search in sources :

Example 16 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project Hyperium by HyperiumClient.

the class MixinNetHandlerPlayClient method handleCustomPayload.

@Inject(method = "handleCustomPayload", at = @At("RETURN"))
private void handleCustomPayload(S3FPacketCustomPayload packetIn, CallbackInfo ci) {
    PacketBuffer packetBuffer = packetIn.getBufferData();
    try {
        int readableBytes = packetBuffer.readableBytes();
        if (readableBytes > 0) {
            byte[] payload = new byte[readableBytes - 1];
            packetBuffer.readBytes(payload);
            String message = new String(payload, Charsets.UTF_8);
            if (LoginReplyHandler.SHOW_MESSAGES) {
                GeneralChatHandler.instance().sendMessage("Packet message on channel " + packetIn.getChannelName() + " -> " + message);
            }
            if ("REGISTER".equalsIgnoreCase(packetIn.getChannelName())) {
                if (message.contains("Hyperium")) {
                    PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
                    buffer.writeString("Hyperium;" + Metadata.getVersion() + ";" + Metadata.getVersionID());
                    addToSendQueue(new C17PacketCustomPayload("REGISTER", buffer));
                    PacketBuffer addonbuffer = new PacketBuffer(Unpooled.buffer());
                    List<AddonManifest> addons = AddonBootstrap.INSTANCE.getAddonManifests();
                    addonbuffer.writeInt(addons.size());
                    for (AddonManifest addonmanifest : addons) {
                        String addonName = addonmanifest.getName();
                        String version = addonmanifest.getVersion();
                        if (addonName == null)
                            addonName = addonmanifest.getMainClass();
                        if (version == null)
                            version = "unknown";
                        addonbuffer.writeString(addonName);
                        addonbuffer.writeString(version);
                    }
                    addToSendQueue(new C17PacketCustomPayload("hyperium|Addons", addonbuffer));
                }
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : C17PacketCustomPayload(net.minecraft.network.play.client.C17PacketCustomPayload) AddonManifest(cc.hyperium.internal.addons.AddonManifest) PacketBuffer(net.minecraft.network.PacketBuffer) URISyntaxException(java.net.URISyntaxException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 17 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project minecolonies by Minecolonies.

the class SaveScanMessage method toBytes.

@Override
public void toBytes(@NotNull final ByteBuf buf) {
    final NBTTagCompound wrapperCompound = new NBTTagCompound();
    wrapperCompound.setString(TAG_MILLIS, fileName);
    wrapperCompound.setTag(TAG_SCHEMATIC, nbttagcompound);
    final PacketBuffer buffer = new PacketBuffer(buf);
    try (ByteBufOutputStream stream = new ByteBufOutputStream(buffer)) {
        CompressedStreamTools.writeCompressed(wrapperCompound, stream);
    } catch (final IOException e) {
        Log.getLogger().info("Problem at retrieving structure on server.", e);
    }
}
Also used : ByteBufOutputStream(io.netty.buffer.ByteBufOutputStream) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IOException(java.io.IOException) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 18 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project Bewitchment by Um-Mitternacht.

the class ParticleMessage method fromBytes.

@Override
public void fromBytes(ByteBuf byteBuf) {
    PacketBuffer buf = new PacketBuffer(byteBuf);
    particleF = buf.readEnumValue(ParticleF.class);
    x = buf.readDouble();
    y = buf.readDouble();
    z = buf.readDouble();
    amount = buf.readInt();
    xSpeed = buf.readDouble();
    ySpeed = buf.readDouble();
    zSpeed = buf.readDouble();
    int argCount = buf.readInt();
    args = new int[argCount];
    for (int i = 0; i < argCount; i++) {
        args[i] = buf.readInt();
    }
}
Also used : ParticleF(com.bewitchment.client.fx.ParticleF) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 19 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project Solar by ArekkuusuJerii.

the class ServerToClientPacket method fromBytes.

@Override
public void fromBytes(ByteBuf buf) {
    PacketBuffer beef = new PacketBuffer(buf);
    try {
        handler = PacketHandler.HANDLERS.get(buf.readInt());
        data = beef.readCompoundTag();
    } catch (Exception e) {
        Solar.LOG.error("[Packet] Failed to receive packet");
        e.printStackTrace();
    }
}
Also used : PacketBuffer(net.minecraft.network.PacketBuffer)

Example 20 with PacketBuffer

use of net.minecraft.network.PacketBuffer in project Solar by ArekkuusuJerii.

the class ClientToServerPacket method fromBytes.

@Override
public void fromBytes(ByteBuf buf) {
    PacketBuffer beef = new PacketBuffer(buf);
    try {
        handler = PacketHandler.HANDLERS.get(buf.readInt());
        data = beef.readCompoundTag();
    } catch (Exception e) {
        Solar.LOG.error("[Packet] Failed to receive packet");
        e.printStackTrace();
    }
}
Also used : PacketBuffer(net.minecraft.network.PacketBuffer)

Aggregations

PacketBuffer (net.minecraft.network.PacketBuffer)103 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)18 FMLProxyPacket (net.minecraftforge.fml.common.network.internal.FMLProxyPacket)14 IOException (java.io.IOException)13 ByteBuf (io.netty.buffer.ByteBuf)11 SPacketCustomPayload (net.minecraft.network.play.server.SPacketCustomPayload)7 BlockPos (net.minecraft.util.math.BlockPos)7 HashMap (java.util.HashMap)4 DimensionInformation (mcjty.rftoolsdim.dimensions.DimensionInformation)4 DimensionDescriptor (mcjty.rftoolsdim.dimensions.description.DimensionDescriptor)4 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 NetHandlerPlayServer (net.minecraft.network.NetHandlerPlayServer)3 Test (org.junit.Test)3 PacketBufferBC (buildcraft.lib.net.PacketBufferBC)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 PacketCustomTileData (gregtech.api.net.PacketCustomTileData)2 PacketUIWidgetUpdate (gregtech.api.net.PacketUIWidgetUpdate)2 AbstractData (hellfirepvp.fracture.common.data.AbstractData)2