Rename beds mod to mcl_beds

This commit is contained in:
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."
end
function beds.register_bed(name, def)
function mcl_beds.register_bed(name, def)
minetest.register_node(name .. "_bottom", {
description = def.description,
_doc_items_longdesc = def._doc_items_longdesc or beddesc,
@ -59,9 +59,8 @@ function beds.register_bed(name, def)
},
selection_box = {
type = "fixed",
fixed = def.selectionbox,
fixed = def.selectionbox.bottom,
},
on_place = function(itemstack, placer, pointed_thing)
local under = pointed_thing.under
@ -119,7 +118,7 @@ function beds.register_bed(name, def)
end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
beds.on_rightclick(pos, clicker)
mcl_beds.on_rightclick(pos, clicker)
return itemstack
end,
@ -164,7 +163,6 @@ function beds.register_bed(name, def)
paramtype2 = "facedir",
sunlight_propagates = true,
is_ground_content = false,
pointable = false,
groups = {handy = 1, flammable = 3, bed = 2, dig_by_piston=1, fall_damage_add_percent=-50},
_mcl_hardness = 0.2,
_mcl_blast_resistance = 1,
@ -174,6 +172,10 @@ function beds.register_bed(name, def)
type = "fixed",
fixed = def.nodebox.top,
},
selection_box = {
type = "fixed",
fixed = def.selectionbox.top,
},
on_destruct = function(pos)
destruct_bed(pos, 2)
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
local function check_in_beds(players)
local in_bed = beds.player
local in_bed = mcl_beds.player
if not players then
players = minetest.get_connected_players()
end
@ -55,9 +55,9 @@ local function lay_down(player, pos, bed_pos, state, skip)
-- stand up
if state ~= nil and not state then
local p = beds.pos[name] or nil
if beds.player[name] ~= nil then
beds.player[name] = nil
local p = mcl_beds.pos[name] or nil
if mcl_beds.player[name] ~= nil then
mcl_beds.player[name] = nil
player_in_bed = player_in_bed - 1
end
-- 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
else
beds.player[name] = 1
beds.pos[name] = pos
mcl_beds.player[name] = 1
mcl_beds.pos[name] = pos
player_in_bed = player_in_bed + 1
-- physics, eye_offset, etc
@ -104,42 +104,42 @@ local function update_formspecs(finished)
local all_in_bed = ges == player_in_bed
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
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]"
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]"
end
end
for name,_ in pairs(beds.player) do
minetest.show_formspec(name, "beds_form", form_n)
for name,_ in pairs(mcl_beds.player) do
minetest.show_formspec(name, "mcl_beds_form", form_n)
end
end
-- Public functions
function beds.kick_players()
for name, _ in pairs(beds.player) do
function mcl_beds.kick_players()
for name, _ in pairs(mcl_beds.player) do
local player = minetest.get_player_by_name(name)
lay_down(player, nil, nil, false)
end
end
function beds.skip_night()
function mcl_beds.skip_night()
minetest.set_timeofday(0.25) -- tod = 6000
end
function beds.on_rightclick(pos, player)
function mcl_beds.on_rightclick(pos, player)
local name = player:get_player_name()
local ppos = player:getpos()
local tod = minetest.get_timeofday() * 24000
-- Values taken from Minecraft Wiki with offset of +6000
if tod < 18541 and tod > 5458 then
if beds.player[name] then
if mcl_beds.player[name] then
lay_down(player, nil, nil, false)
end
minetest.chat_send_player(name, "You can only sleep at night.")
@ -147,9 +147,9 @@ function beds.on_rightclick(pos, player)
end
-- move to bed
if not beds.player[name] then
if not mcl_beds.player[name] then
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
lay_down(player, nil, nil, false)
end
@ -165,8 +165,8 @@ function beds.on_rightclick(pos, player)
update_formspecs(is_night_skip_enabled())
end
if is_night_skip_enabled() then
beds.skip_night()
beds.kick_players()
mcl_beds.skip_night()
mcl_beds.kick_players()
end
end)
end
@ -179,7 +179,7 @@ if enable_respawn then
-- respawn player at bed if enabled and valid position is found
minetest.register_on_respawnplayer(function(player)
local name = player:get_player_name()
local pos = beds.spawn[name]
local pos = mcl_beds.spawn[name]
if pos then
player:setpos(pos)
return true
@ -190,20 +190,20 @@ end
minetest.register_on_leaveplayer(function(player)
local name = player:get_player_name()
lay_down(player, nil, nil, false, true)
beds.player[name] = nil
mcl_beds.player[name] = nil
if check_in_beds() then
minetest.after(2, function()
update_formspecs(is_night_skip_enabled())
if is_night_skip_enabled() then
beds.skip_night()
beds.kick_players()
mcl_beds.skip_night()
mcl_beds.kick_players()
end
end)
end
end)
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "beds_form" then
if formname ~= "mcl_beds_form" then
return
end
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
update_formspecs(is_night_skip_enabled())
if is_night_skip_enabled() then
beds.skip_night()
beds.kick_players()
mcl_beds.skip_night()
mcl_beds.kick_players()
end
end
end)

View File

@ -1,13 +1,13 @@
beds = {}
beds.player = {}
beds.pos = {}
beds.spawn = {}
mcl_beds = {}
mcl_beds.player = {}
mcl_beds.pos = {}
mcl_beds.spawn = {}
beds.formspec = "size[8,15;true]" ..
mcl_beds.formspec = "size[8,15;true]" ..
"bgcolor[#080808BB; true]" ..
"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

View File

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

View File

@ -11,21 +11,21 @@ if cf ~= nil then
bkwd = true
end
function beds.save_spawns()
if not beds.spawn then
function mcl_beds.save_spawns()
if not mcl_beds.spawn then
return
end
local data = {}
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))
end
output:write(table.concat(data))
io.close(output)
end
function beds.read_spawns()
local spawns = beds.spawn
function mcl_beds.read_spawns()
local spawns = mcl_beds.spawn
local input = io.open(file, "r")
if input and not bkwd then
repeat
@ -40,24 +40,24 @@ function beds.read_spawns()
until input:read(0) == nil
io.close(input)
elseif input and bkwd then
beds.spawn = minetest.deserialize(input:read("*all"))
mcl_beds.spawn = minetest.deserialize(input:read("*all"))
input:close()
beds.save_spawns()
mcl_beds.save_spawns()
os.rename(file, file .. ".backup")
file = org_file
end
end
beds.read_spawns()
mcl_beds.read_spawns()
function beds.set_spawns()
for name,_ in pairs(beds.player) do
function mcl_beds.set_spawns()
for name,_ in pairs(mcl_beds.player) do
local player = minetest.get_player_by_name(name)
local p = player:getpos()
-- but don't change spawn location if borrowing a bed
if not minetest.is_protected(p, name) then
beds.spawn[name] = p
mcl_beds.spawn[name] = p
end
end
beds.save_spawns()
mcl_beds.save_spawns()
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