forked from sirrobzeroone/3d_armor_flyswim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.lua
More file actions
231 lines (202 loc) · 8.34 KB
/
Copy pathmodel.lua
File metadata and controls
231 lines (202 loc) · 8.34 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
-- 3D Armor Hovering Animations
-- Copyright (C) 2026 Kunshan Wang
--
-- This library is free software; you can redistribute it and/or
-- modify it under the terms of the GNU Lesser General Public
-- License as published by the Free Software Foundation; either
-- version 2.1 of the License, or (at your option) any later version.
--
-- This library is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- Lesser General Public License for more details.
--
-- You should have received a copy of the GNU Lesser General Public
-- License along with this library; if not, see <https://www.gnu.org/licenses/>.
-------------------------------------------------------------------------------
-- This file sets the player model and plays player animations.
armor_hover.model = {
initialize = function(self)
end,
on_joinplayer = function(self, player)
self:init_state(player)
end,
on_leaveplayer = function(self, player)
end,
set_animation = function(self, player, mstate, mining)
mining = armor_hover.to_boolean(mining)
local state = self:get_state(player)
local is_attached = armor_hover.game_backend:is_attached(player)
local mstate_def = armor_hover.mstates[mstate]
local emote = state.current_emote
local function determine_anim_name()
-- Emote comes first. It will override even the "game override".
-- That's intentional. It allows something like lying on a boat.
if emote then
return armor_hover.emotes[emote]
end
if is_attached then
local game_anim_name = state.game_override.anim_name
if game_anim_name then
-- Override mining, too.
mining = state.game_override.mining
return game_anim_name
end
-- fall through
end
if mstate_def.configurable then
return armor_hover.get_chosen_anim_name(player, mstate)
else
return mstate_def.anim_name
end
end
local anim_name = determine_anim_name()
local anim = armor_hover.animations[anim_name]
if state.current_anim_name ~= anim_name then
state.current_anim_name = anim_name
if state.current_mtrack then
player:stop_animation(state.current_mtrack)
end
player:play_animation(anim.track, anim)
state.current_mtrack = anim.track
local float = armor_hover.to_boolean(anim.float)
if state.floating ~= float then
state.floating = float
if float then
player:play_animation(armor_hover.floating_effect.track, armor_hover.floating_effect)
else
player:stop_animation(armor_hover.floating_effect.track)
end
end
local cape = anim.cape
if state.cape ~= cape then
state.cape = cape
if state.current_cape_track then
player:stop_animation(state.current_cape_track)
end
if cape then
local cape_anim = armor_hover.cape_effects[cape]
player:play_animation(cape_anim.track, cape_anim)
state.current_cape_track = cape_anim.track
end
end
end
if state.mining ~= mining then
state.mining = mining
if mining then
player:play_animation(armor_hover.mining_animation.track, armor_hover.mining_animation)
else
player:stop_animation(armor_hover.mining_animation.track)
end
end
local look_pitch = player:get_look_vertical()
local track_info = armor_hover.tracks_info[anim.track]
local head_pitch = anim.lock_head and 0 or look_pitch + track_info.body_pitch + track_info.head_pitch
local arm_pitch = not mining and 0 or look_pitch + track_info.body_pitch
player:set_bone_override("Head", {
rotation = { vec = vector.new(head_pitch, 0, 0) }
})
player:set_bone_override("Arm_Right", {
rotation = { vec = vector.new(arm_pitch, 0, 0) }
})
-- Reset eye offset if the player was attached and is not detached.
-- Other mods often set eye offset when attaching a player,
-- and reset to (0, 0, 0) when detaching, aiming to reset the offset.
-- Since our eye offset is player-customizable,
-- we refresh the eye offset.
if state.is_attached and not is_attached then
armor_hover.refresh_eye_offset(player)
end
state.is_attached = armor_hover.to_boolean(is_attached)
end,
set_skin_10 = function(self, player, texture)
local state = self:get_state(player)
state.textures[1] = texture
state.textures[2] = self.blank_texture
self:reapply_player_textures(player)
end,
set_skin_18 = function(self, player, texture)
local state = self:get_state(player)
state.textures[1] = self.blank_texture
state.textures[2] = texture
self:reapply_player_textures(player)
end,
set_armor = function(self, player, texture)
local state = self:get_state(player)
state.textures[3] = texture
self:reapply_player_textures(player)
end,
set_wielded_item = function(self, player, texture)
local state = self:get_state(player)
state.textures[4] = texture
self:reapply_player_textures(player)
end,
set_emote = function(self, player, emote)
if not armor_hover.emotes[emote] then
local player_name = player:get_player_name()
core.chat_send_player(player_name, "Invalid emote: " .. emote)
return
end
local state = self:get_state(player)
state.current_emote = emote
end,
clear_emote = function(self, player)
local state = self:get_state(player)
state.current_emote = nil
end,
-- The "game override" allows games to override the animation when the player is attached.
-- It can implement effects such as driving boats, riding horses, sleeping, etc.
set_game_override = function(self, player, anim_name, mining)
local state = self:get_state(player)
state.game_override.anim_name = anim_name
state.game_override.mining = armor_hover.to_boolean(mining)
end,
}
armor_hover.model.player_model = "3d_armor_hover_character.glb"
armor_hover.model.blank_texture = "blank.png"
function armor_hover.model:init_state(player)
armor_hover.player_states[player:get_player_name()].model = {
textures = { self.blank_texture, self.blank_texture, self.blank_texture, self.blank_texture },
current_anim_name = nil,
mining = false,
floating = false,
current_mtrack = nil,
current_cape_track = nil,
current_emote = nil,
is_attached = false,
game_override = {
anim_name = nil,
mining = false,
},
}
end
function armor_hover.model:get_state(player)
return armor_hover.player_states[player:get_player_name()].model
end
local function clear_local_animation(player)
local none = { x = 0, y = 0 }
player:set_local_animation(none, none, none, none, 30)
end
-- Reset the player model. Called when the user joins or when the model is accidentally set by other mods.
function armor_hover.model:reset_player_model(player)
local state = self:get_state(player)
local player_model = self.player_model
local textures = state.textures
armor_hover.debug("Setting model for player '%s' to '%s'", player:get_player_name(), player_model)
player:set_properties({
mesh = player_model,
textures = textures,
visual = "mesh",
visual_size = { x = 1, y = 1 },
})
clear_local_animation(player)
end
-- Re-apply player textures.
function armor_hover.model:reapply_player_textures(player)
local state = self:get_state(player)
local textures = state.textures
armor_hover.debug("Applying textures to player '%s'", player:get_player_name())
player:set_properties({
textures = textures,
})
end