Merge pull request #4 from kaeza/master

Various fixes and additions
This commit is contained in:
VanessaE 2013-03-11 09:54:05 -07:00
commit e0c7ad2d6a
13 changed files with 237 additions and 83 deletions

View File

@ -23,20 +23,6 @@ minetest.register_node("homedecor:fence_brass", {
groups = {snappy=3},
sounds = default.node_sound_wood_defaults(),
walkable = true,
on_rightclick = function(pos, node, clicker)
if not homedecor_node_is_owned(pos, clicker) then
local fdir = minetest.dir_to_facedir(clicker:get_look_dir())
local itemstack = clicker:get_wielded_item()
if itemstack:get_name() == "default:sign_wall" then
minetest.env:add_node(pos, {name = "homedecor:fence_brass_with_sign", param2 = fdir})
itemstack:take_item()
return itemstack
else
print(S("want to simply place the wielded item like usual."))
-- What goes here if I want to just place the wielded node (dirt, cobble, etc) normally?
end
end
end,
on_place = function(itemstack, placer, pointed_thing)
if not homedecor_node_is_owned(pointed_thing.under, placer) then
@ -63,31 +49,6 @@ minetest.register_node("homedecor:fence_wrought_iron", {
groups = {snappy=3},
sounds = default.node_sound_wood_defaults(),
walkable = true,
on_rightclick = function(pos, node, clicker)
if not homedecor_node_is_owned(pos, clicker) then
local fdir = minetest.dir_to_facedir(clicker:get_look_dir())
local itemstack = clicker:get_wielded_item()
if itemstack:get_name() == "default:sign_wall" then
minetest.env:add_node(pos, {name = "homedecor:fence_wrought_iron_with_sign", param2 = fdir})
itemstack:take_item()
clicker:set_wielded_item(itemstack)
return itemstack
else
print(S("want to simply place the wielded item like usual."))
-- What goes here if I want to just place the wielded node (dirt, cobble, etc) normally?
end
end
end,
on_place = function(itemstack, placer, pointed_thing)
if not homedecor_node_is_owned(pointed_thing.under, placer) then
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
minetest.env:add_node(pointed_thing.above, {name = "homedecor:fence_wrought_iron", param2 = fdir})
itemstack:take_item()
placer:set_wielded_item(itemstack)
return itemstack
end
end
})
-- brass/wrought iron with signs:
@ -130,18 +91,6 @@ minetest.register_node("homedecor:fence_brass_with_sign", {
{ items = { "homedecor:fence_brass" }},
},
},
on_construct = function(pos)
homedecor_construct_sign(pos)
end,
on_destruct = function(pos)
homedecor_destruct_sign(pos)
end,
on_receive_fields = function(pos, formname, fields, sender)
homedecor_update_sign(pos, fields)
end,
on_punch = function(pos, node, puncher)
homedecor_update_sign(pos)
end,
})
minetest.register_node("homedecor:fence_wrought_iron_with_sign", {
@ -182,18 +131,6 @@ minetest.register_node("homedecor:fence_wrought_iron_with_sign", {
{ items = { "homedecor:fence_wrought_iron" }},
},
},
on_construct = function(pos)
homedecor_construct_sign(pos)
end,
on_destruct = function(pos)
homedecor_destruct_sign(pos)
end,
on_receive_fields = function(pos, formname, fields, sender)
homedecor_update_sign(pos, fields)
end,
on_punch = function(pos, node, puncher)
homedecor_update_sign(pos)
end,
})
-- other types of fences
@ -700,4 +637,8 @@ minetest.register_on_punchnode(function (pos, node)
end
end)
minetest.register_alias("homedecor:fence_wood_with_sign", "signs:sign_post")
homedecor_register_fence_with_sign("default:fence_wood", "signs:sign_post")
homedecor_register_fence_with_sign("homedecor:fence_brass", "homedecor:fence_brass_with_sign")
homedecor_register_fence_with_sign("homedecor:fence_wrought_iron", "homedecor:fence_wrought_iron_with_sign")

View File

