1
0
Fork 0

Rename beds mod to mcl_beds

objects
Wuzzy 2017-05-07 20:21:37 +02:00
parent 4c71611c3d
commit d76ab30892
19 changed files with 102 additions and 83 deletions

View File

@ -1,34 +0,0 @@
-- Simple shaped bed
beds.register_bed("beds:bed", {
description = "Bed",
inventory_image = "beds_bed.png",
wield_image = "beds_bed.png",
tiles = {
bottom = {
"beds_bed_top_bottom.png^[transformR90",
"default_wood.png",
"beds_bed_side_bottom_r.png",
"beds_bed_side_bottom_r.png^[transformfx",
"blank.png",
"beds_bed_side_bottom.png"
},
top = {
"beds_bed_top_top.png^[transformR90",
"default_wood.png",
"beds_bed_side_top_r.png",
"beds_bed_side_top_r.png^[transformfx",
"beds_bed_side_top.png",
"blank.png",
}
},
nodebox = {
bottom = {-0.5, -0.5, -0.5, 0.5, 0.06, 0.5},
top = {-0.5, -0.5, -0.5, 0.5, 0.06, 0.5},
},
selectionbox = {-0.5, -0.5, -0.5, 0.5, 0.06, 1.5},
recipe = {
{"group:wool", "group:wool", "group:wool"},
{"group:wood", "group:wood", "group:wood"}
},
})

View File

@ -35,7 +35,7 @@ else
beddesc = beddesc .. "Going into bed seems to make time pass faster: The night will be skipped when you go sleep and you're alone in this world. If you're not alone, the night is skipped when all players in this world went to sleep." beddesc = beddesc .. "Going into bed seems to make time pass faster: The night will be skipped when you go sleep and you're alone in this world. If you're not alone, the night is skipped when all players in this world went to sleep."
end end
function beds.register_bed(name, def) function mcl_beds.register_bed(name, def)
minetest.register_node(name .. "_bottom", { minetest.register_node(name .. "_bottom", {
description = def.description, description = def.description,
_doc_items_longdesc = def._doc_items_longdesc or beddesc, _doc_items_longdesc = def._doc_items_longdesc or beddesc,
@ -59,9 +59,8 @@ function beds.register_bed(name, def)
}, },
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = def.selectionbox, fixed = def.selectionbox.bottom,
}, },
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
local under = pointed_thing.under local under = pointed_thing.under
@ -119,7 +118,7 @@ function beds.register_bed(name, def)
end, end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
beds.on_rightclick(pos, clicker) mcl_beds.on_rightclick(pos, clicker)
return itemstack return itemstack
end, end,
@ -164,7 +163,6 @@ function beds.register_bed(name, def)
paramtype2 = "facedir", paramtype2 = "facedir",
sunlight_propagates = true, sunlight_propagates = true,
is_ground_content = false, is_ground_content = false,
pointable = false,
groups = {handy = 1, flammable = 3, bed = 2, dig_by_piston=1, fall_damage_add_percent=-50}, groups = {handy = 1, flammable = 3, bed = 2, dig_by_piston=1, fall_damage_add_percent=-50},
_mcl_hardness = 0.2, _mcl_hardness = 0.2,
_mcl_blast_resistance = 1, _mcl_blast_resistance = 1,
@ -174,6 +172,10 @@ function beds.register_bed(name, def)
type = "fixed", type = "fixed",
fixed = def.nodebox.top, fixed = def.nodebox.top,
}, },
selection_box = {
type = "fixed",
fixed = def.selectionbox.top,
},
on_destruct = function(pos) on_destruct = function(pos)
destruct_bed(pos, 2) destruct_bed(pos, 2)
end, end,

View File

