Move sitting functions in handlers folder (turn it globals)
This commit is contained in:
parent
711d9fe88d
commit
84358fc489
52
handlers/animations.lua
Normal file
52
handlers/animations.lua
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
local function top_face(pointed_thing)
|
||||||
|
return pointed_thing.above.y > pointed_thing.under.y
|
||||||
|
end
|
||||||
|
|
||||||
|
function xdecor.sit(pos, node, clicker, pointed_thing)
|
||||||
|
if not top_face(pointed_thing) then return end
|
||||||
|
local player = clicker:get_player_name()
|
||||||
|
local objs = minetest.get_objects_inside_radius(pos, 0.1)
|
||||||
|
local vel = clicker:get_player_velocity()
|
||||||
|
local ctrl = clicker:get_player_control()
|
||||||
|
|
||||||
|
for _, p in pairs(objs) do
|
||||||
|
if p:get_player_name() ~= player then return end
|
||||||
|
end
|
||||||
|
|
||||||
|
if default.player_attached[player] 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 not default.player_attached[player] and node.param2 <= 3 and not
|
||||||
|
ctrl.sneak and vel.x == 0 and vel.y == 0 and vel.z == 0 then
|
||||||
|
|
||||||
|
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)
|
||||||
|
default.player_attached[player] = true
|
||||||
|
default.player_set_animation(clicker, "sit", 30)
|
||||||
|
|
||||||
|
if node.param2 == 0 then clicker:set_look_yaw(3.15)
|
||||||
|
elseif node.param2 == 1 then clicker:set_look_yaw(7.9)
|
||||||
|
elseif node.param2 == 2 then clicker:set_look_yaw(6.28)
|
||||||
|
elseif node.param2 == 3 then clicker:set_look_yaw(4.75) end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function xdecor.sit_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() or
|
||||||
|
default.player_attached[pname] then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
@ -21,7 +21,8 @@ xdecor.nodebox = {
|
|||||||
xdecor.pixelbox = function(size, boxes)
|
xdecor.pixelbox = function(size, boxes)
|
||||||
local fixed = {}
|
local fixed = {}
|
||||||
for _, box in pairs(boxes) do
|
for _, box in pairs(boxes) do
|
||||||
local x, y, z, w, h, l = unpack(box) -- `unpack` has been changed to `table.unpack` in newest Lua versions.
|
-- `unpack` has been changed to `table.unpack` in newest Lua versions.
|
||||||
|
local x, y, z, w, h, l = unpack(box)
|
||||||
fixed[#fixed+1] = {
|
fixed[#fixed+1] = {
|
||||||
(x / size) - 0.5,
|
(x / size) - 0.5,
|
||||||
(y / size) - 0.5,
|
(y / size) - 0.5,
|
||||||
|
@ -87,9 +87,7 @@ function xdecor.register(name, def)
|
|||||||
if inventory then
|
if inventory then
|
||||||
def.on_construct = def.on_construct or function(pos)
|
def.on_construct = def.on_construct or function(pos)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
if infotext then
|
if infotext then meta:set_string("infotext", infotext) end
|
||||||
meta:set_string("infotext", infotext)
|
|
||||||
end
|
|
||||||
|
|
||||||
local size = inventory.size or default_inventory_size
|
local size = inventory.size or default_inventory_size
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
|
5
init.lua
5
init.lua
@ -2,9 +2,13 @@
|
|||||||
xdecor = {}
|
xdecor = {}
|
||||||
local modpath = minetest.get_modpath("xdecor")
|
local modpath = minetest.get_modpath("xdecor")
|
||||||
|
|
||||||
|
-- Handlers.
|
||||||
|
dofile(modpath.."/handlers/animations.lua")
|
||||||
dofile(modpath.."/handlers/helpers.lua")
|
dofile(modpath.."/handlers/helpers.lua")
|
||||||
dofile(modpath.."/handlers/nodeboxes.lua")
|
dofile(modpath.."/handlers/nodeboxes.lua")
|
||||||
dofile(modpath.."/handlers/registration.lua")
|
dofile(modpath.."/handlers/registration.lua")
|
||||||
|
|
||||||
|
-- Item files.
|
||||||
dofile(modpath.."/chess.lua")
|
dofile(modpath.."/chess.lua")
|
||||||
dofile(modpath.."/cooking.lua")
|
dofile(modpath.."/cooking.lua")
|
||||||
dofile(modpath.."/craftitems.lua")
|
dofile(modpath.."/craftitems.lua")
|
||||||
@ -15,7 +19,6 @@ dofile(modpath.."/mailbox.lua")
|
|||||||
dofile(modpath.."/nodes.lua")
|
dofile(modpath.."/nodes.lua")
|
||||||
dofile(modpath.."/recipes.lua")
|
dofile(modpath.."/recipes.lua")
|
||||||
dofile(modpath.."/rope.lua")
|
dofile(modpath.."/rope.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))
|
||||||
|
49
nodes.lua
49
nodes.lua
@ -90,6 +90,27 @@ xdecor.register("candle", {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
xdecor.register("chair", {
|
||||||
|
description = "Chair",
|
||||||
|
tiles = {"xdecor_wood.png"},
|
||||||
|
sounds = default.node_sound_wood_defaults(),
|
||||||
|
groups = {choppy=3, oddly_breakable_by_hand=2, flammable=3},
|
||||||
|
on_rotate = screwdriver.rotate_simple,
|
||||||
|
node_box = xdecor.pixelbox(16, {
|
||||||
|
{3, 0, 11, 2, 16, 2},
|
||||||
|
{11, 0, 11, 2, 16, 2},
|
||||||
|
{5, 9, 11.5, 6, 6, 1},
|
||||||
|
{3, 0, 3, 2, 6, 2},
|
||||||
|
{11, 0, 3, 2, 6, 2},
|
||||||
|
{3, 6, 3, 10, 2, 8}
|
||||||
|
}),
|
||||||
|
can_dig = xdecor.sit_dig,
|
||||||
|
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||||
|
pos.y = pos.y + 0 -- Sitting position.
|
||||||
|
xdecor.sit(pos, node, clicker, pointed_thing)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
xpanes.register_pane("chainlink", {
|
xpanes.register_pane("chainlink", {
|
||||||
description = "Chain Link",
|
description = "Chain Link",
|
||||||
tiles = {"xdecor_chainlink.png"},
|
tiles = {"xdecor_chainlink.png"},
|
||||||
@ -172,6 +193,34 @@ xdecor.register("crate", {
|
|||||||
sounds = default.node_sound_wood_defaults()
|
sounds = default.node_sound_wood_defaults()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
xdecor.register("cushion", {
|
||||||
|
description = "Cushion",
|
||||||
|
tiles = {"xdecor_cushion.png"},
|
||||||
|
groups = {snappy=3, flammable=3, fall_damage_add_percent=-50},
|
||||||
|
on_place = minetest.rotate_node,
|
||||||
|
node_box = xdecor.nodebox.slab_y(0.5),
|
||||||
|
can_dig = xdecor.sit_dig,
|
||||||
|
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||||
|
pos.y = pos.y + 0
|
||||||
|
xdecor.sit(pos, node, clicker, pointed_thing)
|
||||||
|
|
||||||
|
local wield_item = clicker:get_wielded_item():get_name()
|
||||||
|
if wield_item == "xdecor:cushion" and clicker:get_player_control().sneak then
|
||||||
|
local player_name = clicker:get_player_name()
|
||||||
|
if minetest.is_protected(pos, player_name) then
|
||||||
|
minetest.record_protection_violation(pos, player_name) return
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.set_node(pos, {name="xdecor:cushion_block", param2=node.param2})
|
||||||
|
|
||||||
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
|
itemstack:take_item()
|
||||||
|
end
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
xdecor.register("cushion_block", {
|
xdecor.register("cushion_block", {
|
||||||
tiles = {"xdecor_cushion.png"},
|
tiles = {"xdecor_cushion.png"},
|
||||||
groups = {snappy=3, flammable=3, fall_damage_add_percent=-75, not_in_creative_inventory=1},
|
groups = {snappy=3, flammable=3, fall_damage_add_percent=-75, not_in_creative_inventory=1},
|
||||||
|
113
sitting.lua
113
sitting.lua
@ -1,113 +0,0 @@
|
|||||||
local function pointed_face(pointed_thing)
|
|
||||||
return pointed_thing.above.y > pointed_thing.under.y -- Top face pointed.
|
|
||||||
end
|
|
||||||
|
|
||||||
local function sit(pos, node, clicker, pointed_thing)
|
|
||||||
if not pointed_face(pointed_thing) then return end
|
|
||||||
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
|
|
||||||
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 default.player_attached[player] ~= true and node.param2 <= 3 and
|
|
||||||
clicker:get_player_control().sneak == false and
|
|
||||||
clicker:get_player_velocity().x == 0 and
|
|
||||||
clicker:get_player_velocity().y == 0 and
|
|
||||||
clicker:get_player_velocity().z == 0 then
|
|
||||||
|
|
||||||
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)
|
|
||||||
default.player_attached[player] = true
|
|
||||||
default.player_set_animation(clicker, "sit", 30)
|
|
||||||
|
|
||||||
if node.param2 == 0 then
|
|
||||||
clicker:set_look_yaw(3.15)
|
|
||||||
elseif node.param2 == 1 then
|
|
||||||
clicker:set_look_yaw(7.9)
|
|
||||||
elseif node.param2 == 2 then
|
|
||||||
clicker:set_look_yaw(6.28)
|
|
||||||
elseif node.param2 == 3 then
|
|
||||||
clicker:set_look_yaw(4.75)
|
|
||||||
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", {
|
|
||||||
description = "Chair",
|
|
||||||
tiles = {"xdecor_wood.png"},
|
|
||||||
sounds = default.node_sound_wood_defaults(),
|
|
||||||
groups = {choppy=3, oddly_breakable_by_hand=2, flammable=3},
|
|
||||||
on_rotate = screwdriver.rotate_simple,
|
|
||||||
node_box = xdecor.pixelbox(16, {
|
|
||||||
{3, 0, 11, 2, 16, 2},
|
|
||||||
{11, 0, 11, 2, 16, 2},
|
|
||||||
{5, 9, 11.5, 6, 6, 1},
|
|
||||||
{3, 0, 3, 2, 6, 2},
|
|
||||||
{11, 0, 3, 2, 6, 2},
|
|
||||||
{3, 6, 3, 10, 2, 8}
|
|
||||||
}),
|
|
||||||
can_dig = dig,
|
|
||||||
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
|
||||||
pos.y = pos.y + 0 -- Sitting position.
|
|
||||||
sit(pos, node, clicker, pointed_thing)
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
xdecor.register("cushion", {
|
|
||||||
description = "Cushion",
|
|
||||||
tiles = {"xdecor_cushion.png"},
|
|
||||||
groups = {snappy=3, flammable=3, fall_damage_add_percent=-50},
|
|
||||||
on_place = minetest.rotate_node,
|
|
||||||
node_box = xdecor.nodebox.slab_y(0.5),
|
|
||||||
can_dig = dig,
|
|
||||||
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
|
||||||
pos.y = pos.y + 0
|
|
||||||
sit(pos, node, clicker, pointed_thing)
|
|
||||||
|
|
||||||
local wield_item = clicker:get_wielded_item():get_name()
|
|
||||||
if wield_item == "xdecor:cushion" and clicker:get_player_control().sneak then
|
|
||||||
local player_name = clicker:get_player_name()
|
|
||||||
if minetest.is_protected(pos, player_name) then
|
|
||||||
minetest.record_protection_violation(pos, player_name)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if pointed_face(pointed_thing) then
|
|
||||||
minetest.set_node(pos, {name="xdecor:cushion_block", param2=node.param2})
|
|
||||||
end
|
|
||||||
|
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
|
||||||
itemstack:take_item()
|
|
||||||
end
|
|
||||||
|
|
||||||
return itemstack
|
|
||||||
end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
@ -122,7 +122,8 @@ function worktable:craftguide_formspec(meta, pagenum, item, recipe_num, filter)
|
|||||||
local items = minetest.get_all_craft_recipes(item)[recipe_num].items
|
local items = minetest.get_all_craft_recipes(item)[recipe_num].items
|
||||||
local width = minetest.get_all_craft_recipes(item)[recipe_num].width
|
local width = minetest.get_all_craft_recipes(item)[recipe_num].width
|
||||||
if width == 0 then width = math.min(3, #items) end
|
if width == 0 then width = math.min(3, #items) end
|
||||||
local rows = math.ceil(table.maxn(items) / width) -- Lua 5.3 removed `table.maxn`, use `xdecor.maxn` in case of failure.
|
-- Lua 5.3 removed `table.maxn`, use `xdecor.maxn` in case of breakage.
|
||||||
|
local rows = math.ceil(table.maxn(items) / width)
|
||||||
|
|
||||||
local function is_group(item)
|
local function is_group(item)
|
||||||
if item:sub(1,6) == "group:" then return "\nG" end
|
if item:sub(1,6) == "group:" then return "\nG" end
|
||||||
@ -414,7 +415,8 @@ for node in pairs(minetest.registered_nodes) do
|
|||||||
sounds = def.sounds,
|
sounds = def.sounds,
|
||||||
tiles = tiles,
|
tiles = tiles,
|
||||||
groups = groups,
|
groups = groups,
|
||||||
node_box = xdecor.pixelbox(16, {unpack(d, 3)}), -- `unpack` has been changed to `table.unpack` in newest Lua versions.
|
-- `unpack` has been changed to `table.unpack` in newest Lua versions.
|
||||||
|
node_box = xdecor.pixelbox(16, {unpack(d, 3)}),
|
||||||
sunlight_propagates = true,
|
sunlight_propagates = true,
|
||||||
on_place = minetest.rotate_node,
|
on_place = minetest.rotate_node,
|
||||||
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||||
|
Loading…
Reference in New Issue
Block a user