@ -1,22 +1,11 @@
-- This code was borrowed from Pilzadam's rework of thexyz's signs mod
-- Font: 04.jp.org
-- Boilerplate to support localized strings if intllib mod is installed.
local S
if (minetest.get_modpath("intllib")) then
dofile(minetest.get_modpath("intllib").."/intllib.lua")
S = intllib.Getter(minetest.get_current_modname())
else
S = function ( s ) return s end
end
-- load characters map
local chars_file = io.open(minetest.get_modpath("homedecor").."/characters", "r")
local charmap = {}
local max_chars = 16
if not chars_file then
print("[homedecor] "..S("E: character map file not found"))
print("[signs] E: character map file not found")
else
while true do
local char = chars_file:read("*l")
@ -29,6 +18,20 @@ else
end
end
local signs = {
{delta = {x = 0, y = 0, z = 0.399}, yaw = 0},
{delta = {x = 0.399, y = 0, z = 0}, yaw = math.pi / -2},
{delta = {x = 0, y = 0, z = -0.399}, yaw = math.pi},
{delta = {x = -0.399, y = 0, z = 0}, yaw = math.pi / 2},
}
local signs_yard = {
{delta = {x = 0, y = 0, z = -0.05}, yaw = 0},
{delta = {x = -0.05, y = 0, z = 0}, yaw = math.pi / -2},
{delta = {x = 0, y = 0, z = 0.05}, yaw = math.pi},
{delta = {x = 0.05, y = 0, z = 0}, yaw = math.pi / 2},
}
local signs_post = {
{delta = {x = 0, y = 0, z = -0.226}, yaw = 0},
{delta = {x = -0.226, y = 0, z = 0}, yaw = math.pi / -2},
@ -36,6 +39,10 @@ local signs_post = {
{delta = {x = 0.226, y = 0, z = 0}, yaw = math.pi / 2},
}
local sign_groups = {choppy=2, dig_immediate=2}
local fences_with_sign = { }
homedecor_construct_sign = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("formspec", "field[text;;${text}]")
@ -45,7 +52,7 @@ end
homedecor_destruct_sign = function(pos)
local objects = minetest.env:get_objects_inside_radius(pos, 0.5)
for _, v in ipairs(objects) do
if v:get_entity_name() == "homedecor:sign_text" then
if v:get_entity_name() == "signs:text" then
v:remove()
end
end
@ -60,7 +67,7 @@ homedecor_update_sign = function(pos, fields)
local text = meta:get_string("text")
local objects = minetest.env:get_objects_inside_radius(pos, 0.5)
for _, v in ipairs(objects) do
if v:get_entity_name() == "homedecor:sign_text" then
if v:get_entity_name() == "signs:text" then
v:set_properties({textures={homedecor_generate_texture(homedecor_create_lines(text))}})
return
end
@ -68,20 +75,172 @@ homedecor_update_sign = function(pos, fields)
-- if there is no entity
local sign_info
if minetest.env:get_node(pos).name == "homedecor:fence_brass_with_sign"
or minetest.env:get_node(pos).name == "homedecor:fence_wrought_iron_with_sign" then
if minetest.env:get_node(pos).name == "signs:sign_yard" then
sign_info = signs_yard[minetest.env:get_node(pos).param2 + 1]
elseif minetest.env:get_node(pos).name == "default:sign_wall" then
sign_info = signs[minetest.env:get_node(pos).param2 + 1]
elseif minetest.env:get_node(pos).name == "signs:sign_post" then
sign_info = signs_post[minetest.env:get_node(pos).param2 + 1]
end
if sign_info == nil then
return
end
local text = minetest.env:add_entity({x = pos.x + sign_info.delta.x,
y = pos.y + sign_info.delta.y,
z = pos.z + sign_info.delta.z}, "homedecor:sign_text")
y = pos.y + sign_info.delta.y,
z = pos.z + sign_info.delta.z}, "signs:text")
text:setyaw(sign_info.yaw)
end
minetest.register_entity("homedecor:sign_text", {
minetest.register_node(":default:sign_wall", {
description = "Sign",
inventory_image = "default_sign_wall.png",
wield_image = "default_sign_wall.png",
node_placement_prediction = "",
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
drawtype = "nodebox",
node_box = {type = "fixed", fixed = {-0.45, -0.15, 0.4, 0.45, 0.45, 0.498}},
selection_box = {type = "fixed", fixed = {-0.45, -0.15, 0.4, 0.45, 0.45, 0.498}},
tiles = {"signs_top.png", "signs_bottom.png", "signs_side.png", "signs_side.png", "signs_back.png", "signs_front.png"},
groups = sign_groups,
on_place = function(itemstack, placer, pointed_thing)
local node=minetest.env:get_node(pointed_thing.under)
if minetest.registered_nodes[node.name].on_rightclick then
return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer)
else
local above = pointed_thing.above
local under = pointed_thing.under
local dir = {x = under.x - above.x,
y = under.y - above.y,
z = under.z - above.z}
local wdir = minetest.dir_to_wallmounted(dir)
local placer_pos = placer:getpos()
if placer_pos then
dir = {
x = above.x - placer_pos.x,
y = above.y - placer_pos.y,
z = above.z - placer_pos.z
}
end
local fdir = minetest.dir_to_facedir(dir)
local sign_info
local pt_name = minetest.env:get_node(under).name
print(dump(pt_name))
if fences_with_sign[pt_name] then
minetest.env:add_node(under, {name = fences_with_sign[pt_name], param2 = fdir})
sign_info = signs_post[fdir + 1]
elseif wdir == 0 then
--how would you add sign to ceiling?
minetest.env:add_item(above, "default:sign_wall")
itemstack:take_item()
return itemstack
elseif wdir == 1 then
minetest.env:add_node(above, {name = "signs:sign_yard", param2 = fdir})
sign_info = signs_yard[fdir + 1]
else
minetest.env:add_node(above, {name = "default:sign_wall", param2 = fdir})
sign_info = signs[fdir + 1]
end
local text = minetest.env:add_entity({x = above.x + sign_info.delta.x,
y = above.y + sign_info.delta.y,
z = above.z + sign_info.delta.z}, "signs:text")
text:setyaw(sign_info.yaw)
itemstack:take_item()
return itemstack
end
end,
on_construct = function(pos)
homedecor_construct_sign(pos)
end,
on_destruct = function(pos)
homedecor_destruct_sign(pos)
end,
on_receive_fields = function(pos, formname, fields, sender)
homedecor_update_sign(pos, fields)
end,
on_punch = function(pos, node, puncher)
homedecor_update_sign(pos)
end,
})
minetest.register_node(":signs:sign_yard", {
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
drawtype = "nodebox",
node_box = {type = "fixed", fixed = {
{-0.45, -0.15, -0.049, 0.45, 0.45, 0.049},
{-0.05, -0.5, -0.049, 0.05, -0.15, 0.049}
}},
selection_box = {type = "fixed", fixed = {-0.45, -0.15, -0.049, 0.45, 0.45, 0.049}},
tiles = {"signs_top.png", "signs_bottom.png", "signs_side.png", "signs_side.png", "signs_back.png", "signs_front.png"},
groups = {choppy=2, dig_immediate=2},
drop = "default:sign_wall",
on_construct = function(pos)
homedecor_construct_sign(pos)
end,
on_destruct = function(pos)
homedecor_destruct_sign(pos)
end,
on_receive_fields = function(pos, formname, fields, sender)
homedecor_update_sign(pos, fields)
end,
on_punch = function(pos, node, puncher)
homedecor_update_sign(pos)
end,
})
minetest.register_node(":signs:sign_post", {
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{ -0.125, -0.5, -0.125, 0.125, 0.5, 0.125 },
{ -0.45, -0.15, -0.225, 0.45, 0.45, -0.125 },
}
},
selection_box = {
type = "fixed",
fixed = {
{ -0.125, -0.5, -0.125, 0.125, 0.5, 0.125 },
{ -0.45, -0.15, -0.225, 0.45, 0.45, -0.125 },
}
},
tiles = {
"signs_post_top.png",
"signs_post_bottom.png",
"signs_post_side.png",
"signs_post_side.png",
"signs_post_back.png",
"signs_post_front.png",
},
groups = {choppy=2, dig_immediate=2},
drop = {
max_items = 2,
items = {
{ items = { "default:sign_wall" }},
{ items = { "default:fence_wood" }},
},
},
})
minetest.register_entity(":signs:text", {
collisionbox = { 0, 0, 0, 0, 0, 0 },
visual = "upright_sprite",
textures = {},
@ -178,7 +337,7 @@ homedecor_generate_line = function(s, ypos)
file = charmap[s:sub(i, i + 1)]
i = i + 2
else
print("[homedecor] "..S("W: unknown symbol in '%s' at %d (probably %s)"):format(s, i, s:sub(i, i)))
print("[signs] W: unknown symbol in '"..s.."' at "..i.." (probably "..s:sub(i, i)..")")
i = i + 1
end
if file ~= nil then
@ -198,3 +357,57 @@ homedecor_generate_line = function(s, ypos)
return texture
end
local function copy ( t )
local nt = { };
for k, v in pairs(t) do
if type(v) == "table" then
nt[k] = copy(v)
else
nt[k] = v
end
end
return nt
end
function homedecor_register_fence_with_sign(fencename, fencewithsignname)
local def = copy(minetest.registered_nodes[fencename])
local def_sign = copy(minetest.registered_nodes[fencewithsignname])
if not (def and def_sign) then
error("Attempt to register unknown node as fence")
end
fences_with_sign[fencename] = fencewithsignname
def.on_place = function(itemstack, placer, pointed_thing, ...)
if not homedecor_node_is_owned(pointed_thing.under, placer) then
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
minetest.env:add_node(pointed_thing.above, {name = fencename, param2 = fdir})
itemstack:take_item()
placer:set_wielded_item(itemstack)
return itemstack
end
end
def_sign.on_construct = function(pos, ...)
homedecor_construct_sign(pos)
end
def_sign.on_destruct = function(pos, ...)
homedecor_destruct_sign(pos)
end
def_sign.on_receive_fields = function(pos, formname, fields, sender, ...)
homedecor_update_sign(pos, fields)
end
def_sign.on_punch = function(pos, node, puncher, ...)
homedecor_update_sign(pos)
end
local fencename = fencename
def_sign.after_dig_node = function(pos, node, ...)
node.name = fencename
minetest.env:add_node(pos, node)
end
def_sign.drop = "default:sign_wall"
minetest.register_node(":"..fencename, def)
minetest.register_node(":"..fencewithsignname, def_sign)
print("Registered "..fencename.." and "..fencewithsignname)
end
if minetest.setting_get("log_mods") then
minetest.log("action", "signs loaded")
end

BIN
textures/signs_back.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 277 B

BIN
textures/signs_bottom.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 B

BIN
textures/signs_front.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 271 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 B

BIN
textures/signs_post_top.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 B

BIN
textures/signs_side.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 B

BIN
textures/signs_sign.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
textures/signs_top.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 B