Java Code Examples for net.minecraft.util.PacketByteBuf#readVarInt()
The following examples show how to use
net.minecraft.util.PacketByteBuf#readVarInt() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FMLPlayMessages.java From patchwork-api with GNU Lesser General Public License v2.1 | 6 votes |
private SpawnEntity(PacketByteBuf buf) { this.entity = null; this.typeId = buf.readVarInt(); this.entityId = buf.readInt(); this.uuid = buf.readUuid(); this.posX = buf.readDouble(); this.posY = buf.readDouble(); this.posZ = buf.readDouble(); this.pitch = buf.readByte(); this.yaw = buf.readByte(); this.headYaw = buf.readByte(); this.velX = buf.readShort(); this.velY = buf.readShort(); this.velZ = buf.readShort(); this.buf = buf; }
Example 2
Source File: VelocityUtil.java From Sandbox with GNU Lesser General Public License v3.0 | 6 votes |
public static boolean checkIntegrity(final PacketByteBuf buf) { final byte[] signature = new byte[32]; buf.readBytes(signature); final byte[] data = new byte[buf.readableBytes()]; buf.getBytes(buf.readerIndex(), data); try { final Mac mac = Mac.getInstance("HmacSHA256"); mac.init(new SecretKeySpec(SandboxConfig.velocityKey.get().getBytes(), "HmacSHA256")); final byte[] mySignature = mac.doFinal(data); if (!MessageDigest.isEqual(signature, mySignature)) { return false; } } catch (final InvalidKeyException | NoSuchAlgorithmException e) { throw new AssertionError(e); } int version = buf.readVarInt(); if (version != 1) { throw new IllegalStateException("Unsupported forwarding version " + version + ", wanted " + 1); } return true; }
Example 3
Source File: MixinPacketInflater.java From bleachhack-1.14 with GNU General Public License v3.0 | 5 votes |
@Inject(at = @At("HEAD"), method = "decode(Lio/netty/channel/ChannelHandlerContext;Lio/netty/buffer/ByteBuf;Ljava/util/List;)V", cancellable = true) protected void decode(ChannelHandlerContext channelHandlerContext_1, ByteBuf byteBuf_1, List<Object> list_1, CallbackInfo info) throws Exception { if (!ModuleManager.getModule(AntiChunkBan.class).isToggled()) return; info.cancel(); if (byteBuf_1.readableBytes() != 0) { PacketByteBuf packetByteBuf_1 = new PacketByteBuf(byteBuf_1); int int_1 = packetByteBuf_1.readVarInt(); if (int_1 == 0) { list_1.add(packetByteBuf_1.readBytes(packetByteBuf_1.readableBytes())); } else { if (int_1 > 51200000) { throw new DecoderException("Badly compressed packet - size of " + (int_1 / 1000000) + "MB is larger than protocol maximum of 50 MB"); } byte[] bytes_1 = new byte[packetByteBuf_1.readableBytes()]; packetByteBuf_1.readBytes(bytes_1); this.inflater.setInput(bytes_1); byte[] bytes_2 = new byte[int_1]; this.inflater.inflate(bytes_2); list_1.add(Unpooled.wrappedBuffer(bytes_2)); this.inflater.reset(); } } }
Example 4
Source File: MixinPacketInflater.java From bleachhack-1.14 with GNU General Public License v3.0 | 5 votes |
@Inject(at = @At("HEAD"), method = "decode(Lio/netty/channel/ChannelHandlerContext;Lio/netty/buffer/ByteBuf;Ljava/util/List;)V", cancellable = true) protected void decode(ChannelHandlerContext channelHandlerContext_1, ByteBuf byteBuf_1, List<Object> list_1, CallbackInfo info) throws Exception { if (!ModuleManager.getModule(AntiChunkBan.class).isToggled()) return; info.cancel(); if (byteBuf_1.readableBytes() != 0) { PacketByteBuf packetByteBuf_1 = new PacketByteBuf(byteBuf_1); int int_1 = packetByteBuf_1.readVarInt(); if (int_1 == 0) { list_1.add(packetByteBuf_1.readBytes(packetByteBuf_1.readableBytes())); } else { if (int_1 > 51200000) { throw new DecoderException("Badly compressed packet - size of " + (int_1 / 1000000) + "MB is larger than protocol maximum of 50 MB"); } byte[] bytes_1 = new byte[packetByteBuf_1.readableBytes()]; packetByteBuf_1.readBytes(bytes_1); this.inflater.setInput(bytes_1); byte[] bytes_2 = new byte[int_1]; this.inflater.inflate(bytes_2); list_1.add(Unpooled.wrappedBuffer(bytes_2)); this.inflater.reset(); } } }
Example 5
Source File: ServerNetworkHandler.java From fabric-carpet with MIT License | 5 votes |
public static void handleData(PacketByteBuf data, ServerPlayerEntity player) { if (data != null) { int id = data.readVarInt(); if (id == CarpetClient.HELLO) onHello(player, data); if (id == CarpetClient.DATA) onClientData(player, data); } }
Example 6
Source File: ClientNetworkHandler.java From fabric-carpet with MIT License | 5 votes |
public static void handleData(PacketByteBuf data, ClientPlayerEntity player) { if (data != null) { int id = data.readVarInt(); if (id == CarpetClient.HI) onHi(data); if (id == CarpetClient.DATA) onSyncData(data, player); } }
Example 7
Source File: FMLPlayMessages.java From patchwork-api with GNU Lesser General Public License v2.1 | 4 votes |
public static OpenContainer decode(PacketByteBuf buf) { return new OpenContainer(buf.readVarInt(), buf.readVarInt(), buf.readText(), new PacketByteBuf(Unpooled.wrappedBuffer(buf.readByteArray(32600)))); }