forked from minetest/minetest_game
Beds: Fix code style issues
This commit is contained in:
parent
aa676ab878
commit
45bc0b245f
@ -19,6 +19,7 @@ function beds.register_bed(name, def)
|
|||||||
type = "fixed",
|
type = "fixed",
|
||||||
fixed = def.selectionbox,
|
fixed = def.selectionbox,
|
||||||
},
|
},
|
||||||
|
|
||||||
after_place_node = function(pos, placer, itemstack)
|
after_place_node = function(pos, placer, itemstack)
|
||||||
local n = minetest.get_node_or_nil(pos)
|
local n = minetest.get_node_or_nil(pos)
|
||||||
if not n or not n.param2 then
|
if not n or not n.param2 then
|
||||||
@ -36,6 +37,7 @@ function beds.register_bed(name, def)
|
|||||||
minetest.set_node(p, {name = n.name:gsub("%_bottom", "_top"), param2 = n.param2})
|
minetest.set_node(p, {name = n.name:gsub("%_bottom", "_top"), param2 = n.param2})
|
||||||
return false
|
return false
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_destruct = function(pos)
|
on_destruct = function(pos)
|
||||||
local n = minetest.get_node_or_nil(pos)
|
local n = minetest.get_node_or_nil(pos)
|
||||||
if not n then return end
|
if not n then return end
|
||||||
@ -46,9 +48,11 @@ function beds.register_bed(name, def)
|
|||||||
minetest.remove_node(p)
|
minetest.remove_node(p)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_rightclick = function(pos, node, clicker)
|
on_rightclick = function(pos, node, clicker)
|
||||||
beds.on_rightclick(pos, clicker)
|
beds.on_rightclick(pos, clicker)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_rotate = function(pos, node, user, mode, new_param2)
|
on_rotate = function(pos, node, user, mode, new_param2)
|
||||||
local dir = minetest.facedir_to_dir(node.param2)
|
local dir = minetest.facedir_to_dir(node.param2)
|
||||||
local p = vector.add(pos, dir)
|
local p = vector.add(pos, dir)
|
||||||
@ -99,7 +103,6 @@ function beds.register_bed(name, def)
|
|||||||
|
|
||||||
minetest.register_alias(name, name .. "_bottom")
|
minetest.register_alias(name, name .. "_bottom")
|
||||||
|
|
||||||
-- register recipe
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = name,
|
output = name,
|
||||||
recipe = def.recipe
|
recipe = def.recipe
|
||||||
|
@ -1,44 +1,45 @@
|
|||||||
-- fancy shaped bed
|
-- Fancy shaped bed
|
||||||
|
|
||||||
beds.register_bed("beds:fancy_bed", {
|
beds.register_bed("beds:fancy_bed", {
|
||||||
description = "Fancy Bed",
|
description = "Fancy Bed",
|
||||||
inventory_image = "beds_bed_fancy.png",
|
inventory_image = "beds_bed_fancy.png",
|
||||||
wield_image = "beds_bed_fancy.png",
|
wield_image = "beds_bed_fancy.png",
|
||||||
tiles = {
|
tiles = {
|
||||||
bottom = {
|
bottom = {
|
||||||
"beds_bed_top1.png",
|
"beds_bed_top1.png",
|
||||||
"default_wood.png",
|
"default_wood.png",
|
||||||
"beds_bed_side1.png",
|
"beds_bed_side1.png",
|
||||||
"beds_bed_side1.png^[transformFX",
|
"beds_bed_side1.png^[transformFX",
|
||||||
"default_wood.png",
|
"default_wood.png",
|
||||||
"beds_bed_foot.png",
|
"beds_bed_foot.png",
|
||||||
},
|
},
|
||||||
top = {
|
top = {
|
||||||
"beds_bed_top2.png",
|
"beds_bed_top2.png",
|
||||||
"default_wood.png",
|
"default_wood.png",
|
||||||
"beds_bed_side2.png",
|
"beds_bed_side2.png",
|
||||||
"beds_bed_side2.png^[transformFX",
|
"beds_bed_side2.png^[transformFX",
|
||||||
"beds_bed_head.png",
|
"beds_bed_head.png",
|
||||||
"default_wood.png",
|
"default_wood.png",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
nodebox = {
|
nodebox = {
|
||||||
bottom = {
|
bottom = {
|
||||||
{-0.5, -0.5, -0.5, -0.375, -0.065, -0.4375},
|
{-0.5, -0.5, -0.5, -0.375, -0.065, -0.4375},
|
||||||
{0.375, -0.5, -0.5, 0.5, -0.065, -0.4375},
|
{0.375, -0.5, -0.5, 0.5, -0.065, -0.4375},
|
||||||
{-0.5, -0.375, -0.5, 0.5, -0.125, -0.4375},
|
{-0.5, -0.375, -0.5, 0.5, -0.125, -0.4375},
|
||||||
{-0.5, -0.375, -0.5, -0.4375, -0.125, 0.5},
|
{-0.5, -0.375, -0.5, -0.4375, -0.125, 0.5},
|
||||||
{0.4375, -0.375, -0.5, 0.5, -0.125, 0.5},
|
{0.4375, -0.375, -0.5, 0.5, -0.125, 0.5},
|
||||||
{-0.4375, -0.3125, -0.4375, 0.4375, -0.0625, 0.5},
|
{-0.4375, -0.3125, -0.4375, 0.4375, -0.0625, 0.5},
|
||||||
},
|
},
|
||||||
top = {
|
top = {
|
||||||
{-0.5, -0.5, 0.4375, -0.375, 0.1875, 0.5},
|
{-0.5, -0.5, 0.4375, -0.375, 0.1875, 0.5},
|
||||||
{0.375, -0.5, 0.4375, 0.5, 0.1875, 0.5},
|
{0.375, -0.5, 0.4375, 0.5, 0.1875, 0.5},
|
||||||
{-0.5, 0, 0.4375, 0.5, 0.125, 0.5},
|
{-0.5, 0, 0.4375, 0.5, 0.125, 0.5},
|
||||||
{-0.5, -0.375, 0.4375, 0.5, -0.125, 0.5},
|
{-0.5, -0.375, 0.4375, 0.5, -0.125, 0.5},
|
||||||
{-0.5, -0.375, -0.5, -0.4375, -0.125, 0.5},
|
{-0.5, -0.375, -0.5, -0.4375, -0.125, 0.5},
|
||||||
{0.4375, -0.375, -0.5, 0.5, -0.125, 0.5},
|
{0.4375, -0.375, -0.5, 0.5, -0.125, 0.5},
|
||||||
{-0.4375, -0.3125, -0.5, 0.4375, -0.0625, 0.4375},
|
{-0.4375, -0.3125, -0.5, 0.4375, -0.0625, 0.4375},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
selectionbox = {-0.5, -0.5, -0.5, 0.5, 0.06, 1.5},
|
selectionbox = {-0.5, -0.5, -0.5, 0.5, 0.06, 1.5},
|
||||||
recipe = {
|
recipe = {
|
||||||
@ -48,41 +49,42 @@ beds.register_bed("beds:fancy_bed", {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
-- simple shaped bed
|
-- Simple shaped bed
|
||||||
|
|
||||||
beds.register_bed("beds:bed", {
|
beds.register_bed("beds:bed", {
|
||||||
description = "Simple Bed",
|
description = "Simple Bed",
|
||||||
inventory_image = "beds_bed.png",
|
inventory_image = "beds_bed.png",
|
||||||
wield_image = "beds_bed.png",
|
wield_image = "beds_bed.png",
|
||||||
tiles = {
|
tiles = {
|
||||||
bottom = {
|
bottom = {
|
||||||
"beds_bed_top_bottom.png^[transformR90",
|
"beds_bed_top_bottom.png^[transformR90",
|
||||||
"default_wood.png",
|
"default_wood.png",
|
||||||
"beds_bed_side_bottom_r.png",
|
"beds_bed_side_bottom_r.png",
|
||||||
"beds_bed_side_bottom_r.png^[transformfx",
|
"beds_bed_side_bottom_r.png^[transformfx",
|
||||||
"beds_transparent.png",
|
"beds_transparent.png",
|
||||||
"beds_bed_side_bottom.png"
|
"beds_bed_side_bottom.png"
|
||||||
},
|
},
|
||||||
top = {
|
top = {
|
||||||
"beds_bed_top_top.png^[transformR90",
|
"beds_bed_top_top.png^[transformR90",
|
||||||
"default_wood.png",
|
"default_wood.png",
|
||||||
"beds_bed_side_top_r.png",
|
"beds_bed_side_top_r.png",
|
||||||
"beds_bed_side_top_r.png^[transformfx",
|
"beds_bed_side_top_r.png^[transformfx",
|
||||||
"beds_bed_side_top.png",
|
"beds_bed_side_top.png",
|
||||||
"beds_transparent.png",
|
"beds_transparent.png",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
nodebox = {
|
nodebox = {
|
||||||
bottom = {-0.5, -0.5, -0.5, 0.5, 0.06, 0.5},
|
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},
|
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},
|
selectionbox = {-0.5, -0.5, -0.5, 0.5, 0.06, 1.5},
|
||||||
recipe = {
|
recipe = {
|
||||||
{"wool:red", "wool:red", "wool:white"},
|
{"wool:red", "wool:red", "wool:white"},
|
||||||
{"group:wood", "group:wood", "group:wood"}
|
{"group:wood", "group:wood", "group:wood"}
|
||||||
},
|
},
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
-- aliases for PA's beds mod
|
-- Aliases for PilzAdam's beds mod
|
||||||
|
|
||||||
minetest.register_alias("beds:bed_bottom_red", "beds:bed_bottom")
|
minetest.register_alias("beds:bed_bottom_red", "beds:bed_bottom")
|
||||||
minetest.register_alias("beds:bed_top_red", "beds:bed_top")
|
minetest.register_alias("beds:bed_top_red", "beds:bed_top")
|
||||||
|
@ -6,15 +6,14 @@ if enable_respawn == nil then
|
|||||||
enable_respawn = true
|
enable_respawn = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Helper functions
|
||||||
-- helper functions
|
|
||||||
|
|
||||||
local function get_look_yaw(pos)
|
local function get_look_yaw(pos)
|
||||||
local n = minetest.get_node(pos)
|
local n = minetest.get_node(pos)
|
||||||
if n.param2 == 1 then
|
if n.param2 == 1 then
|
||||||
return pi/2, n.param2
|
return pi / 2, n.param2
|
||||||
elseif n.param2 == 3 then
|
elseif n.param2 == 3 then
|
||||||
return -pi/2, n.param2
|
return -pi / 2, n.param2
|
||||||
elseif n.param2 == 0 then
|
elseif n.param2 == 0 then
|
||||||
return pi, n.param2
|
return pi, n.param2
|
||||||
else
|
else
|
||||||
@ -70,8 +69,8 @@ local function lay_down(player, pos, bed_pos, state, skip)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- physics, eye_offset, etc
|
-- physics, eye_offset, etc
|
||||||
player:set_eye_offset({x=0,y=0,z=0}, {x=0,y=0,z=0})
|
player:set_eye_offset({x = 0, y = 0, z = 0}, {x = 0, y = 0, z = 0})
|
||||||
player:set_look_yaw(math.random(1, 180)/100)
|
player:set_look_yaw(math.random(1, 180) / 100)
|
||||||
default.player_attached[name] = false
|
default.player_attached[name] = false
|
||||||
player:set_physics_override(1, 1, 1)
|
player:set_physics_override(1, 1, 1)
|
||||||
hud_flags.wielditem = true
|
hud_flags.wielditem = true
|
||||||
@ -84,11 +83,11 @@ local function lay_down(player, pos, bed_pos, state, skip)
|
|||||||
player_in_bed = player_in_bed + 1
|
player_in_bed = player_in_bed + 1
|
||||||
|
|
||||||
-- physics, eye_offset, etc
|
-- physics, eye_offset, etc
|
||||||
player:set_eye_offset({x=0,y=-13,z=0}, {x=0,y=0,z=0})
|
player:set_eye_offset({x = 0, y = -13, z = 0}, {x = 0, y = 0, z = 0})
|
||||||
local yaw, param2 = get_look_yaw(bed_pos)
|
local yaw, param2 = get_look_yaw(bed_pos)
|
||||||
player:set_look_yaw(yaw)
|
player:set_look_yaw(yaw)
|
||||||
local dir = minetest.facedir_to_dir(param2)
|
local dir = minetest.facedir_to_dir(param2)
|
||||||
local p = {x=bed_pos.x+dir.x/2,y=bed_pos.y,z=bed_pos.z+dir.z/2}
|
local p = {x = bed_pos.x + dir.x / 2, y = bed_pos.y, z = bed_pos.z + dir.z / 2}
|
||||||
player:set_physics_override(0, 0, 0)
|
player:set_physics_override(0, 0, 0)
|
||||||
player:setpos(p)
|
player:setpos(p)
|
||||||
default.player_attached[name] = true
|
default.player_attached[name] = true
|
||||||
@ -102,17 +101,15 @@ end
|
|||||||
local function update_formspecs(finished)
|
local function update_formspecs(finished)
|
||||||
local ges = #minetest.get_connected_players()
|
local ges = #minetest.get_connected_players()
|
||||||
local form_n = ""
|
local form_n = ""
|
||||||
local is_majority = (ges/2) < player_in_bed
|
local is_majority = (ges / 2) < player_in_bed
|
||||||
|
|
||||||
if finished then
|
if finished then
|
||||||
form_n = beds.formspec ..
|
form_n = beds.formspec .. "label[2.7,11; Good morning.]"
|
||||||
"label[2.7,11; Good morning.]"
|
|
||||||
else
|
else
|
||||||
form_n = beds.formspec ..
|
form_n = beds.formspec .. "label[2.2,11;" .. tostring(player_in_bed) ..
|
||||||
"label[2.2,11;"..tostring(player_in_bed).." of "..tostring(ges).." players are in bed]"
|
" of " .. tostring(ges) .. " players are in bed]"
|
||||||
if is_majority and is_night_skip_enabled() then
|
if is_majority and is_night_skip_enabled() then
|
||||||
form_n = form_n ..
|
form_n = form_n .. "button_exit[2,8;4,0.75;force;Force night skip]"
|
||||||
"button_exit[2,8;4,0.75;force;Force night skip]"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -122,10 +119,10 @@ local function update_formspecs(finished)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- public functions
|
-- Public functions
|
||||||
|
|
||||||
function beds.kick_players()
|
function beds.kick_players()
|
||||||
for name,_ in pairs(beds.player) do
|
for name, _ in pairs(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
|
||||||
@ -175,7 +172,7 @@ function beds.on_rightclick(pos, player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- callbacks
|
-- Callbacks
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
beds.read_spawns()
|
beds.read_spawns()
|
||||||
|
@ -3,14 +3,15 @@ beds.player = {}
|
|||||||
beds.pos = {}
|
beds.pos = {}
|
||||||
beds.spawn = {}
|
beds.spawn = {}
|
||||||
|
|
||||||
beds.formspec = "size[8,15;true]"..
|
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("beds")
|
||||||
|
|
||||||
-- load files
|
-- Load files
|
||||||
dofile(modpath.."/functions.lua")
|
|
||||||
dofile(modpath.."/api.lua")
|
dofile(modpath .. "/functions.lua")
|
||||||
dofile(modpath.."/beds.lua")
|
dofile(modpath .. "/api.lua")
|
||||||
dofile(modpath.."/spawns.lua")
|
dofile(modpath .. "/beds.lua")
|
||||||
|
dofile(modpath .. "/spawns.lua")
|
||||||
|
@ -43,7 +43,7 @@ function beds.save_spawns()
|
|||||||
end
|
end
|
||||||
local output = io.open(org_file, "w")
|
local output = io.open(org_file, "w")
|
||||||
for i, v in pairs(beds.spawn) do
|
for i, v in pairs(beds.spawn) do
|
||||||
output:write(v.x.." "..v.y.." "..v.z.." "..i.."\n")
|
output:write(v.x .. " " .. v.y .. " " .. v.z .. " " .. i .. "\n")
|
||||||
end
|
end
|
||||||
io.close(output)
|
io.close(output)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user