Added coloured beds, new textures, fixed top

There are now 9 different coloured beds (roygbv, black, grey & white)
with new recipes (2 coloured wool + 1 white wool over 2 sticks), changed
textures and added 3D pillow. I've also changed the code to prevent the
top (pillow) node from destroying other nodes when the bed is placed.
Any previously placed old bed is replaced with a new, blue bed using the
alias function.
master
thefamilygrog 2013-04-01 14:33:24 -04:00
parent 8e61c9d6b0
commit c4ebf28ab7
51 changed files with 188 additions and 171 deletions

359
init.lua
View File

@ -1,146 +1,199 @@
local player_in_bed = 0
minetest.register_node("beds:bed_bottom", {
description = "Bed",
drawtype = "nodebox",
tiles = {"beds_bed_top_bottom.png", "default_wood.png", "beds_bed_side.png", "beds_bed_side.png", "beds_bed_side.png", "beds_bed_side.png"},
paramtype = "light",
paramtype2 = "facedir",
stack_max = 1,
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3},
sounds = default.node_sound_wood_defaults(),
node_box = {
type = "fixed",
fixed = {
-- bed
{-0.5, 0.0, -0.5, 0.5, 0.3, 0.5},
-- stützen
{-0.5, -0.5, -0.5, -0.4, 0.0, -0.4},
{0.4, 0.0, -0.4, 0.5, -0.5, -0.5},
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.3, 1.5},
}
},
on_construct = function(pos)
local node = minetest.env:get_node(pos)
local param2 = node.param2
if param2 == 0 then
node.name = "beds:bed_top"
pos.z = pos.z+1
minetest.env:set_node(pos, node)
elseif param2 == 1 then
node.name = "beds:bed_top"
pos.x = pos.x+1
minetest.env:set_node(pos, node)
elseif param2 == 2 then
node.name = "beds:bed_top"
pos.z = pos.z-1
minetest.env:set_node(pos, node)
elseif param2 == 3 then
node.name = "beds:bed_top"
pos.x = pos.x-1
minetest.env:set_node(pos, node)
end
end,
on_destruct = function(pos)
local node = minetest.env:get_node(pos)
local param2 = node.param2
if param2 == 0 then
pos.z = pos.z+1
minetest.env:remove_node(pos)
elseif param2 == 1 then
pos.x = pos.x+1
minetest.env:remove_node(pos)
elseif param2 == 2 then
pos.z = pos.z-1
minetest.env:remove_node(pos)
elseif param2 == 3 then
pos.x = pos.x-1
minetest.env:remove_node(pos)
end
end,
on_rightclick = function(pos, node, clicker)
if not clicker:is_player() then
return
end
local meta = minetest.env:get_meta(pos)
local param2 = node.param2
if param2 == 0 then
pos.z = pos.z+1
elseif param2 == 1 then
pos.x = pos.x+1
elseif param2 == 2 then
pos.z = pos.z-1
elseif param2 == 3 then
pos.x = pos.x-1
end
if clicker:get_player_name() == meta:get_string("player") then
local beds_list = {
{ "Red Bed", "red"},
{ "Orange Bed", "orange"},
{ "Yellow Bed", "yellow"},
{ "Green Bed", "green"},
{ "Blue Bed", "blue"},
{ "Violet Bed", "violet"},
{ "Black Bed", "black"},
{ "Grey Bed", "grey"},
{ "White Bed", "white"},
}
for i in ipairs(beds_list) do
local beddesc = beds_list[i][1]
local colour = beds_list[i][2]
minetest.register_node("beds:bed_bottom_"..colour, {
description = beddesc,
drawtype = "nodebox",
tiles = {"beds_bed_top_bottom_"..colour..".png", "default_wood.png", "beds_bed_side_"..colour..".png", "beds_bed_side_"..colour..".png", "beds_bed_side_"..colour..".png", "beds_bed_side_"..colour..".png"},
paramtype = "light",
paramtype2 = "facedir",
stack_max = 1,
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3},
sounds = default.node_sound_wood_defaults(),
node_box = {
type = "fixed",
fixed = {
-- bed
{-0.5, 0.0, -0.5, 0.5, 0.3125, 0.5},
-- legs
{-0.5, -0.5, -0.5, -0.4, 0.0, -0.4},
{0.4, 0.0, -0.4, 0.5, -0.5, -0.5},
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.3125, 1.5},
}
},
on_construct = function(pos)
local node = minetest.env:get_node(pos)
local param2 = node.param2
node.name = "beds:bed_top_"..colour
if param2 == 0 then
pos.x = pos.x-1
elseif param2 == 1 then
pos.z = pos.z+1
elseif param2 == 2 then
elseif param2 == 1 then
pos.x = pos.x+1
elseif param2 == 3 then
elseif param2 == 2 then
pos.z = pos.z-1
elseif param2 == 3 then
pos.x = pos.x-1
end
if( minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z}).name == "air" ) then
minetest.env:set_node(pos, node)
end
end,
on_destruct = function(pos)
local node = minetest.env:get_node(pos)
local param2 = node.param2
if param2 == 0 then
pos.z = pos.z+1
elseif param2 == 1 then
pos.x = pos.x+1
elseif param2 == 2 then
pos.z = pos.z-1
elseif param2 == 3 then
pos.x = pos.x-1
end
if( minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z}).name == "beds:bed_top_"..colour ) then
if( minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z}).param2 == param2 ) then
minetest.env:remove_node(pos)
end
end
end,
on_rightclick = function(pos, node, clicker)
if not clicker:is_player() then
return
end
local meta = minetest.env:get_meta(pos)
local param2 = node.param2
if param2 == 0 then
pos.z = pos.z+1
elseif param2 == 1 then
pos.x = pos.x+1
elseif param2 == 2 then
pos.z = pos.z-1
elseif param2 == 3 then
pos.x = pos.x-1
end
if clicker:get_player_name() == meta:get_string("player") then
if param2 == 0 then
pos.x = pos.x-1
elseif param2 == 1 then
pos.z = pos.z+1
elseif param2 == 2 then
pos.x = pos.x+1
elseif param2 == 3 then
pos.z = pos.z-1
end
pos.y = pos.y-0.5
clicker:setpos(pos)
meta:set_string("player", "")
player_in_bed = player_in_bed-1
elseif meta:get_string("player") == "" then
pos.y = pos.y-0.5
clicker:setpos(pos)
meta:set_string("player", clicker:get_player_name())
player_in_bed = player_in_bed+1
end
pos.y = pos.y-0.5
clicker:setpos(pos)
meta:set_string("player", "")
player_in_bed = player_in_bed-1
elseif meta:get_string("player") == "" then
pos.y = pos.y-0.5
clicker:setpos(pos)
meta:set_string("player", clicker:get_player_name())
player_in_bed = player_in_bed+1
end
end
})
minetest.register_node("beds:bed_top", {
drawtype = "nodebox",
tiles = {"beds_bed_top_top.png", "default_wood.png", "beds_bed_side_top_r.png", "beds_bed_side_top_l.png", "default_wood.png", "beds_bed_side.png"},
paramtype = "light",
paramtype2 = "facedir",
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3},
sounds = default.node_sound_wood_defaults(),
node_box = {
type = "fixed",
fixed = {
-- bed
{-0.5, 0.0, -0.5, 0.5, 0.3, 0.5},
-- stützen
{-0.4, 0.0, 0.4, -0.5, -0.5, 0.5},
{0.5, -0.5, 0.5, 0.4, 0.0, 0.4},
}
},
selection_box = {
type = "fixed",
fixed = {
{0, 0, 0, 0, 0, 0},
}
},
})
minetest.register_alias("beds:bed", "beds:bed_bottom")
minetest.register_craft({
output = "beds:bed",
recipe = {
{"wool:white", "wool:white", "wool:white", },
{"default:stick", "", "default:stick", }
}
})
})
minetest.register_node("beds:bed_top_"..colour, {
drawtype = "nodebox",
tiles = {"beds_bed_top_top_"..colour..".png", "default_wood.png", "beds_bed_side_top_r_"..colour..".png", "beds_bed_side_top_l_"..colour..".png", "default_wood.png", "beds_bed_side_"..colour..".png"},
paramtype = "light",
paramtype2 = "facedir",
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3},
sounds = default.node_sound_wood_defaults(),
node_box = {
type = "fixed",
fixed = {
-- bed
{-0.5, 0.0, -0.5, 0.5, 0.3125, 0.5},
{-0.4375, 0.3125, 0.1, 0.4375, 0.4375, 0.5},
-- legs
{-0.4, 0.0, 0.4, -0.5, -0.5, 0.5},
{0.5, -0.5, 0.5, 0.4, 0.0, 0.4},
}
},
selection_box = {
type = "fixed",
fixed = {
{0, 0, 0, 0, 0, 0},
}
},
})
minetest.register_alias("beds:bed_bottom", "beds:bed_bottom_blue")
minetest.register_alias("beds:bed_top", "beds:bed_top_blue")
minetest.register_alias("beds:bed", "beds:bed_bottom_blue")
minetest.register_alias("beds:bed_"..colour, "beds:bed_bottom_"..colour)
minetest.register_craft({
output = "beds:bed_"..colour,
recipe = {
{"wool:"..colour, "wool:"..colour, "wool:white", },
{"default:stick", "", "default:stick", }
}
})
minetest.register_abm({
nodenames = {"beds:bed_bottom_"..colour},
interval = 1,
chance = 1,
action = function(pos, node)
local meta = minetest.env:get_meta(pos)
if meta:get_string("player") ~= "" then
local param2 = node.param2
if param2 == 0 then
pos.z = pos.z+1
elseif param2 == 1 then
pos.x = pos.x+1
elseif param2 == 2 then
pos.z = pos.z-1
elseif param2 == 3 then
pos.x = pos.x-1
end
local player = minetest.env:get_player_by_name(meta:get_string("player"))
if player == nil then
meta:set_string("player", "")
player_in_bed = player_in_bed-1
return
end
local player_pos = player:getpos()
player_pos.x = math.floor(0.5+player_pos.x)
player_pos.y = math.floor(0.5+player_pos.y)
player_pos.z = math.floor(0.5+player_pos.z)
if pos.x ~= player_pos.x or pos.y ~= player_pos.y or pos.z ~= player_pos.z then
meta:set_string("player", "")
player_in_bed = player_in_bed-1
return
end
end
end
})
end
beds_player_spawns = {}
local file = io.open(minetest.get_worldpath().."/beds_player_spawns", "r")
@ -189,42 +242,6 @@ minetest.register_on_respawnplayer(function(player)
end
end)
minetest.register_abm({
nodenames = {"beds:bed_bottom"},
interval = 1,
chance = 1,
action = function(pos, node)
local meta = minetest.env:get_meta(pos)
if meta:get_string("player") ~= "" then
local param2 = node.param2
if param2 == 0 then
pos.z = pos.z+1
elseif param2 == 1 then
pos.x = pos.x+1
elseif param2 == 2 then
pos.z = pos.z-1
elseif param2 == 3 then
pos.x = pos.x-1
end
local player = minetest.env:get_player_by_name(meta:get_string("player"))
if player == nil then
meta:set_string("player", "")
player_in_bed = player_in_bed-1
return
end
local player_pos = player:getpos()
player_pos.x = math.floor(0.5+player_pos.x)
player_pos.y = math.floor(0.5+player_pos.y)
player_pos.z = math.floor(0.5+player_pos.z)
if pos.x ~= player_pos.x or pos.y ~= player_pos.y or pos.z ~= player_pos.z then
meta:set_string("player", "")
player_in_bed = player_in_bed-1
return
end
end
end
})
if minetest.setting_get("log_mods") then
minetest.log("action", "beds loaded")
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 536 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 490 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 494 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 485 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 526 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 500 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 487 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 483 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 483 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 507 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 498 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 493 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 490 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 476 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 502 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 484 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 487 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 488 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 484 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 509 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 505 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 494 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 479 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 470 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 505 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 479 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 468 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 539 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 333 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 331 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 605 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 455 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 475 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 462 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 455 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 506 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 487 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 457 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 B