Total overhaul

Big shoutout to Stu. Stu made this possible in the first place, and Stu
single-handedly updated the code this go round. Please, ladies and
gentlemen, give a big round to Stu!
master
Austin Williamson 2014-05-06 20:11:26 -06:00
parent 6d4474f251
commit 91269a3686
30 changed files with 11418 additions and 192 deletions

View File

@ -3,7 +3,7 @@
=====================================
depends: default, inventory_plus, unified_skins
depends: default, inventory_plus, stu's multiskin
Adds clothing to the game. Craft basic items out of wool- on the "loom"- dye, and wear!

View File

@ -1,25 +1,37 @@
local time = 0
local update_time = tonumber(minetest.setting_get("3d_clothing_update_time"))
if not update_time then
update_time = 1
minetest.setting_set("3d_clothing_update_time", tostring(update_time))
end
CLOTHING_INIT_DELAY = 1
CLOTHING_INIT_TIMES = 1
MULTISKIN_DEFAULT_SKIN = "captain_hindsight.png"
clothing = {
player_hp = {},
elements = {"head", "torso", "legs", "feet"},
formspec = "size[8,8.5]button[0,0;2,0.5;main;Back]"
.."list[current_player;main;0,4.5;8,4;]"
.."list[detached:player_name_clothing;clothing_head;3,0;1,1;]"
.."list[detached:player_name_clothing;clothing_torso;3,1;1,1;]"
.."list[detached:player_name_clothing;clothing_legs;3,2;1,1;]"
.."list[detached:player_name_clothing;clothing_feet;3,3;1,1;]",
formspec = "size[8,8.5]list[detached:player_name_clothing;clothing;0,1;2,3;]"
.."image[2,0.75;2,4;clothing_preview]"
.."list[current_player;main;0,4.5;8,4;]"
.."list[current_player;craft;4,1;3,3;]"
.."list[current_player;craftpreview;7,2;1,1;]",
textures = {},
}
clothing.def = {
state = 0,
count = 0
}
if inventory_plus then
clothing.formspec = "size[8,8.5]button[0,0;2,0.5;main;Back]"
.."list[detached:player_name_clothing;clothing;0,1;2,3;]"
.."image[2.5,0.75;2,4;clothing_preview]"
.."list[current_player;main;0,4.5;8,4;]"
elseif unified_inventory then
unified_inventory.register_button("clothing", {
type = "image",
image = "inventory_plus_clothing.png",
})
unified_inventory.register_page("clothing", {
get_formspec = function(player)
local name = player:get_player_name()
local formspec = "background[0.06,0.99;7.92,7.52;clothing_ui_form.png]"
.."label[0,0;Clothing]"
.."list[detached:"..name.."_clothing;clothing;0,1;2,3;]"
.."image[2.5,0.75;2,4;"..clothing.textures[name].preview.."]"
return {formspec=formspec}
end,
})
end
clothing.set_player_clothing = function(self, player)
if not player then
@ -27,154 +39,123 @@ clothing.set_player_clothing = function(self, player)
end
local name = player:get_player_name()
local player_inv = player:get_inventory()
local clothing_texture = uniskins.default_texture
local clothing_level = 0
local state = 0
local items = 0
if not name or not player_inv then
return
end
local clothing_texture = "clothing_trans.png"
local elements = {}
local textures = {}
for _,v in ipairs(self.elements) do
local stack = player_inv:get_stack("clothing_"..v, 1)
local level = stack:get_definition().groups["clothing_"..v]
if level then
local item = stack:get_name()
table.insert(textures, item:gsub("%:", "_")..".png")
clothing_level = clothing_level + level
state = state + stack:get_wear()
items = items+1
end
end
if table.getn(textures) > 0 then
clothing_texture = table.concat(textures, "^")
end
local clothing_groups = {fleshy=100}
if clothing_level > 0 then
clothing_groups.level = math.floor(clothing_level / 20)
clothing_groups.fleshy = 100 - clothing_level
end
-- player:set_clothing_groups(clothing_groups)
uniskins.clothing[name] = clothing_texture
uniskins:update_player_visuals(player)
clothing.def[name].state = state
clothing.def[name].count = items
end
clothing.update_clothing = function(self, player)
if not player then
return
end
local name = player:get_player_name()
local hp = player:get_hp() or 0
if hp == 0 or hp == self.player_hp[name] then
return
end
if self.player_hp[name] > hp then
local player_inv = player:get_inventory()
local clothing_inv = minetest.get_inventory({type="detached", name=name.."_clothing"})
if not clothing_inv then
return
end
local heal_max = 0
local state = 0
local items = 0
for _,v in ipairs(self.elements) do
local stack = clothing_inv:get_stack("clothing_"..v, 1)
if stack:get_count() > 0 then
local use = stack:get_definition().groups["clothing_use"] or 0
local heal = stack:get_definition().groups["clothing_heal"] or 0
local item = stack:get_name()
stack:add_wear(use)
clothing_inv:set_stack("clothing_"..v, 1, stack)
player_inv:set_stack("clothing_"..v, 1, stack)
state = state + stack:get_wear()
items = items+1
if stack:get_count() == 0 then
local desc = minetest.registered_items[item].description
if desc then
minetest.chat_send_player(name, "Your "..desc.." got destroyed!")
end
self:set_player_clothing(player)
local preview = multiskin:get_skin_name(name) or "clothing_preview"
preview = preview..".png"
for i=1, 6 do
local stack = player_inv:get_stack("clothing", i)
local item = stack:get_name()
if stack:get_count() == 1 then
local def = stack:get_definition()
if def.groups["clothing"] == 1 then
local texture = item:gsub("%:", "_")
table.insert(textures, texture..".png")
if not def.groups["no_preview"] then
preview = preview.."^"..texture.."_preview.png"
end
heal_max = heal_max + heal
end
end
clothing.def[name].state = state
clothing.def[name].count = items
if heal_max > math.random(100) then
player:set_hp(self.player_hp[name])
return
end
end
self.player_hp[name] = hp
if #textures > 0 then
clothing_texture = table.concat(textures, "^")
end
self.textures[name].clothing = clothing_texture
self.textures[name].preview = preview
multiskin[name].clothing = clothing_texture
multiskin:update_player_visuals(player)
end
-- Register Callbacks
clothing.get_clothing_formspec = function(self, name)
local formspec = clothing.formspec:gsub("player_name", name)
return formspec:gsub("clothing_preview", clothing.textures[name].preview)
end
clothing.update_inventory = function(self, player)
local name = player:get_player_name()
if unified_inventory then
if unified_inventory.current_page[name] == "clothing" then
unified_inventory.set_inventory_formspec(player, "clothing")
end
else
local formspec = clothing:get_clothing_formspec(name)
if inventory_plus then
local page = player:get_inventory_formspec()
if page:find("detached:"..name.."_clothing") then
inventory_plus.set_inventory_formspec(player, formspec)
end
else
player:set_inventory_formspec(formspec)
end
end
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
local name = player:get_player_name()
if fields.clothing then
local formspec = clothing.formspec:gsub("player_name", name)
if inventory_plus and fields.clothing then
local formspec = clothing:get_clothing_formspec(name)
inventory_plus.set_inventory_formspec(player, formspec)
return
end
for field, _ in pairs(fields) do
if string.sub(field,0,string.len("skins_set_")) == "skins_set_" then
minetest.after(0, function(player)
uniskins.skin[name] = skins.skins[name]..".png"
uniskins:update_player_visuals(player)
end, player)
end
end
end)
minetest.register_on_joinplayer(function(player)
inventory_plus.register_button(player,"clothing", "clothing")
local player_inv = player:get_inventory()
multiskin:init(player)
local name = player:get_player_name()
local player_inv = player:get_inventory()
local clothing_inv = minetest.create_detached_inventory(name.."_clothing",{
on_put = function(inv, listname, index, stack, player)
player:get_inventory():set_stack(listname, index, stack)
clothing:set_player_clothing(player)
clothing:update_inventory(player)
end,
on_take = function(inv, listname, index, stack, player)
player:get_inventory():set_stack(listname, index, nil)
clothing:set_player_clothing(player)
clothing:update_inventory(player)
end,
on_move = function(inv, from_list, from_index, to_list, to_index, count, player)
local plaver_inv = player:get_inventory()
local stack = inv:get_stack(to_list, to_index)
player_inv:set_stack(to_list, to_index, stack)
player_inv:set_stack(from_list, from_index, nil)
clothing:set_player_clothing(player)
clothing:update_inventory(player)
end,
allow_put = function(inv, listname, index, stack, player)
if inv:is_empty(listname) then
return 1
end
return 0
return 1
end,
allow_take = function(inv, listname, index, stack, player)
return stack:get_count()
end,
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
return 0
return count
end,
})
for _,v in ipairs(clothing.elements) do
local list = "clothing_"..v
player_inv:set_size(list, 1)
clothing_inv:set_size(list, 1)
clothing_inv:set_stack(list, 1, player_inv:get_stack(list, 1))
if inventory_plus then
inventory_plus.register_button(player,"clothing", "Clothing")
end
clothing.player_hp[name] = 0
clothing.def[name] = {
state = 0,
count = 0
clothing_inv:set_size("clothing", 6)
player_inv:set_size("clothing", 6)
for i=1, 6 do
local stack = player_inv:get_stack("clothing", i)
clothing_inv:set_stack("clothing", i, stack)
end
clothing.textures[name] = {
clthing = "clothing_trans.png",
preview = "clothing_preview.png",
}
minetest.after(0, function(player)
clothing:set_player_clothing(player)
end, player)
end)
minetest.register_globalstep(function(dtime)
time = time + dtime
if time > update_time then
for _,player in ipairs(minetest.get_connected_players()) do
clothing:update_clothing(player)
end
time = 0
for i=1, CLOTHING_INIT_TIMES do
minetest.after(CLOTHING_INIT_DELAY * i, function(player)
clothing:set_player_clothing(player)
if inventory_plus == nil and unified_inventory == nil then
clothing:update_inventory(player)
end
end, player)
end
end)

Binary file not shown.

After

Width:  |  Height:  |  Size: 402 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 549 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 664 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 936 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 467 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 516 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 828 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 303 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 239 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 B

View File

@ -1,3 +1,4 @@
default
inventory_plus
unified_skins
multiskin
inventory_plus?
unified_inventory?

154
init.lua
View File

@ -1,42 +1,48 @@
dofile(minetest.get_modpath(minetest.get_current_modname()).."/clothing.lua")
--[[
BIG THANKS TO STU, WHO MADE THIS ALL POSSIBLE
]]--
-- Crafting
local craft_ingreds = {
red = "wool:red",
blue = "wool:blue",
yellow = "wool:yellow",
red = "wool:red",
blue = "wool:blue",
yellow = "wool:yellow",
}
for k, v in pairs(craft_ingreds) do
minetest.register_craft({
output = "clothing:shirt_"..k,
recipe = {
{v, "", v},
{v, v, v},
{v, v, v},
},
})
minetest.register_craft({
output = "clothing:pants_"..k,
recipe = {
{v, v, v},
{v, "", v},
{v, "", v},
},
})
minetest.register_tool("clothing:shirt_"..k, {
description = k.." shirt",
inventory_image = "clothing_inv_shirt_"..k.."_overlay.png ^ clothing_shirt_inv_white.png",
texture = "clothing_shirt_"..k.."_overlay.png ^ clothing_shirt_white.png",
groups = {armor_torso=1, armor_heal=5, armor_use=2000},
wear = 0,
})
minetest.register_craft({
output = "clothing:shirt_"..k,
recipe = {
{v, "", v},
{v, v, v},
{v, v, v},
},
})
minetest.register_craft({
output = "clothing:pants_"..k,
recipe = {
{v, v, v},
{v, "", v},
{v, "", v},
},
})
minetest.register_tool("clothing:shirt_"..k, {
description = k.." shirt",
inventory_image = "clothing_inv_shirt_"..k.."_overlay.png ^ clothing_shirt_inv_white.png",
texture = "clothing_shirt_"..k.."_overlay.png ^ clothing_shirt_white.png",
groups = {clothing=1},
wear = 0,
})
minetest.register_tool("clothing:pants_"..k, {
description = k.." pants",
inventory_image = "clothing_inv_pants_"..k.."_overlay.png ^ clothing_pants_inv_white.png",
texture = "clothing_pants_"..k.."_overlay.png ^ clothing_pants_white.png",
groups = {armor_legs=1, armor_heal=5, armor_use=2000},
wear = 0,
})
minetest.register_tool("clothing:pants_"..k, {
description = k.." pants",
inventory_image = "clothing_inv_pants_"..k.."_overlay.png ^ clothing_pants_inv_white.png",
texture = "clothing_pants_"..k.."_overlay.png ^ clothing_pants_white.png",
groups = {clothing=1},
wear = 0,
})
end
@ -45,32 +51,64 @@ end
-- Register White Stuff
minetest.register_tool("clothing:shirt_white", {
description = "White shirt",
inventory_image = "clothing_inv_shirt_white.png",
texture = "clothing_shirt_white.png",
groups = {armor_torso=1, armor_heal=5, armor_use=2000},
wear = 0,
description = "White shirt",
inventory_image = "clothing_inv_shirt_white.png",
texture = "clothing_shirt_white.png",
groups = {clothing=1},
wear = 0,
})
minetest.register_tool("clothing:pants_white", {
description = "White pants",
inventory_image = "clothing_inv_pants_white.png",
texture = "clothing_pants_white.png",
groups = {armor_legs=1, armor_heal=5, armor_use=2000},
wear = 0,
description = "White pants",
inventory_image = "clothing_inv_pants_white.png",
texture = "clothing_pants_white.png",
groups = {clothing=1},
wear = 0,
})
minetest.register_craft({
output = "clothing:shirt_white",
recipe = {
{"wool:white", "", "wool:white"},
{"wool:white", "wool:white", "wool:white"},
{"wool:white", "wool:white", "wool:white"},
},
})
minetest.register_craft({
output = "clothing:pants_white",
recipe = {
{"wool:white", "wool:white", "wool:white"},
{"wool:white", "", "wool:white"},
{"wool:white", "", "wool:white"},
},
})
output = "clothing:shirt_white",
recipe = {
{"wool:white", "", "wool:white"},
{"wool:white", "wool:white", "wool:white"},
{"wool:white", "wool:white", "wool:white"},
},
})
minetest.register_craft({
output = "clothing:pants_white",
recipe = {
{"wool:white", "wool:white", "wool:white"},
{"wool:white", "", "wool:white"},
{"wool:white", "", "wool:white"},
},
})
-- Stu's Stuff
minetest.register_craftitem("clothing:hindsight_shirt", {
description = "Captain Hindsight Shirt",
inventory_image = "clothing_inv_hindsight_shirt.png",
groups = {clothing=1},
})
minetest.register_craftitem("clothing:hindsight_pants", {
description = "Captain Hindsight Pants",
inventory_image = "clothing_inv_hindsight_pants.png",
groups = {clothing=1},
})
minetest.register_craftitem("clothing:hindsight_boots", {
description = "Captain Hindsight Boots",
inventory_image = "clothing_inv_hindsight_boots.png",
groups = {clothing=1},
})
minetest.register_craftitem("clothing:hindsight_cape", {
description = "Captain Hindsight Cape",
inventory_image = "clothing_inv_hindsight_cape.png",
groups = {clothing=1, no_preview=1},
})
minetest.register_craftitem("clothing:paper_bag", {
description = "Paper Bag",
inventory_image = "clothing_inv_paper_bag.png",
groups = {clothing=1, no_preview=1},
})

