Get rid of metas on sitting function and more robust rightclick callback

This commit is contained in:
jp 2015-11-15 21:31:57 +01:00
parent 0beedaf539
commit d2ec545395

View File

@ -1,23 +1,19 @@
screwdriver = screwdriver or {}
local function sit(pos, node, clicker)
local meta = minetest.get_meta(pos)
local player = clicker:get_player_name()
if meta:get_string("is_sit") == "yes" then
meta:set_string("is_sit", "")
if default.player_attached[player] == true then
pos.y = pos.y - 0.5
clicker:setpos(pos)
clicker:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
clicker:set_physics_override(1, 1, 1)
default.player_attached[player] = false
default.player_set_animation(clicker, "stand", 30)
elseif meta:get_string("is_sit") == "" and
elseif default.player_attached[player] ~= true and
clicker:get_player_velocity().x == 0 and
clicker:get_player_velocity().y == 0 and
clicker:get_player_velocity().z == 0 then
meta:set_string("is_sit", "yes")
clicker:set_eye_offset({x=0, y=-7, z=2}, {x=0, y=0, z=0})
clicker:set_physics_override(0, 0, 0)
clicker:setpos(pos)
@ -69,8 +65,7 @@ xdecor.register("barrel", {
infotext = "Barrel",
tiles = {"xdecor_barrel_top.png", "xdecor_barrel_sides.png"},
groups = {choppy=3, flammable=3},
sounds = default.node_sound_wood_defaults(),
on_rotate = screwdriver.rotate_simple
sounds = default.node_sound_wood_defaults()
})
xdecor.register("cabinet", {
@ -193,14 +188,13 @@ xdecor.register("chair", {
on_rightclick = function(pos, node, clicker)
local objs = minetest.get_objects_inside_radius(pos, 0.5)
for _, p in pairs(objs) do
if p:get_player_name() ~= nil or node.param2 > 3 or not
clicker or not clicker:is_player() then return end
if p:get_player_name() ~= clicker:get_player_name() or
node.param2 > 3 then return end
end
pos.y = pos.y + 0
sit(pos, node, clicker)
end,
can_dig = function(pos, player)
local meta = minetest.get_meta(pos)
local pname = player:get_player_name()
local objs = minetest.get_objects_inside_radius(pos, 0.5)
@ -281,14 +275,13 @@ xdecor.register("cushion", {
on_rightclick = function(pos, node, clicker)
local objs = minetest.get_objects_inside_radius(pos, 0.5)
for _, p in pairs(objs) do
if p:get_player_name() ~= nil or node.param2 > 3 or not
clicker or not clicker:is_player() then return end
if p:get_player_name() ~= clicker:get_player_name() or
node.param2 > 3 then return end
end
pos.y = pos.y + 0
sit(pos, node, clicker)
end,
can_dig = function(pos, player)
local meta = minetest.get_meta(pos)
local pname = player:get_player_name()
local objs = minetest.get_objects_inside_radius(pos, 0.5)