allow wardrobe to support player provided skins, bugs may occur with larger than 64x32 or 64x64 skins

master
Jordan Snelling 2018-02-15 20:52:18 +00:00
parent e4cf1d02b7
commit 80e010fc64
14 changed files with 234 additions and 184 deletions

View File

@ -675,7 +675,7 @@ function doors.register_trapdoor(name, def)
end
doors.register_trapdoor("doors:trapdoor", {
description = "Trapdoor",
description = "Oak Trapdoor",
inventory_image = "doors_trapdoor.png",
wield_image = "doors_trapdoor.png",
tile_front = "doors_trapdoor.png",
@ -685,7 +685,7 @@ doors.register_trapdoor("doors:trapdoor", {
})
doors.register_trapdoor("doors:trapdoor_steel", {
description = "Steel Trapdoor",
description = "Iron Trapdoor",
inventory_image = "doors_trapdoor_steel.png",
wield_image = "doors_trapdoor_steel.png",
tile_front = "doors_trapdoor_steel.png",
@ -700,9 +700,8 @@ doors.register_trapdoor("doors:trapdoor_steel", {
minetest.register_craft({
output = 'doors:trapdoor 2',
recipe = {
{'group:wood', 'group:wood', 'group:wood'},
{'group:wood', 'group:wood', 'group:wood'},
{'', '', ''},
{'core:oak_planks', 'core:oak_planks', 'core:oak_planks'},
{'core:oak_planks', 'core:oak_planks', 'core:oak_planks'},
}
})
@ -714,79 +713,6 @@ minetest.register_craft({
}
})
-----key tool-----
minetest.register_tool("doors:key", {
description = "Key Tool",
inventory_image = "doors_key.png",
on_use = function(itemstack, user, pointed_thing)
local pos = pointed_thing.under
if pointed_thing.type ~= "node"
or not doors.get(pos) then
return
end
local player_name = user:get_player_name()
local meta = minetest.get_meta(pos) ; if not meta then return end
local owner = meta:get_string("doors_owner")
local prot = meta:get_string("doors_protected")
local ok = 0
local infotext = ""
if prot == ""
and owner == "" then
-- flip normal to owned
if minetest.is_protected(pos, player_name) then
minetest.record_protection_violation(pos, player_name)
else
infotext = "Owned by " .. player_name
owner = player_name
prot = ""
ok = 1
end
elseif prot == ""
and owner ~= "" then
-- flip owned to protected
if player_name == owner then
infotext = "Protected by " .. player_name
owner = ""
prot = player_name
ok = 1
end
elseif prot ~= ""
and owner == "" then
-- flip protected to normal
if player_name == prot then
owner = ""
prot = ""
ok = 1
end
end
if ok == 1 then
meta:set_string("infotext", infotext)
meta:set_string("doors_owner", owner)
meta:set_string("doors_protected", prot)
if not minetest.setting_getbool("creative_mode") then
itemstack:add_wear(65535 / 50)
end
end
return itemstack
end,
})
----fence gate----
function doors.register_fencegate(name, def)

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 344 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 162 B

View File

@ -6,17 +6,25 @@ local p_choice = {}
local p_rgb = {}
local p_skin = {}
local p_size = {}
p_choice = minetest.deserialize(wardrobe.hand_textures:get_string("c"))
p_rgb = minetest.deserialize(wardrobe.hand_textures:get_string("rgb"))
p_skin = minetest.deserialize(wardrobe.hand_textures:get_string("skin"))
p_size = minetest.deserialize(wardrobe.hand_textures:get_string("size"))
local count = 1
if wardrobe.hand_textures:get_string("c") == "" then
else
for k, v in pairs(p_choice) do
for k, v in pairs(p_skin) do
player_names[count] = k
@ -34,18 +42,23 @@ else
--print(":newhand:" .. v)
if v == "Virtuoel" then
minetest.register_node(":newhand:Virtuoel", {
if p_skin[v] ~= nil then
local tex_string = "wardrobe_player_" .. v .. ".png"
if p_size[v] == 32 then tex_string = "[combine:64x64:0,0=" .. tex_string end -- caution, will not support larger than 64 wide skins
minetest.register_node(":newhand:" .. v, {
description = "",
tiles = {
"wardrobe_player_virtuoel.png",
tex_string
},
on_place = function(itemstack, placer, pointed_thing)
local stack = ItemStack(":")
local ret = minetest.item_place(stack, placer, pointed_thing)
return ItemStack("newhand:virtuoel" .. itemstack:get_count())
return ItemStack("newhand:" .. v ..itemstack:get_count())
end,
drawtype = "mesh",
@ -53,36 +66,32 @@ else
node_placement_prediction = "",
})
else
minetest.register_node(":newhand:" .. v, {
description = "",
tiles = {
"(wardrobe_skin.png^[multiply:#".. p_rgb[v][1].. ")^"..
"(wardrobe_under_shirt_" .. p_choice[v][5] .. ".png^[multiply:#".. p_rgb[v][5].. ")^"..
"(wardrobe_under_shirt_" .. p_choice[v][6] .. ".png^[multiply:#".. p_rgb[v][6].. ")^"..
"(wardrobe_shirt_" .. p_choice[v][11] .. ".png^[multiply:#".. p_rgb[v][11].. ")^"..
"(wardrobe_shirt_" .. p_choice[v][12] .. ".png^[multiply:#".. p_rgb[v][12]..")",
},
on_place = function(itemstack, placer, pointed_thing)
local stack = ItemStack(":")
local ret = minetest.item_place(stack, placer, pointed_thing)
return ItemStack("newhand:" .. v ..itemstack:get_count())
end,
minetest.register_node(":newhand:" .. v, {
description = "",
--sunlight_propagates = true,
--visual_scale = 1,
--wield_scale = {x=1,y=1,z=1},
--paramtype = "light",
drawtype = "mesh",
mesh = "hand.b3d",
node_placement_prediction = "",
})
tiles = {
"(wardrobe_skin.png^[multiply:#".. p_rgb[v][1].. ")^"..
"(wardrobe_under_shirt_" .. p_choice[v][5] .. ".png^[multiply:#".. p_rgb[v][5].. ")^"..
"(wardrobe_under_shirt_" .. p_choice[v][6] .. ".png^[multiply:#".. p_rgb[v][6].. ")^"..
"(wardrobe_shirt_" .. p_choice[v][11] .. ".png^[multiply:#".. p_rgb[v][11].. ")^"..
"(wardrobe_shirt_" .. p_choice[v][12] .. ".png^[multiply:#".. p_rgb[v][12]..")",
},
on_place = function(itemstack, placer, pointed_thing)
local stack = ItemStack(":")
local ret = minetest.item_place(stack, placer, pointed_thing)
return ItemStack("newhand:" .. v ..itemstack:get_count())
end,
drawtype = "mesh",
mesh = "hand.b3d",
node_placement_prediction = "",
})
end

View File

@ -50,7 +50,33 @@ else -- if the serialized data does exist, load it into memory
end
if wardrobe.hand_textures:get_string("skin") == "" then
wardrobe.player_has_skin = {}
wardrobe.player_skin_size = {}
else
wardrobe.player_has_skin = minetest.deserialize(wardrobe.hand_textures:get_string("skin"))
wardrobe.player_skin_size = minetest.deserialize(wardrobe.hand_textures:get_string("size"))
end
local function get_size(w) -- ported from a fork
local file = io.open(w)
if file then
file:seek("set", 16)
local widthstr, heightstr = file:read(4), file:read(4)
local width=widthstr:sub(1,1):byte()*16777216+widthstr:sub(2,2):byte()*65536+widthstr:sub(3,3):byte()*256+widthstr:sub(4,4):byte()
local height=heightstr:sub(1,1):byte()*16777216+heightstr:sub(2,2):byte()*65536+heightstr:sub(3,3):byte()*256+heightstr:sub(4,4):byte()
file:close()
return width, height
end
end
-- initalize the external hands module.
@ -794,6 +820,12 @@ function wardrobe.update_dummy(pos, player, fields)
local pname = player:get_player_name()
local entity = minetest.get_objects_inside_radius({x=pos.x, y=pos.y+0.5, z=pos.z}, 0.1)
if wardrobe.player_has_skin[pname] then
return
end
if fields ~= nil then
wardrobe.save_text_fields(fields, pname)
@ -854,7 +886,7 @@ function wardrobe.close_eyes(player)
local pname = player:get_player_name()
if pname == "Virtuoel" then
if wardrobe.player_has_skin[pname] then
return
@ -909,30 +941,48 @@ function wardrobe.apply_to_player(player, fields)
local pname = player:get_player_name()
if fields ~= nil then
wardrobe.save_text_fields(fields, pname)
end
if pname == "Virtuoel" then
if wardrobe.player_has_skin[pname] then
player:set_properties({
textures = {
"ptextures_transparent.png",
"wardrobe_player_virtuoel.png",
"ptextures_transparent.png",
"ptextures_transparent.png",
"ptextures_transparent.png",
"ptextures_transparent.png",
"ptextures_transparent.png",
}
})
if wardrobe.player_skin_size[pname] == 32 then
return
player:set_properties({
textures = {
"wardrobe_player_" .. pname .. ".png",
"ptextures_transparent.png",
"ptextures_transparent.png",
"ptextures_transparent.png",
"ptextures_transparent.png",
"ptextures_transparent.png",
"ptextures_transparent.png",
},
})
elseif wardrobe.player_skin_size[pname] == 64 then
player:set_properties({
textures = {
"ptextures_transparent.png",
"wardrobe_player_" .. pname .. ".png",
"ptextures_transparent.png",
"ptextures_transparent.png",
"ptextures_transparent.png",
"ptextures_transparent.png",
"ptextures_transparent.png",
},
})
end
else
if fields ~= nil then
wardrobe.save_text_fields(fields, pname)
end
player:set_properties({
textures = {
"ptextures_transparent.png",
@ -1037,61 +1087,102 @@ end
function wardrobe.load_user_data(player)
-- let's check if the user has a pre-installed skin first!
local pname = player:get_player_name()
-- load non-RGB choices --0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2
--1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2
if player:get_attribute("wardrobe_choices") == nil then
wardrobe.formspec_selections[pname] = {2,2,2,1,2,1,2,1,2,1,2,1,1,1,2,1,1,1,1,1,1,1}
print ("[Wardrobe] Failed Loading Texture Data for Player: " .. pname)
local f = io.open(wardrobe.texture_path.."wardrobe_player_"..pname..".png")
if f then
f:close()
wardrobe.player_has_skin[pname] = true
print ("[Wardrobe] " .. pname .. " has a custom user skin!")
local w, h = get_size(wardrobe.texture_path.."wardrobe_player_"..pname..".png")
if w / h == 2 then -- this is a 64x32 type skin
wardrobe.player_skin_size[pname] = 32
print ("[Wardrobe] " .. pname .. " has a 64x32 type skin!")
elseif w / h == 1 then -- this is a square 64x64 type skin;
wardrobe.player_skin_size[pname] = 64
print ("[Wardrobe] " .. pname .. " has a 64x64 type skin!")
end
player:set_attribute("wardrobe_choices", minetest.serialize(wardrobe.formspec_selections))
else
wardrobe.formspec_selections[pname] = minetest.deserialize(player:get_attribute("wardrobe_choices"))
print ("[Wardrobe] Loaded Texture Data for Player: " .. pname)
wardrobe.player_skin_size[pname] = 64 -- we use this for the hands module
-- setup the wardrobe API because no custom skin was found
-- create from template clothing --0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2
--1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2
if player:get_attribute("wardrobe_choices") == nil then
wardrobe.formspec_selections[pname] = {2,2,2,1,2,1,2,1,2,1,2,1,1,1,2,1,1,1,1,1,1,1}
print ("[Wardrobe] Failed Loading Texture Data for Player: " .. pname)
player:set_attribute("wardrobe_choices", minetest.serialize(wardrobe.formspec_selections))
else
wardrobe.formspec_selections[pname] = minetest.deserialize(player:get_attribute("wardrobe_choices"))
print ("[Wardrobe] Loaded Texture Data for Player: " .. pname)
end
-- create from template RGB
if player:get_attribute("wardrobe_rgb") == nil then
wardrobe.formspec_selections_rgb[pname] = {}
wardrobe.formspec_selections_rgb[pname][1] = "e3c0a3"
wardrobe.formspec_selections_rgb[pname][2] = "ffffff"
wardrobe.formspec_selections_rgb[pname][3] = "3636eb"
wardrobe.formspec_selections_rgb[pname][4] = "4a301b"
wardrobe.formspec_selections_rgb[pname][5] = "dddddd"
wardrobe.formspec_selections_rgb[pname][6] = "ffffff"
wardrobe.formspec_selections_rgb[pname][7] = "1b275d"
wardrobe.formspec_selections_rgb[pname][8] = "ffffff"
wardrobe.formspec_selections_rgb[pname][9] = "777777"
wardrobe.formspec_selections_rgb[pname][10] = "ffffff"
wardrobe.formspec_selections_rgb[pname][11] = "39881c"
wardrobe.formspec_selections_rgb[pname][12] = "ffffff"
wardrobe.formspec_selections_rgb[pname][13] = "ffffff"
wardrobe.formspec_selections_rgb[pname][14] = "ffffff"
wardrobe.formspec_selections_rgb[pname][15] = "141414"
wardrobe.formspec_selections_rgb[pname][16] = "ffffff"
wardrobe.formspec_selections_rgb[pname][17] = "ffffff"
wardrobe.formspec_selections_rgb[pname][18] = "ffffff"
wardrobe.formspec_selections_rgb[pname][19] = "ffffff"
wardrobe.formspec_selections_rgb[pname][20] = "ffffff"
wardrobe.formspec_selections_rgb[pname][21] = "ffffff"
wardrobe.formspec_selections_rgb[pname][22] = "ffffff"
print ("[Wardrobe] Failed Loading RGB Data for Player: " .. pname)
player:set_attribute("wardrobe_rgb", minetest.serialize(wardrobe.formspec_selections_rgb[pname]))
--wardrobe.hand_textures:set_string("rgb", minetest.serialize(wardrobe.formspec_selections_rgb))
else
wardrobe.formspec_selections_rgb[pname] = minetest.deserialize(player:get_attribute("wardrobe_rgb"))
print ("[Wardrobe] Loaded RGB Data for Player: " .. pname)
end
end
-- load RGB
if player:get_attribute("wardrobe_rgb") == nil then
wardrobe.formspec_selections_rgb[pname] = {}
wardrobe.formspec_selections_rgb[pname][1] = "e3c0a3"
wardrobe.formspec_selections_rgb[pname][2] = "ffffff"
wardrobe.formspec_selections_rgb[pname][3] = "3636eb"
wardrobe.formspec_selections_rgb[pname][4] = "4a301b"
wardrobe.formspec_selections_rgb[pname][5] = "dddddd"
wardrobe.formspec_selections_rgb[pname][6] = "ffffff"
wardrobe.formspec_selections_rgb[pname][7] = "1b275d"
wardrobe.formspec_selections_rgb[pname][8] = "ffffff"
wardrobe.formspec_selections_rgb[pname][9] = "777777"
wardrobe.formspec_selections_rgb[pname][10] = "ffffff"
wardrobe.formspec_selections_rgb[pname][11] = "39881c"
wardrobe.formspec_selections_rgb[pname][12] = "ffffff"
wardrobe.formspec_selections_rgb[pname][13] = "ffffff"
wardrobe.formspec_selections_rgb[pname][14] = "ffffff"
wardrobe.formspec_selections_rgb[pname][15] = "141414"
wardrobe.formspec_selections_rgb[pname][16] = "ffffff"
wardrobe.formspec_selections_rgb[pname][17] = "ffffff"
wardrobe.formspec_selections_rgb[pname][18] = "ffffff"
wardrobe.formspec_selections_rgb[pname][19] = "ffffff"
wardrobe.formspec_selections_rgb[pname][20] = "ffffff"
wardrobe.formspec_selections_rgb[pname][21] = "ffffff"
wardrobe.formspec_selections_rgb[pname][22] = "ffffff"
print ("[Wardrobe] Failed Loading RGB Data for Player: " .. pname)
player:set_attribute("wardrobe_rgb", minetest.serialize(wardrobe.formspec_selections_rgb[pname]))
--wardrobe.hand_textures:set_string("rgb", minetest.serialize(wardrobe.formspec_selections_rgb))
else
wardrobe.formspec_selections_rgb[pname] = minetest.deserialize(player:get_attribute("wardrobe_rgb"))
print ("[Wardrobe] Loaded RGB Data for Player: " .. pname)
end
wardrobe.hand_textures:set_string("c", minetest.serialize(wardrobe.formspec_selections))
wardrobe.hand_textures:set_string("rgb", minetest.serialize(wardrobe.formspec_selections_rgb))
wardrobe.hand_textures:set_string("skin", minetest.serialize(wardrobe.player_has_skin))
wardrobe.hand_textures:set_string("size", minetest.serialize(wardrobe.player_skin_size))
end
@ -1100,6 +1191,9 @@ function wardrobe.save_user_data(player)
wardrobe.hand_textures:set_string("c", minetest.serialize(wardrobe.formspec_selections))
wardrobe.hand_textures:set_string("rgb", minetest.serialize(wardrobe.formspec_selections_rgb))
wardrobe.hand_textures:set_string("skin", minetest.serialize(wardrobe.player_has_skin))
wardrobe.hand_textures:set_string("size", minetest.serialize(wardrobe.player_skin_size))
player:set_attribute("wardrobe_choices", minetest.serialize(wardrobe.formspec_selections[pname]))
player:set_attribute("wardrobe_rgb", minetest.serialize(wardrobe.formspec_selections_rgb[pname]))
@ -1108,6 +1202,6 @@ end
minetest.register_on_joinplayer(function(player)
wardrobe.load_user_data(player)
wardrobe.apply_to_player(player)
end)

Binary file not shown.

After

Width:  |  Height:  |  Size: 743 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 743 B

View File

@ -37,10 +37,25 @@ zcg.add_craft = function(input, output, groups)
return
end
if not groups then groups = {} end
local stack_num = ItemStack(nil)
if input.output == nil then
-- prevent a crash indexing nil
else
stack_num = ItemStack(input.output):get_count()
end
--print(stack_num:get_count(), input.output)
local c = {}
c.width = input.width
c.type = input.type
c.items = input.items
c.number = stack_num
if c.items == nil then return end
for i, item in pairs(c.items) do
if item:sub(0,6) == "group:" then
@ -54,7 +69,8 @@ zcg.add_craft = function(input, output, groups)
zcg.add_craft({
width = c.width,
type = c.type,
items = table_copy(c.items)
items = table_copy(c.items),
output = input.output
}, output, g2) -- it is needed to copy the table, else groups won't work right
end
return
@ -109,14 +125,12 @@ zcg.formspec = function(pn)
.. "listcolors[#573b2e;#de9860;#ffffff;#3f2832;#ffffff]"
if zcg.users[pn].history.index > 1 then
formspec = formspec .. "button[0,2;1.55,1;zcg_previous;Last Recipe]"
formspec = formspec .. "button[0,3.1;2.25,1;zcg_previous;Last Recipe]"
else
--formspec = formspec .. "image[0,1;1,1;zcg_previous_inactive.png]"
end
if zcg.users[pn].history.index < #zcg.users[pn].history.list then
formspec = formspec .. "button[1.45,2;1.55,1;zcg_next;Next Recipe]"
formspec = formspec .. "button[2.25,3.1;2.25,1;zcg_next;Next Recipe]"
else
--formspec = formspec .. "image[1,1;1,1;zcg_next_inactive.png]"
end
-- Show craft recipe
if current_item ~= "" then
@ -146,6 +160,11 @@ zcg.formspec = function(pn)
end
formspec = formspec .. "image[6,1;1,1;core_crafting_arrow.png]"
formspec = formspec .. "item_image_button[7,1;1,1;"..zcg.users[pn].current_item..";;]"
formspec = formspec .. "label[7.8,1.5;" .. tostring(c.number) .. "]"
--print (dump(zcg.crafts["stairs:slab_grass_wildlands"]))
end
end
end
@ -159,8 +178,10 @@ zcg.formspec = function(pn)
if i >= npp then break end
formspec = formspec .. "item_image_button["..(i%8)..","..(math.floor(i/8)+5)..";1,1;"..name..";zcg:"..name..";]"
i = i+1
end
end
if page > 0 then
formspec = formspec .. "button[0,8.1;2.25,1;zcg_page:"..(page-1)..";Previous Page]"
end