@ -0,0 +1,50 @@
-- 3D bed
local nodebox = {
bottom = {
{-0.5, -5/16, -0.5, 0.5, 0.06, 0.5},
{-0.5, -0.5, -0.5, -5/16, -5/16, -5/16},
{0.5, -0.5, -0.5, 5/16, -5/16, -5/16},
},
top = {
{-0.5, -5/16, -0.5, 0.5, 0.06, 0.5},
{-0.5, -0.5, 0.5, -5/16, -5/16, 5/16},
{0.5, -0.5, 0.5, 5/16, -5/16, 5/16},
},
}
mcl_beds.register_bed("mcl_beds:bed_red", {
description = "Bed",
inventory_image = "mcl_beds_bed_red.png",
wield_image = "mcl_beds_bed_red.png",
tiles = {
bottom = {
"mcl_beds_bed_top_bottom_red.png",
"mcl_beds_bed_bottom_bottom.png",
"mcl_beds_bed_side_bottom_r_red.png",
"mcl_beds_bed_side_bottom_r_red.png^[transformfx",
"mcl_beds_bed_side_top_red.png",
"mcl_beds_bed_side_bottom_red.png"
},
top = {
"mcl_beds_bed_top_top_red.png",
"mcl_beds_bed_bottom_top.png",
"mcl_beds_bed_side_top_r_red.png",
"mcl_beds_bed_side_top_r_red.png^[transformfx",
"mcl_beds_bed_side_top_red.png",
"mcl_beds_bed_side_bottom_red.png"
}
},
nodebox = nodebox,
selectionbox = {
bottom = {-0.5, -0.5, -0.5, 0.5, 0.06, 0.5},
top = {-0.5, -0.5, -0.5, 0.5, 0.06, 0.5},
},
recipe = {
{"group:wool", "group:wool", "group:wool"},
{"group:wood", "group:wood", "group:wood"}
},
})
minetest.register_alias("beds:bed_bottom", "mcl_beds:bed_red_bottom")
minetest.register_alias("beds:bed_top", "mcl_beds:bed_red_top")

View File

