Initial commit

master
Brent Hull 2013-05-11 22:14:38 -04:00
commit 34dce89063
10 changed files with 188 additions and 0 deletions

7
README.txt Normal file
View File

@ -0,0 +1,7 @@
Minetest models mod - Choose per-player character models in-game
Code license: WTFPL
Texture license: CC-BY-SA (uses content from the default game in model screenshots)
Dependencies: modmenu or inventory_plus
Optional dependencies: mobs (simple mobs) - for example models
See list.lua for more information about registering player models to use with this mod.

14
models/COPYING Normal file
View File

@ -0,0 +1,14 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.

2
models/depends.txt Normal file
View File

@ -0,0 +1,2 @@
inventory_plus
default

112
models/init.lua Normal file
View File

@ -0,0 +1,112 @@
-- Models mod for minetest
-- Allows players to choose their player model in-game
-- License: WTFPL
-- Based on the skins mod by Zeg9 (WTFPL)
models = {}
models.models = {}
dofile(minetest.get_modpath("models").."/list.lua")
models.file = minetest.get_worldpath() .. "/playermodels.txt"
models.load = function()
local input = io.open(models.file, "r")
local data = nil
if input then
data = input:read('*all')
end
if data and data ~= "" then
lines = string.split(data,"\n")
for _, line in ipairs(lines) do
data = string.split(line, ' ', 2)
models.models[data[1]] = data[2]
end
io.close(input)
end
end
models.load()
print("[Models]: Loaded saved player model settings")
models.save = function()
local output = io.open(models.file,'w')
for name, skin in pairs(models.models) do
if name and skin then
output:write(name .. " " .. skin .. "\n")
end
end
io.close(output)
end
models.update_player_skin = function(player)
local name = player:get_player_name()
local modelname = models.models[name]
player:set_properties({
visual = "mesh",
mesh = models.list[modelname].mesh,
textures = models.list[modelname].textures,
visual_size = models.list[modelname].visual_size,
collisionbox = models.list[modelname].collisionbox
})
models.save()
end
models.formspec = {}
models.formspec.main = function(name)
page = models.pages[name]
if page == nil then page = 0 end
local formspec = "size[8,7.5]"
.. "button[0,0;2,.5;main;Back]"
.. "label[0,.5;Your current model:]"
.. "label[0,1.5;Choose a model below:]"
formspec = formspec .. "image[3,.5;2,1;"..models.list[models.models[name]].textures[1].."]"
local imodel = 0
local isprite = 0
local smodel = 0 -- Skip models, used for pages
local ssprite = 0 -- Skip sprites, used for pages
for modelname, modelprops in pairs(models.list) do
if smodel < page*8 then smodel = smodel + 1 else
if imodel < 8 then
formspec = formspec .. "image_button["..(imodel)..",2;1,2;"..modelprops.preview..";models_set_"..modelname..";]"
end
imodel = imodel +1
end
end
if page > 0 then
formspec = formspec .. "button[0,7;1,.5;models_page_"..(page-1)..";<<]"
end
formspec = formspec .. "label[3,6.5;Page "..page.."]"
if imodel > 8 or isprite > 8 then
formspec = formspec .. "button[7,7;1,.5;models_page_"..(page+1)..";>>]"
end
return formspec
end
models.pages = {}
minetest.register_on_joinplayer(function(player)
local p_name = player:get_player_name()
if not models.models[p_name] then
models.models[player:get_player_name()] = "character"
elseif models.models[p_name] ~= "character" then
--don't update model if the player is using the default
models.update_player_skin(player)
end
inventory_plus.register_button(player,"models","Player Model")
end)
minetest.register_on_player_receive_fields(function(player,formname,fields)
if fields.models then
inventory_plus.set_inventory_formspec(player,models.formspec.main(player:get_player_name()))
end
for field, _ in pairs(fields) do
if string.sub(field,0,string.len("models_set_")) == "models_set_" then
models.models[player:get_player_name()] = string.sub(field,string.len("models_set_")+1)
models.update_player_skin(player)
inventory_plus.set_inventory_formspec(player,models.formspec.main(player:get_player_name()))
end
if string.sub(field,0,string.len("models_page_")) == "models_page_" then
models.pages[player:get_player_name()] = tonumber(string.sub(field,string.len("models_page_")+1))
inventory_plus.set_inventory_formspec(player,models.formspec.main(player:get_player_name()))
end
end
end)

52
models/list.lua Normal file
View File

@ -0,0 +1,52 @@
-- Models mod for minetest
-- Allows players to choose their player model in-game
-- License: WTFPL
-- Based on the skins mod by Zeg9 (WTFPL)
models.list = {}
--models.register_model(name, modeldef)
--Registers a character model
--Parameters:
--name:
-- This should be a unique name for the model (use the node naming
-- convention, for example: "mobs:dungeon_master")
--modeldef:
-- mesh: mesh to be loaded
-- textures: textures for the mesh (uv map)
-- preview: image preview in the model selection menu
-- visual_size: vertical/horizontal size (depends on model shape/size)
-- collisionbox: collision box dimensions
models.register_model = function(name, modeldef)
models.list[name] = modeldef
end
--default player
models.register_model("character", {
mesh = "character.x",
textures = {"character.png"},
preview = "models_character_preview.png",
visual_size = {x=1, y=1},
collisionbox = {-0.5, -1, -0.5, 0.5, 1, 0.5}
})
--some test models using simple mobs if installed
if (minetest.get_modpath("mobs") ~= nil) then
models.register_model("mobs:dungeon_master", {
mesh = "mobs_dungeon_master.x",
textures = {"mobs_dungeon_master.png"},
preview = "models_dm_preview.png",
visual_size = {x=8, y=8},
collisionbox = {-0.7, -0.01, -0.7, 0.7, 2.6, 0.7}
})
models.register_model("mobs:sheep", {
mesh = "mobs_sheep.x",
textures = {"mobs_sheep.png"},
preview = "models_sheep_preview.png",
visual_size = {x=1, y=1},
collisionbox = {-0.4, -0.01, -0.4, 0.4, 1, 0.4}
})
end

1
models/optdepends.txt Normal file
View File

@ -0,0 +1 @@
mobs

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

0
modpack.txt Normal file
View File