generated from grepsedawk/sharded.cr
-
Notifications
You must be signed in to change notification settings - Fork 8
/
entity.cr
69 lines (58 loc) · 1.9 KB
/
entity.cr
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
class Rosegold::Entity
METADATA = Array(Metadata).from_json(Rosegold.read_game_asset "entities.json")
class Metadata
include JSON::Serializable
property id : Int32
@[JSON::Field(key: "internalId")]
property internal_id : Int32
property name : String
@[JSON::Field(key: "displayName")]
property display_name : String
property width : Float64
property height : Float64
property type : String
property category : String
end
property \
entity_id : UInt64,
uuid : UUID,
entity_type : UInt32,
position : Vec3d,
pitch : Float32,
yaw : Float32,
head_yaw : Float32,
velocity : Vec3d,
passenger_ids : Array(UInt64) = [] of UInt64,
effects : Array(EntityEffect) = [] of EntityEffect
property? \
on_ground : Bool = true,
living : Bool = false
def initialize(@entity_id, @uuid, @entity_type, @position, @pitch, @yaw, @head_yaw, @velocity, @on_ground = true, @living = false)
end
def metadata
METADATA.find { |data| data.id == @entity_type }
end
def bounding_box
if metadata = self.metadata
half_width = metadata.width / 2.0
min = Vec3d.new(position.x - half_width, position.y, position.z - half_width)
max = Vec3d.new(position.x + half_width, position.y + metadata.height, position.z + half_width)
AABBd.new(min, max)
else
# Default bounding box for entities with unknown dimensions
half_size = 0.5
min = Vec3d.new(position.x - half_size, position.y, position.z - half_size)
max = Vec3d.new(position.x + half_size, position.y + 1, position.z + half_size)
AABBd.new(min, max)
end
end
def update_passengers(client)
passenger_ids.each do |passenger_id|
if client.player.entity_id == passenger_id
client.player.feet = position
elsif entity = client.dimension.entities[passenger_id]?
entity.position = position
end
end
end
end