Doors: Code cleanup

Remove spaces inside curly brackets
Split lines over 90 columns
This commit is contained in:
paramat 2016-07-07 17:48:02 +01:00
parent 60f6564c75
commit 3d44804074

View File

@ -1,4 +1,3 @@
--[[ --[[
Copyright (C) 2012 PilzAdam Copyright (C) 2012 PilzAdam
@ -166,9 +165,11 @@ function _doors.door_toggle(pos, clicker)
local dir = minetest.get_node(pos).param2 local dir = minetest.get_node(pos).param2
if state % 2 == 0 then if state % 2 == 0 then
minetest.sound_play(def.door.sounds[1], {pos = pos, gain = 0.3, max_hear_distance = 10}) minetest.sound_play(def.door.sounds[1],
{pos = pos, gain = 0.3, max_hear_distance = 10})
else else
minetest.sound_play(def.door.sounds[2], {pos = pos, gain = 0.3, max_hear_distance = 10}) minetest.sound_play(def.door.sounds[2],
{pos = pos, gain = 0.3, max_hear_distance = 10})
end end
minetest.swap_node(pos, { minetest.swap_node(pos, {
@ -181,21 +182,25 @@ function _doors.door_toggle(pos, clicker)
end end
local function on_place_node(place_to, newnode, placer, oldnode, itemstack, pointed_thing) local function on_place_node(place_to, newnode,
placer, oldnode, itemstack, pointed_thing)
-- Run script hook -- Run script hook
local _, callback local _, callback
for _, callback in ipairs(core.registered_on_placenodes) do for _, callback in ipairs(core.registered_on_placenodes) do
-- Deepcopy pos, node and pointed_thing because callback can modify them -- Deepcopy pos, node and pointed_thing because callback can modify them
local place_to_copy = {x = place_to.x, y = place_to.y, z = place_to.z} local place_to_copy = {x = place_to.x, y = place_to.y, z = place_to.z}
local newnode_copy = {name = newnode.name, param1 = newnode.param1, param2 = newnode.param2} local newnode_copy =
local oldnode_copy = {name = oldnode.name, param1 = oldnode.param1, param2 = oldnode.param2} {name = newnode.name, param1 = newnode.param1, param2 = newnode.param2}
local oldnode_copy =
{name = oldnode.name, param1 = oldnode.param1, param2 = oldnode.param2}
local pointed_thing_copy = { local pointed_thing_copy = {
type = pointed_thing.type, type = pointed_thing.type,
above = vector.new(pointed_thing.above), above = vector.new(pointed_thing.above),
under = vector.new(pointed_thing.under), under = vector.new(pointed_thing.under),
ref = pointed_thing.ref, ref = pointed_thing.ref,
} }
callback(place_to_copy, newnode_copy, placer, oldnode_copy, itemstack, pointed_thing_copy) callback(place_to_copy, newnode_copy, placer,
oldnode_copy, itemstack, pointed_thing_copy)
end end
end end
@ -269,7 +274,8 @@ function doors.register(name, def)
end end
local above = {x = pos.x, y = pos.y + 1, z = pos.z} local above = {x = pos.x, y = pos.y + 1, z = pos.z}
if not minetest.registered_nodes[minetest.get_node(above).name].buildable_to then if not minetest.registered_nodes[
minetest.get_node(above).name].buildable_to then
return itemstack return itemstack
end end
@ -316,7 +322,8 @@ function doors.register(name, def)
itemstack:take_item() itemstack:take_item()
end end
on_place_node(pos, minetest.get_node(pos), placer, node, itemstack, pointed_thing) on_place_node(pos, minetest.get_node(pos),
placer, node, itemstack, pointed_thing)
return itemstack return itemstack
end end
@ -514,11 +521,15 @@ function _doors.trapdoor_toggle(pos, clicker)
local def = minetest.registered_nodes[node.name] local def = minetest.registered_nodes[node.name]
if string.sub(node.name, -5) == "_open" then if string.sub(node.name, -5) == "_open" then
minetest.sound_play(def.sound_close, {pos = pos, gain = 0.3, max_hear_distance = 10}) minetest.sound_play(def.sound_close,
minetest.swap_node(pos, {name = string.sub(node.name, 1, string.len(node.name) - 5), param1 = node.param1, param2 = node.param2}) {pos = pos, gain = 0.3, max_hear_distance = 10})
minetest.swap_node(pos, {name = string.sub(node.name, 1,
string.len(node.name) - 5), param1 = node.param1, param2 = node.param2})
else else
minetest.sound_play(def.sound_open, {pos = pos, gain = 0.3, max_hear_distance = 10}) minetest.sound_play(def.sound_open,
minetest.swap_node(pos, {name = node.name .. "_open", param1 = node.param1, param2 = node.param2}) {pos = pos, gain = 0.3, max_hear_distance = 10})
minetest.swap_node(pos, {name = node.name .. "_open",
param1 = node.param1, param2 = node.param2})
end end
end end
@ -527,7 +538,8 @@ function doors.register_trapdoor(name, def)
local name_opened = name.."_open" local name_opened = name.."_open"
local function check_player_priv(pos, player) local function check_player_priv(pos, player)
if not def.protected or minetest.check_player_privs(player, "protection_bypass") then if not def.protected or
minetest.check_player_privs(player, "protection_bypass") then
return true return true
end end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)