0
modpack.txt Normal file
View File

2
multiskin/depends.txt Normal file
View File

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

93
multiskin/init.lua Normal file
View File

@ -0,0 +1,93 @@
MULTISKIN_DEFAULT_SKIN = "character.png"
MULTISKIN_TRANS = "multiskin_trans.png"
multiskin = {}
function multiskin:init(player)
default.player_set_model(player, "multiskin.x")
local name = player:get_player_name()
multiskin[name] = {
skin = MULTISKIN_DEFAULT_SKIN,
armor = MULTISKIN_TRANS,
wielditem = MULTISKIN_TRANS,
clothing = MULTISKIN_TRANS,
}
if minetest.get_modpath("skins") then
local skin = skins.skins[name]
if skin and skins.get_type(skin) == skins.type.MODEL then
multiskin[name].skin = skin..".png"
end
elseif minetest.get_modpath("u_skins") then
local skin = u_skins.u_skins[name]
if skin and u_skins.get_type(skin) == u_skins.type.MODEL then
multiskin[name].skin = skin..".png"
end
end
if minetest.get_modpath("player_textures") then
local filename = minetest.get_modpath("player_textures").."/textures/player_"..name
local f = io.open(filename..".png")
if f then
f:close()
multiskin[name].skin = "player_"..name..".png"
end
end
end
function multiskin:update_player_visuals(player)
if not player then
return
end
local name = player:get_player_name()
if multiskin[name] then
default.player_set_textures(player, {
multiskin[name].skin,
multiskin[name].armor,
multiskin[name].wielditem,
multiskin[name].clothing,
})
end
end
function multiskin:get_skin_name(name)
local skin = nil
if skins then
skin = skins.skins[name] or MULTISKIN_DEFAULT_SKIN
elseif u_skins then
skin = u_skins.u_skins[name] or MULTISKIN_DEFAULT_SKIN
end
return skin
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
local name = player:get_player_name()
for field, _ in pairs(fields) do
if string.find(field, "skins_set_") then
minetest.after(0, function(player)
local skin = multiskin:get_skin_name(name)
if skin then
multiskin[name].skin = skin..".png"
multiskin:update_player_visuals(player)
end
end, player)
end
end
end)
default.player_register_model("multiskin.x", {
animation_speed = 30,
textures = {
MULTISKIN_DEFAULT_SKIN,
MULTISKIN_TRANS,
MULTISKIN_TRANS,
MULTISKIN_TRANS,
},
animations = {
stand = {x=0, y=79},
lay = {x=162, y=166},
walk = {x=168, y=187},
mine = {x=189, y=198},
walk_mine = {x=200, y=219},
sit = {x=81, y=160},
},
})

Binary file not shown.

11104
multiskin/models/multiskin.x Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 146 B

7
readme.txt Normal file
View File

@ -0,0 +1,7 @@
Credits:
====
Base textures - based on Stu's 3d_armor
Captain Hindsight - contributed by Stu
Initial code - based on Stu's 3d_armor
Major code overhaul - contributed by Stu
Multiskin code - contributed by Stu