Abstract some sitting code
This commit is contained in:
parent
50f77146b5
commit
b1a8732665
4
init.lua
4
init.lua
@ -16,5 +16,7 @@ dofile(modpath.."/nodes.lua")
|
|||||||
dofile(modpath.."/sitting.lua")
|
dofile(modpath.."/sitting.lua")
|
||||||
dofile(modpath.."/worktable.lua")
|
dofile(modpath.."/worktable.lua")
|
||||||
dofile(modpath.."/xwall.lua")
|
dofile(modpath.."/xwall.lua")
|
||||||
--print(string.format("xdecor loaded in %.2f ms", (os.clock()-t)*1000))
|
|
||||||
|
--print(string.format("xdecor loaded in %.2f ms", (os.clock()-t)*1000))
|
||||||
|
--TODO: remove the legacy code in ~6 months.
|
||||||
|
|
||||||
|
64
sitting.lua
64
sitting.lua
@ -1,5 +1,13 @@
|
|||||||
local function sit(pos, node, clicker)
|
local function sit(pos, node, clicker)
|
||||||
local player = clicker:get_player_name()
|
local player = clicker:get_player_name()
|
||||||
|
local objs = minetest.get_objects_inside_radius(pos, 0.1)
|
||||||
|
|
||||||
|
for _, p in pairs(objs) do
|
||||||
|
if p:get_player_name() ~= clicker:get_player_name() then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if default.player_attached[player] == true then
|
if default.player_attached[player] == true then
|
||||||
pos.y = pos.y - 0.5
|
pos.y = pos.y - 0.5
|
||||||
clicker:setpos(pos)
|
clicker:setpos(pos)
|
||||||
@ -30,6 +38,20 @@ local function sit(pos, node, clicker)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function dig(pos, player)
|
||||||
|
local pname = player:get_player_name()
|
||||||
|
local objs = minetest.get_objects_inside_radius(pos, 0.1)
|
||||||
|
|
||||||
|
for _, p in pairs(objs) do
|
||||||
|
if not player or not player:is_player() or p:get_player_name() ~= nil or
|
||||||
|
default.player_attached[pname] == true then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
xdecor.register("chair", {
|
xdecor.register("chair", {
|
||||||
description = "Chair",
|
description = "Chair",
|
||||||
tiles = {"xdecor_wood.png"},
|
tiles = {"xdecor_wood.png"},
|
||||||
@ -45,28 +67,10 @@ xdecor.register("chair", {
|
|||||||
{0.1875, -0.5, -0.3125, 0.3125, -0.125, -0.1875},
|
{0.1875, -0.5, -0.3125, 0.3125, -0.125, -0.1875},
|
||||||
{-0.3125, -0.125, -0.3125, 0.3125, 0, 0.1875}}
|
{-0.3125, -0.125, -0.3125, 0.3125, 0, 0.1875}}
|
||||||
},
|
},
|
||||||
|
can_dig = dig,
|
||||||
on_rightclick = function(pos, node, clicker)
|
on_rightclick = function(pos, node, clicker)
|
||||||
local objs = minetest.get_objects_inside_radius(pos, 0.1)
|
|
||||||
for _, p in pairs(objs) do
|
|
||||||
if p:get_player_name() ~= clicker:get_player_name() then return end
|
|
||||||
end
|
|
||||||
|
|
||||||
pos.y = pos.y + 0 -- Sitting position.
|
pos.y = pos.y + 0 -- Sitting position.
|
||||||
sit(pos, node, clicker)
|
sit(pos, node, clicker)
|
||||||
end,
|
|
||||||
can_dig = function(pos, player)
|
|
||||||
local pname = player:get_player_name()
|
|
||||||
local objs = minetest.get_objects_inside_radius(pos, 0.1)
|
|
||||||
|
|
||||||
for _, p in pairs(objs) do
|
|
||||||
if not player or not player:is_player() or
|
|
||||||
p:get_player_name() ~= nil or
|
|
||||||
default.player_attached[pname] == true then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -76,28 +80,10 @@ xdecor.register("cushion", {
|
|||||||
groups = {snappy=3, flammable=3, fall_damage_add_percent=-50},
|
groups = {snappy=3, flammable=3, fall_damage_add_percent=-50},
|
||||||
on_place = minetest.rotate_node,
|
on_place = minetest.rotate_node,
|
||||||
node_box = xdecor.nodebox.slab_y(-0.5, 0.5),
|
node_box = xdecor.nodebox.slab_y(-0.5, 0.5),
|
||||||
|
can_dig = dig,
|
||||||
on_rightclick = function(pos, node, clicker)
|
on_rightclick = function(pos, node, clicker)
|
||||||
local objs = minetest.get_objects_inside_radius(pos, 0.1)
|
pos.y = pos.y + 0 -- Sitting position.
|
||||||
for _, p in pairs(objs) do
|
|
||||||
if p:get_player_name() ~= clicker:get_player_name() then return end
|
|
||||||
end
|
|
||||||
|
|
||||||
pos.y = pos.y + 0
|
|
||||||
sit(pos, node, clicker)
|
sit(pos, node, clicker)
|
||||||
end,
|
|
||||||
can_dig = function(pos, player)
|
|
||||||
local pname = player:get_player_name()
|
|
||||||
local objs = minetest.get_objects_inside_radius(pos, 0.1)
|
|
||||||
|
|
||||||
for _, p in pairs(objs) do
|
|
||||||
if not player or not player:is_player() or
|
|
||||||
p:get_player_name() ~= nil or
|
|
||||||
default.player_attached[pname] == true then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user