欢迎来到Minecraft插件百科!
对百科编辑一脸懵逼?
帮助:快速入门
带您快速熟悉百科编辑!
因近日遭受攻击,百科现已限制编辑,有意编辑请加入插件百科企鹅群:223812289
查看“Data Types”的源代码
←
Data Types
跳转到导航
跳转到搜索
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于这些用户组的用户执行:
用户
、
自动确认用户
、
巡查者
您可以查看和复制此页面的源代码。
所有通过网络发送的数据均为大端序([[wikipedia:Endianness#Big-endian|big-endian]],这意味着字节被从高位向低位发送。日常中大多数的计算机为小端序,所以可能需要在发送数据到网络之前将其转换为大端序。 {| class="wikitable" |- ! Name ! Size (bytes) ! Encodes ! Notes |- ! Boolean | 1 | false or true | Value can be either true (<code>0x01</code>) or false (<code>0x00</code>) |- ! Byte | 1 | -128 to 127 | Signed 8-bit integer, [[wikipedia:Two's complement|two's complement]] |- ! Unsigned Byte | 1 | 0 to 255 | Unsigned 8-bit integer |- ! Short | 2 | -32768 to 32767 | Signed 16-bit integer, two's complement |- ! Unsigned Short | 2 | 0 to 65535 | Unsigned 16-bit integer |- ! Int | 4 | -2147483648 to 2147483647 | Signed 32-bit integer, two's complement |- ! Long | 8 | -9223372036854775808 to 9223372036854775807 | Signed 64-bit integer, two's complement |- ! Float | 4 | [[wikipedia:Single-precision floating-point format|Single-precision 32-bit IEEE 754 floating point]] | |- ! Double | 8 | [[wikipedia:Double-precision floating-point format|Double-precision 64-bit IEEE 754 floating point]] | |- ! String | ≥ 1 <br />≤ 2147483652 | A sequence of [[wikipedia:Unicode|Unicode]] code points | [[wikipedia:UTF-8|UTF-8]] string prefixed with its size in bytes as a VarInt |- ! Chat | ≥ 1 <br />≤ 2147483652 | See [[Chat]] | Encoded as a String |- ! VarInt | ≥ 1 <br />≤ 5 | -2147483648 to 2147483647 | [http://developers.google.com/protocol-buffers/docs/encoding#varints Protocol Buffer Varint], encoding a two's complement signed 32-bit integer |- ! VarLong | ≥ 1 <br />≤ 10 | -9223372036854775808 to 9223372036854775807 | [http://developers.google.com/protocol-buffers/docs/encoding#varints Protocol Buffer Varint], encoding a two's complement signed 64-bit integer |- ! Chunk | Varies | A vertical chunk column | See [[SMP Map Format#Data]] |- ! Metadata | Varies | See [[Entities#Entity Metadata Format]] | |- ! Slot | Varies | See [[Slot Data]] | |- ! Object Data | 4 or 10 | See [[Object Data]] | |- ! NBT Tag | Varies | See [[NBT]] | |- ! Position | 8 | Integer/block position: x (-33554432 to 33554431), y (-2048 to 2047), z (-33554432 to 33554431) | x as a 26-bit integer, followed by y as a 12-bit integer, followed by z as a 26-bit integer (all signed, two's complement). See also [[#Position|the section below]]. |- ! Angle | 1 | Rotation angle in steps of 1/256 of a full turn | Whether or not this is signed does not matter, since the resulting angles are the same. |- ! UUID | 16 | A [[wikipedia:Universally_unique_identifier|UUID]] | The vanilla Minecraft server internally sends this as two longs. <pre>this.writeLong(uuid.getMostSignificantBits()); this.writeLong(uuid.getLeastSignificantBits());</pre> |- ! Optional X | 0 or size of X | A field of type X, or nothing | Whether or not the field is present must be known from the context. |- ! Array of X | count times size of X | Zero or more fields of type X | The count must be known from the context. |- ! Byte Array | Varies | Depends on context | This is just a sequence of zero or more bytes, its meaning should be explained somewhere else, e.g. in the packet description. The length must also be known from the context. |} === 位置 === 分成 3 部分的 64 个比特位 * x: 26 MSBs * z: 26 LSBs * y: 12 bits between them 像这样编码: ((x & 0x3FFFFFF) << 38) | ((y & 0xFFF) << 26) | (z & 0x3FFFFFF) 像这样解码: long val; // Encoded value x = val >> 38; y = (val >> 26) & 0xFFF z = val << 38 >> 38 Note: 位移的细节是和编程语言相关的;以上代码若没有调整可能在 Java 中正确运行但在其他语言中无法正确运行。 === 定点数据 === 有些域可能会被存储为 [https://en.wikipedia.org/wiki/Fixed-point_arithmetic 定点数(fixed point)],即使用一定数量的比特位来存储小数的整数部分(小数点的左边),其余比特位表示小数部分 (小数点的右边)。浮点数 (float 和 double) 则相反,它将数字本身(底数)放在一个块里, 小数点的位置(指数)在其一旁存储。 实际上,虽然定点数的范围比浮点数小,但他们对于更高数值的精度更高。这使得他们成为在Minecraft中表示一个实体的全局坐标的理想选择,因为比起在一个方块(或一米)中精确的确定他们的位置而言,存储表示他们所在方块的整数部分显得更重要。 Coordinates are often represented as a 32-bit integer, where 5 of the least-significant bits are dedicated to the fractional part, and the rest store the integer part. Java lacks support for fractional integers directly, but you can represent them as integers. To convert from a double to this integer representation, use the following formulas: abs_int = (int)double * 32; And back again: double = (double)abs_int / 32;
返回
Data Types
。
导航菜单
个人工具
登录
命名空间
页面
讨论
大陆简体
查看
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
编辑相关
百科公告
编辑帮助
互助客栈
贡献分数
测试沙盒
发布条目
插件分类
管理
安全
聊天
编程
经济
修正
娱乐
综合
信息
机械
角色
传送
网页
整地
创世
付费
其它
工具
链入页面
相关更改
特殊页面
页面信息
相关网站
MCMOD百科
Minecraft中文百科
Minecraft纪念论坛
Minecraft百度贴吧
虚无世界Wiki