-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconvert.v
More file actions
153 lines (133 loc) · 4.05 KB
/
Copy pathconvert.v
File metadata and controls
153 lines (133 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
module protocol
import protocol.enums
import protocol.model
import protocol.packets
import protocol.types
import bedrock_v.nbt
// The bridge between the version independent model types and the shapes the
// selected version puts on the wire. Callers work in model types and never
// have to know which of the two a packet happens to want.
// shield_runtime_id is the item the client draws a blocking pose for. It is a
// runtime id, so it moves with the item palette rather than with the protocol.
const shield_runtime_id = 358
pub fn actor_unique_id(value i64) types.ActorUniqueID {
return types.ActorUniqueID{
value: value
}
}
pub fn actor_runtime_id(value u64) types.ActorRuntimeID {
return types.ActorRuntimeID{
value: value
}
}
pub fn vec3(v model.Vector3) [3]f32 {
return [v.x, v.y, v.z]!
}
pub fn vec3_from_array(v [3]f32) model.Vector3 {
return model.Vector3{v[0], v[1], v[2]}
}
pub fn block_pos(v model.BlockPosition) types.NetworkBlockPosition {
return types.NetworkBlockPosition{
x: i32(v.x)
y: i32(v.y)
z: i32(v.z)
}
}
pub fn block_pos_from(v types.NetworkBlockPosition) model.BlockPosition {
return model.BlockPosition{
x: int(v.x)
y: int(v.y)
z: int(v.z)
}
}
// block_pos_from_legacy reads the older of the two block position shapes, which
// the packets that predate types.NetworkBlockPosition still carry.
pub fn block_pos_from_legacy(v types.BlockPos) model.BlockPosition {
return model.BlockPosition{
x: int(v.x)
y: int(v.y)
z: int(v.z)
}
}
pub fn item_descriptor(item model.ItemStack) types.NetworkItemStackDescriptor {
return types.NetworkItemStackDescriptor{
id: i16(item.id)
stack_size: u16(item.count)
aux_value: u32(item.meta)
block_runtime_id: u32(item.block_runtime_id)
user_data_buffer: item.raw_extra_data
blocking: item.id == shield_runtime_id
}
}
pub fn item_instance(item model.ItemStack) types.NetworkItemInstanceDescriptor {
return types.NetworkItemInstanceDescriptor{
id: i32(item.id)
stack_size: u16(item.count)
aux_value: u32(item.meta)
block_runtime_id: i32(item.block_runtime_id)
user_data_buffer: item.raw_extra_data
blocking: item.id == shield_runtime_id
}
}
pub fn item_descriptor_v2(item model.ItemStack) types.NetworkItemStackDescriptorV2 {
return item_descriptor_v2_tracked(item, 0)
}
pub fn item_descriptor_v2_tracked(item model.ItemStack, net_id int) types.NetworkItemStackDescriptorV2 {
mut d := types.NetworkItemStackDescriptorV2{
id: i16(item.id)
stack_size: u16(item.count)
aux_value: u32(item.meta)
block_runtime_id: u32(item.block_runtime_id)
user_data_buffer: item.raw_extra_data
blocking: item.id == shield_runtime_id
}
if item.count > 0 && item.id != 0 && net_id != 0 {
d.net_id = i32(net_id)
}
return d
}
pub fn item_stack_from_descriptor_v2(item types.NetworkItemStackDescriptorV2) model.ItemStack {
return model.ItemStack{
id: int(item.id)
count: int(item.stack_size)
meta: int(item.aux_value)
block_runtime_id: int(item.block_runtime_id)
raw_extra_data: item.user_data_buffer
}
}
pub fn level_sound_event(event_name string, position model.Vector3, data i32, actor_identifier string, entity_unique_id u64) &packets.LevelSoundEventPacket {
mut packet := &packets.LevelSoundEventPacket{
event_name: event_name
data: data
actor_identifier: actor_identifier
entity_unique_id: entity_unique_id
}
packet.position[0] = position.x
packet.position[1] = position.y
packet.position[2] = position.z
return packet
}
pub fn rotation_byte(value f32) i8 {
mut scaled := int(value * 256.0 / 360.0)
scaled %= 256
if scaled < 0 {
scaled += 256
}
return i8(u8(scaled))
}
pub fn uuid_from_bytes(b []u8) types.Uuid {
mut uuid := types.Uuid{}
for i := 0; i < 16 && i < b.len; i++ {
uuid.bytes[i] = b[i]
}
return uuid
}
pub fn empty_nbt() nbt.RootTag {
return nbt.RootTag{
name: ''
tag: nbt.Tag(nbt.new_compound())
}
}
pub fn game_type(value int) enums.GameType {
return unsafe { enums.GameType(value) }
}