@ -30,7 +30,7 @@ local function is_night_skip_enabled()
end end
local function check_in_beds(players) local function check_in_beds(players)
local in_bed = beds.player local in_bed = mcl_beds.player
if not players then if not players then
players = minetest.get_connected_players() players = minetest.get_connected_players()
end end
@ -55,9 +55,9 @@ local function lay_down(player, pos, bed_pos, state, skip)
-- stand up -- stand up
if state ~= nil and not state then if state ~= nil and not state then
local p = beds.pos[name] or nil local p = mcl_beds.pos[name] or nil
if beds.player[name] ~= nil then if mcl_beds.player[name] ~= nil then
beds.player[name] = nil mcl_beds.player[name] = nil
player_in_bed = player_in_bed - 1 player_in_bed = player_in_bed - 1
end end
-- skip here to prevent sending player specific changes (used for leaving players) -- skip here to prevent sending player specific changes (used for leaving players)
@ -78,8 +78,8 @@ local function lay_down(player, pos, bed_pos, state, skip)
-- lay down -- lay down
else else
beds.player[name] = 1 mcl_beds.player[name] = 1
beds.pos[name] = pos mcl_beds.pos[name] = pos
player_in_bed = player_in_bed + 1 player_in_bed = player_in_bed + 1
-- physics, eye_offset, etc -- physics, eye_offset, etc
@ -104,42 +104,42 @@ local function update_formspecs(finished)
local all_in_bed = ges == player_in_bed local all_in_bed = ges == player_in_bed
if finished then if finished then
form_n = beds.formspec .. "label[2.7,11; Good morning.]" form_n = mcl_beds.formspec .. "label[2.7,11; Good morning.]"
else else
form_n = beds.formspec .. "label[2.2,11;" .. tostring(player_in_bed) .. form_n = mcl_beds.formspec .. "label[2.2,11;" .. tostring(player_in_bed) ..
" of " .. tostring(ges) .. " players are in bed]" " of " .. tostring(ges) .. " players are in bed]"
if all_in_bed and is_night_skip_enabled() then if all_in_bed and is_night_skip_enabled() then
form_n = form_n .. "button_exit[2,8;4,0.75;force;Force night skip]" form_n = form_n .. "button_exit[2,8;4,0.75;force;Force night skip]"
end end
end end
for name,_ in pairs(beds.player) do for name,_ in pairs(mcl_beds.player) do
minetest.show_formspec(name, "beds_form", form_n) minetest.show_formspec(name, "mcl_beds_form", form_n)
end end
end end
-- Public functions -- Public functions
function beds.kick_players() function mcl_beds.kick_players()
for name, _ in pairs(beds.player) do for name, _ in pairs(mcl_beds.player) do
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
lay_down(player, nil, nil, false) lay_down(player, nil, nil, false)
end end
end end
function beds.skip_night() function mcl_beds.skip_night()
minetest.set_timeofday(0.25) -- tod = 6000 minetest.set_timeofday(0.25) -- tod = 6000
end end
function beds.on_rightclick(pos, player) function mcl_beds.on_rightclick(pos, player)
local name = player:get_player_name() local name = player:get_player_name()
local ppos = player:getpos() local ppos = player:getpos()
local tod = minetest.get_timeofday() * 24000 local tod = minetest.get_timeofday() * 24000
-- Values taken from Minecraft Wiki with offset of +6000 -- Values taken from Minecraft Wiki with offset of +6000
if tod < 18541 and tod > 5458 then if tod < 18541 and tod > 5458 then
if beds.player[name] then if mcl_beds.player[name] then
lay_down(player, nil, nil, false) lay_down(player, nil, nil, false)
end end
minetest.chat_send_player(name, "You can only sleep at night.") minetest.chat_send_player(name, "You can only sleep at night.")
@ -147,9 +147,9 @@ function beds.on_rightclick(pos, player)
end end
-- move to bed -- move to bed
if not beds.player[name] then if not mcl_beds.player[name] then
lay_down(player, ppos, pos) lay_down(player, ppos, pos)
beds.set_spawns() -- save respawn positions when entering bed mcl_beds.set_spawns() -- save respawn positions when entering bed
else else
lay_down(player, nil, nil, false) lay_down(player, nil, nil, false)
end end
@ -165,8 +165,8 @@ function beds.on_rightclick(pos, player)
update_formspecs(is_night_skip_enabled()) update_formspecs(is_night_skip_enabled())
end end
if is_night_skip_enabled() then if is_night_skip_enabled() then
beds.skip_night() mcl_beds.skip_night()
beds.kick_players() mcl_beds.kick_players()
end end
end) end)
end end
@ -179,7 +179,7 @@ if enable_respawn then
-- respawn player at bed if enabled and valid position is found -- respawn player at bed if enabled and valid position is found
minetest.register_on_respawnplayer(function(player) minetest.register_on_respawnplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()
local pos = beds.spawn[name] local pos = mcl_beds.spawn[name]
if pos then if pos then
player:setpos(pos) player:setpos(pos)
return true return true
@ -190,20 +190,20 @@ end
minetest.register_on_leaveplayer(function(player) minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name() local name = player:get_player_name()
lay_down(player, nil, nil, false, true) lay_down(player, nil, nil, false, true)
beds.player[name] = nil mcl_beds.player[name] = nil
if check_in_beds() then if check_in_beds() then
minetest.after(2, function() minetest.after(2, function()
update_formspecs(is_night_skip_enabled()) update_formspecs(is_night_skip_enabled())
if is_night_skip_enabled() then if is_night_skip_enabled() then
beds.skip_night() mcl_beds.skip_night()
beds.kick_players() mcl_beds.kick_players()
end end
end) end)
end end
end) end)
minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "beds_form" then if formname ~= "mcl_beds_form" then
return return
end end
if fields.quit or fields.leave then if fields.quit or fields.leave then
@ -214,8 +214,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.force then if fields.force then
update_formspecs(is_night_skip_enabled()) update_formspecs(is_night_skip_enabled())
if is_night_skip_enabled() then if is_night_skip_enabled() then
beds.skip_night() mcl_beds.skip_night()
beds.kick_players() mcl_beds.kick_players()
end end
end end
end) end)

