Java Code Examples for net.minecraft.util.PacketByteBuf#writeVarInt()

The following examples show how to use net.minecraft.util.PacketByteBuf#writeVarInt() . 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 vote down vote up
public static void encode(SpawnEntity msg, PacketByteBuf buf) {
	buf.writeVarInt(msg.typeId);
	buf.writeInt(msg.entityId);
	buf.writeUuid(msg.uuid);
	buf.writeDouble(msg.posX);
	buf.writeDouble(msg.posY);
	buf.writeDouble(msg.posZ);
	buf.writeByte(msg.pitch);
	buf.writeByte(msg.yaw);
	buf.writeByte(msg.headYaw);
	buf.writeShort(msg.velX);
	buf.writeShort(msg.velY);
	buf.writeShort(msg.velZ);

	if (msg.entity instanceof IEntityAdditionalSpawnData) {
		((IEntityAdditionalSpawnData) msg.entity).writeSpawnData(buf);
	}
}
 
Example 2
Source File: ServerNetworkHandler.java    From fabric-carpet with MIT License 5 votes vote down vote up
private PacketByteBuf build()
{
    PacketByteBuf packetBuf = new PacketByteBuf(Unpooled.buffer());
    packetBuf.writeVarInt(CarpetClient.DATA);
    packetBuf.writeCompoundTag(tag);
    return packetBuf;
}
 
Example 3
Source File: HallowedNetworking.java    From the-hallow with MIT License 4 votes vote down vote up
public static PacketByteBuf createShowFloatingItemPacket(Item item) {
	PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
	buf.writeVarInt(Registry.ITEM.getRawId(item));
	return buf;
}
 
Example 4
Source File: FMLPlayMessages.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static void encode(OpenContainer msg, PacketByteBuf buf) {
	buf.writeVarInt(msg.id);
	buf.writeVarInt(msg.windowId);
	buf.writeText(msg.name);
	buf.writeByteArray(msg.additionalData.readByteArray());
}
 
Example 5
Source File: PatchworkPlayNetworkingMessages.java    From patchwork-api with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void sendContainerOpenPacket(ServerPlayerEntity player, NameableContainerFactory factory, Consumer<PacketByteBuf> extraDataWriter) {
	if (player.world.isClient) {
		return;
	}

	player.method_14247();

	ContainerSyncAccess access = (ContainerSyncAccess) player;
	int openContainerId = access.patchwork$getNewContainerSyncId();

	PacketByteBuf extraData = new PacketByteBuf(Unpooled.buffer());
	extraDataWriter.accept(extraData);

	// reset to beginning in case modders read for whatever reason
	extraData.readerIndex(0);

	PacketByteBuf output = new PacketByteBuf(Unpooled.buffer());
	output.writeVarInt(extraData.readableBytes());
	output.writeBytes(extraData);

	if (output.readableBytes() > 32600 || output.readableBytes() < 1) {
		throw new IllegalArgumentException("Invalid PacketByteBuf for openGui, found " + output.readableBytes() + " bytes");
	}

	Container c = factory.createMenu(openContainerId, player.inventory, player);
	ContainerType<?> type = c.getType();

	FMLPlayMessages.OpenContainer msg = new FMLPlayMessages.OpenContainer(type, openContainerId, factory.getDisplayName(), output);
	Packet<?> packet = PatchworkPlayNetworkingMessages.getOpenContainerPacket(msg);

	player.networkHandler.sendPacket(packet);
	player.container = c;
	player.container.addListener(player);

	// TODO MinecraftForge.EVENT_BUS.post(new PlayerContainerEvent.Open(player, c));
}