-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
204 lines (192 loc) · 9.24 KB
/
init.lua
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
-- with a lot of inspiration from https://github.com/bhull2010/minetest-mod-models
player_model = {}
player_model.list = {}
player_model.players = {}
local armormod = nil
if armor ~= nil then
armormod = armor
elseif mcl_player ~= nil then
armormod = mcl_player
end
player_model.register_model = function(name, modeldef)
print("[player_model]: register_model("..name..")")
player_model.list[name] = modeldef
end
for regentityname, ent in pairs(minetest.registered_entities) do
if string.find(regentityname, '^petz:')
or string.find(regentityname, '^animalworld:')
or string.find(regentityname, '^mobs_animal:')
or string.find(regentityname, '^extra_mobs:')
or string.find(regentityname, '^mobs:')
or string.find(regentityname, '^mobs_mc:') then
if minetest.registered_entities[regentityname]['mesh'] ~= nil
and (minetest.registered_entities[regentityname]['textures'] ~= nil or minetest.registered_entities[regentityname]['texture_list'] ~= nil)
and minetest.registered_entities[regentityname]['collisionbox'] ~= nil
and minetest.registered_entities[regentityname]['visual'] == "mesh" then
local modeldef = {}
modeldef.mesh = minetest.registered_entities[regentityname]['mesh']
modeldef.visual_size = minetest.registered_entities[regentityname]['visual_size'] or {x = 1, y = 1}
modeldef.collisionbox = minetest.registered_entities[regentityname]['collisionbox']
if type(minetest.registered_entities[regentityname]['textures']) == "table" then
modeldef.textures = minetest.registered_entities[regentityname]['textures'][1]
elseif type(minetest.registered_entities[regentityname]['texture_list']) == "table" then
modeldef.textures = minetest.registered_entities[regentityname]['texture_list'][1]
elseif minetest.registered_entities[regentityname]['textures'] ~= nil then
modeldef.textures = minetest.registered_entities[regentityname]['textures']
end
if modeldef.textures then
player_model.register_model(regentityname, modeldef)
end
end
end
end
-- wrap 3d_armor to disable it temporarily
if armormod ~= nil then
armormod.player_model_active = {}
if armor ~= nil then
local armor_update_player_visuals = function(self, player) end
armor_update_player_visuals = armor.update_player_visuals
armor.update_player_visuals = function(self, player)
if armormod.player_model_active[player:get_player_name()] == "true" then
-- do nothing
else
armor_update_player_visuals(self, player)
end
end
elseif mcl_player ~= nil then
local mcl_player_player_set_skin = function(player, texture, preview) end
mcl_player_player_set_skin = mcl_player.player_set_skin
mcl_player.player_set_skin = function(player, texture, preview)
if armormod.player_model_active[player:get_player_name()] == "true" then
-- do nothing
else
mcl_player_player_set_skin(player, texture, preview)
end
end
local mcl_player_player_set_armor = function(player, texture, preview) end
mcl_player_player_set_armor = mcl_player.player_set_armor
mcl_player.player_set_armor = function(player, texture, preview)
if armormod.player_model_active[player:get_player_name()] == "true" then
-- do nothing
else
mcl_player_player_set_armor(player, texture, preview)
end
end
local mcl_player_player_set_wielditem = function(player, texture) end
mcl_player_player_set_wielditem = mcl_player.player_set_wielditem
mcl_player.player_set_wielditem = function(player, texture)
if armormod.player_model_active[player:get_player_name()] == "true" then
-- do nothing
else
mcl_player_player_set_wielditem(player, texture)
end
end
end
end
player_model.update_player_model = function(player, modelname)
print("[player_model]: update_player_model("..player:get_player_name()..","..modelname..")")
if armormod ~= nil then
armormod.player_model_active[player:get_player_name()] = "true"
end
if player_model.players[player:get_player_name()] == nil then
-- first shapeshift, store original model for reset
player_model.players[player:get_player_name()] = {}
player_model.players[player:get_player_name()]['original'] = {
visual = player:get_properties()['visual'],
mesh = player:get_properties()['mesh'],
textures = player:get_properties()['textures'],
visual_size = player:get_properties()['visual_size'],
collisionbox = player:get_properties()['collisionbox'],
damage_texture_modifier = player:get_properties()['damage_texture_modifier']
}
end
player:set_properties({
visual = "mesh",
mesh = player_model.list[modelname].mesh,
textures = player_model.list[modelname].textures,
visual_size = player_model.list[modelname].visual_size,
collisionbox = player_model.list[modelname].collisionbox,
damage_texture_modifier = ""
})
player:get_meta():set_string("player_model", modelname)
end
minetest.register_chatcommand("set_player_model", {
params = "<modelname>",
func = function(playername, param)
if param == nil or param == "" then
minetest.chat_send_player(playername, "no model name given")
return
end
if player_model.list[param] ~= nil then
player_model.update_player_model(minetest.get_player_by_name(playername), param)
minetest.chat_send_player(playername, "model "..param.." set")
else
minetest.chat_send_player(playername, "model "..param.." not found")
end
end
})
minetest.register_chatcommand("reset_player_model", {
func = function(playername, param)
if player_model.players[playername] ~= nil and player_model.players[playername]['original'] then
minetest.get_player_by_name(playername):set_properties({
visual = player_model.players[playername]['original']['visual'],
mesh = player_model.players[playername]['original']['mesh'],
textures = player_model.players[playername]['original']['textures'],
visual_size = player_model.players[playername]['original']['visual_size'],
collisionbox = player_model.players[playername]['original']['collisionbox'],
damage_texture_modifier = player_model.players[playername]['original']['damage_texture_modifier']
})
minetest.chat_send_player(playername, "model reset")
if armormod ~= nil then
armormod.player_model_active[playername] = "false"
end
end
end
})
minetest.register_chatcommand("list_player_models", {
func = function(playername, param)
local list = "player models: "
for name in pairs(player_model.list) do
list = list .. name .. " "
end
minetest.chat_send_player(playername, list)
end
})
minetest.register_chatcommand("player_models", {
func = function(playername, param)
local formspec = "size[4,3]".."label[0,0;Select Model]"
local models = {}
for k,v in pairs(player_model.list) do
table.insert(models, k)
end
table.sort(models, function(a, b) return a < b end)
formspec = formspec.."dropdown[0,1;4;dropdownModel;"..table.concat(models, ",")..";0;false]"
formspec = formspec.."button_exit[0,2;2,1;btSet;Set Model]"
formspec = formspec.."button_exit[2,2;2,1;btReset;Reset Model]"
minetest.show_formspec(playername, 'player_models_show_ui', formspec)
end
})
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname == 'player_models_show_ui' then
if fields ~= nil and fields['btSet'] ~= nil and fields['dropdownModel'] ~= nil then
player_model.update_player_model(player, fields['dropdownModel'])
elseif fields ~= nil and fields['btReset'] ~= nil then
local playername = player:get_player_name()
if player_model.players[playername] ~= nil and player_model.players[playername]['original'] then
minetest.get_player_by_name(playername):set_properties({
visual = player_model.players[playername]['original']['visual'],
mesh = player_model.players[playername]['original']['mesh'],
textures = player_model.players[playername]['original']['textures'],
visual_size = player_model.players[playername]['original']['visual_size'],
collisionbox = player_model.players[playername]['original']['collisionbox'],
damage_texture_modifier = player_model.players[playername]['original']['damage_texture_modifier']
})
minetest.chat_send_player(playername, "model reset")
if armormod ~= nil then
armormod.player_model_active[playername] = "false"
end
end
end
end
end)
print("[player_model]: initialized")