View File

@ -1,13 +1,13 @@
beds = {} mcl_beds = {}
beds.player = {} mcl_beds.player = {}
beds.pos = {} mcl_beds.pos = {}
beds.spawn = {} mcl_beds.spawn = {}
beds.formspec = "size[8,15;true]" .. mcl_beds.formspec = "size[8,15;true]" ..
"bgcolor[#080808BB; true]" .. "bgcolor[#080808BB; true]" ..
"button_exit[2,12;4,0.75;leave;Leave Bed]" "button_exit[2,12;4,0.75;leave;Leave Bed]"
local modpath = minetest.get_modpath("beds") local modpath = minetest.get_modpath("mcl_beds")
-- Load files -- Load files

View File

@ -0,0 +1 @@
name = mcl_beds

View File

@ -11,21 +11,21 @@ if cf ~= nil then
bkwd = true bkwd = true
end end
function beds.save_spawns() function mcl_beds.save_spawns()
if not beds.spawn then if not mcl_beds.spawn then
return return
end end
local data = {} local data = {}
local output = io.open(org_file, "w") local output = io.open(org_file, "w")
for k, v in pairs(beds.spawn) do for k, v in pairs(mcl_beds.spawn) do
table.insert(data, string.format("%.1f %.1f %.1f %s\n", v.x, v.y, v.z, k)) table.insert(data, string.format("%.1f %.1f %.1f %s\n", v.x, v.y, v.z, k))
end end
output:write(table.concat(data)) output:write(table.concat(data))
io.close(output) io.close(output)
end end
function beds.read_spawns() function mcl_beds.read_spawns()
local spawns = beds.spawn local spawns = mcl_beds.spawn
local input = io.open(file, "r") local input = io.open(file, "r")
if input and not bkwd then if input and not bkwd then
repeat repeat
@ -40,24 +40,24 @@ function beds.read_spawns()
until input:read(0) == nil until input:read(0) == nil
io.close(input) io.close(input)
elseif input and bkwd then elseif input and bkwd then
beds.spawn = minetest.deserialize(input:read("*all")) mcl_beds.spawn = minetest.deserialize(input:read("*all"))
input:close() input:close()
beds.save_spawns() mcl_beds.save_spawns()
os.rename(file, file .. ".backup") os.rename(file, file .. ".backup")
file = org_file file = org_file
end end
end end
beds.read_spawns() mcl_beds.read_spawns()
function beds.set_spawns() function mcl_beds.set_spawns()
for name,_ in pairs(beds.player) do for name,_ in pairs(mcl_beds.player) do
local player = minetest.get_player_by_name(name) local player = minetest.get_player_by_name(name)
local p = player:getpos() local p = player:getpos()
-- but don't change spawn location if borrowing a bed -- but don't change spawn location if borrowing a bed
if not minetest.is_protected(p, name) then if not minetest.is_protected(p, name) then
beds.spawn[name] = p mcl_beds.spawn[name] = p
end end
end end
beds.save_spawns() mcl_beds.save_spawns()
end end

View File

Before

Width:  |  Height:  |  Size: 913 B

After

Width:  |  Height:  |  Size: 913 B

View File

Before

Width:  |  Height:  |  Size: 886 B

After

Width:  |  Height:  |  Size: 886 B

View File

Before

Width:  |  Height:  |  Size: 301 B

After

Width:  |  Height:  |  Size: 301 B

View File

Before

Width:  |  Height:  |  Size: 624 B

After

Width:  |  Height:  |  Size: 624 B

View File

Before

Width:  |  Height:  |  Size: 661 B

After

Width:  |  Height:  |  Size: 661 B

View File

Before

Width:  |  Height:  |  Size: 707 B

After

Width:  |  Height:  |  Size: 707 B

View File

Before

Width:  |  Height:  |  Size: 807 B

After

Width:  |  Height:  |  Size: 807 B

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB