Mineclonia/mods/mcl_fences/init.lua

198 lines
6.3 KiB
Lua
Raw Normal View History

local init = os.clock()
2015-06-29 17:55:56 +00:00
2017-01-17 01:55:27 +00:00
-- Node box
local p = {-2/16, -1/2, -2/16, 2/16, 1/2, 2/16}
2015-06-29 17:55:56 +00:00
local x1 = {-2/16, 1/2-4/16, 1/16, -1/2, 1/2-1/16, -1/16} --oben(quer) -x
local x12 = {-2/16, -1/2+6/16, 1/16, -1/2, -1/2+9/16, -1/16} --unten(quer) -x
local x2 = {2/16, 1/2-4/16, -1/16, 1/2, 1/2-1/16, 1/16} --oben(quer) x
local x22 = {2/16, -1/2+6/16, -1/16, 1/2, -1/2+9/16, 1/16} --unten(quer) x
local z1 = {1/16, 1/2-4/16, -2/16, -1/16, 1/2-1/16, -1/2} --oben(quer) -z
local z12 = {1/16, -1/2+6/16, -2/16, -1/16, -1/2+9/16, -1/2} --unten(quer) -z
local z2 = {-1/16, 1/2-4/16, 2/16, 1/16, 1/2-1/16, 1/2} --oben(quer) z
local z22 = {-1/16, -1/2+6/16, 2/16, 1/16, -1/2+9/16, 1/2} --unten(quer) z
2017-01-17 01:55:27 +00:00
-- Collision box
local cp = {-2/16, -1/2, -2/16, 2/16, 1, 2/16}
local cx1 = {-2/16, -1/2+6/16, 2/16, -1/2, 1, -2/16} --unten(quer) -x
local cx2 = {2/16, -1/2+6/16, -2/16, 1/2, 1, 2/16} --unten(quer) x
local cz1 = {2/16, -1/2+6/16, -2/16, -2/16, 1, -1/2} --unten(quer) -z
local cz2 = {-2/16, -1/2+6/16, 2/16, 2/16, 1, 1/2} --unten(quer) z
2015-06-29 17:55:56 +00:00
2017-01-17 02:03:43 +00:00
minetest.register_node("mcl_fences:fence", {
description = "Oak Fence",
2015-06-29 17:55:56 +00:00
tiles = {"default_wood.png"},
inventory_image = "default_fence.png",
wield_image = "default_fence.png",
paramtype = "light",
is_ground_content = false,
2017-01-17 01:55:27 +00:00
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fence=1},
2015-06-29 17:55:56 +00:00
stack_max = 64,
sunlight_propagates = true,
drawtype = "nodebox",
2017-01-17 01:55:27 +00:00
connect_sides = { "front", "back", "left", "right" },
connects_to = { "group:solid", "group:fence" },
2015-06-29 17:55:56 +00:00
node_box = {
2017-01-17 01:55:27 +00:00
type = "connected",
fixed = {p},
connect_front = {z1,z12},
connect_back = {z2,z22,},
connect_left = {x1,x12},
connect_right = {x2,x22},
2015-06-29 17:55:56 +00:00
},
2017-01-17 01:55:27 +00:00
collision_box = {
type = "connected",
fixed = {cp},
connect_front = {cz1},
connect_back = {cz2,},
connect_left = {cx1},
connect_right = {cx2},
2015-06-29 17:55:56 +00:00
},
2017-01-17 01:55:27 +00:00
sounds = default.node_sound_wood_defaults(),
2015-06-29 17:55:56 +00:00
})
minetest.register_craft({
2017-01-17 02:03:43 +00:00
output = 'mcl_fences:fence 3',
2015-06-29 17:55:56 +00:00
recipe = {
2017-01-05 03:39:36 +00:00
{'default:wood', 'default:stick', 'default:wood'},
{'default:wood', 'default:stick', 'default:wood'},
2015-06-29 17:55:56 +00:00
}
})
minetest.register_craft({
2017-01-17 02:03:43 +00:00
output = 'mcl_fences:fence_gate',
2015-06-29 17:55:56 +00:00
recipe = {
{'default:stick', 'default:wood', 'default:stick'},
{'default:stick', 'default:wood', 'default:stick'},
}
})
2017-01-10 05:43:07 +00:00
minetest.register_craft({
type = "fuel",
2017-01-17 02:03:43 +00:00
recipe = "mcl_fences:fence",
2017-01-10 05:43:07 +00:00
burntime = 15,
})
minetest.register_craft({
type = "fuel",
2017-01-17 02:03:43 +00:00
recipe = "mcl_fences:fence_gate",
2017-01-10 05:43:07 +00:00
burntime = 15,
})
2015-06-29 17:55:56 +00:00
local meta2
local state2 = 0
local function update_gate(pos, node)
minetest.set_node(pos, node)
2015-06-29 17:55:56 +00:00
end
local function punch_gate(pos, node)
meta2 = minetest.get_meta(pos)
2015-06-29 17:55:56 +00:00
state2 = meta2:get_int("state")
local tmp_node2
if state2 == 1 then
state2 = 0
minetest.sound_play("door_close", {gain = 0.3, max_hear_distance = 10})
2017-01-17 02:03:43 +00:00
tmp_node2 = {name="mcl_fences:fence_gate", param1=node.param1, param2=node.param2}
2015-06-29 17:55:56 +00:00
else
state2 = 1
minetest.sound_play("door_open", {gain = 0.3, max_hear_distance = 10})
2017-01-17 02:03:43 +00:00
tmp_node2 = {name="mcl_fences:fence_gate_open", param1=node.param1, param2=node.param2}
2015-06-29 17:55:56 +00:00
end
update_gate(pos, tmp_node2)
meta2:set_int("state", state2)
end
2017-01-17 02:03:43 +00:00
minetest.register_node("mcl_fences:fence_gate_open", {
2015-06-29 17:55:56 +00:00
tiles = {"default_wood.png"},
inventory_image = "default_fence.png",
wield_image = "default_fence.png",
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
2015-06-29 17:55:56 +00:00
sunlight_propagates = true,
walkable = true,
2017-01-17 01:55:27 +00:00
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fence=1,not_in_inventory=1,mesecon_effector_on=1},
2017-01-17 02:03:43 +00:00
drop = 'mcl_fences:fence_gate',
2015-06-29 17:55:56 +00:00
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-1/2, -1/2+5/16, -1/16, -1/2+2/16, 1/2, 1/16}, --links abschluss
{1/2-2/16, -1/2+5/16, -1/16, 1/2, 1/2, 1/16}, --rechts abschluss
{-1/2, 1/2-4/16, 1/16, -1/2+2/16, 1/2-1/16, 1/2-2/16}, --oben-links(quer) x
{-1/2, -1/2+6/16, 1/16, -1/2+2/16, -1/2+9/16, 1/2-2/16}, --unten-links(quer) x
{1/2-2/16, 1/2-4/16, 1/16, 1/2, 1/2-1/16, 1/2}, --oben-rechts(quer) x
{1/2-2/16, -1/2+6/16, 1/16, 1/2, -1/2+9/16, 1/2}, --unten-rechts(quer) x
{-1/2, -1/2+6/16, 6/16, -1/2+2/16, 1/2-1/16, 1/2}, --mitte links
{1/2-2/16, 1/2-4/16, 1/2, 1/2, -1/2+9/16, 6/16}, --mitte rechts
}
},
selection_box = {
type = "fixed",
fixed = {
{-1/2, -1/2+5/16, -1/16, 1/2, 1/2, 1/16}, --gate
}
},
--on_punch = function(pos, node, puncher)
on_rightclick = function(pos, node, clicker)
punch_gate(pos, node)
end,
mesecons = {effector = {
action_on = (function(pos, node)
punch_gate(pos, node)
end),
}},
})
2017-01-17 02:03:43 +00:00
minetest.register_node("mcl_fences:fence_gate", {
description = "Oak Fence Gate",
2015-06-29 17:55:56 +00:00
tiles = {"default_wood.png"},
2017-01-17 02:03:43 +00:00
inventory_image = "mcl_fences_fence_gate.png",
wield_image = "mcl_fences_fence_gate.png",
2015-06-29 17:55:56 +00:00
paramtype = "light",
is_ground_content = false,
2015-06-29 17:55:56 +00:00
stack_max = 16,
paramtype2 = "facedir",
sunlight_propagates = true,
walkable = true,
2017-01-17 01:55:27 +00:00
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,mesecon_effector_on=1,fence=1},
2015-06-29 17:55:56 +00:00
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
{-1/2, -1/2+5/16, -1/16, -1/2+2/16, 1/2, 1/16}, --links abschluss
{1/2-2/16, -1/2+5/16, -1/16, 1/2, 1/2, 1/16}, --rechts abschluss
{-2/16, -1/2+6/16, -1/16, 0, 1/2-1/16, 1/16}, --mitte links
{0, -1/2+6/16, -1/16, 2/16, 1/2-1/16, 1/16}, --mitte rechts
{-2/16, 1/2-4/16, 1/16, -1/2, 1/2-1/16, -1/16}, --oben(quer) -z
{-2/16, -1/2+6/16, 1/16, -1/2, -1/2+9/16, -1/16}, --unten(quer) -z
{2/16, 1/2-4/16, -1/16, 1/2, 1/2-1/16, 1/16}, --oben(quer) z
{2/16, -1/2+6/16, -1/16, 1/2, -1/2+9/16, 1/16}, --unten(quer) z
p1,p2,p3,p4,p5,
bx1,bx11,bx2,bx21,
}
},
selection_box = {
type = "fixed",
fixed = {
{-1/2, -1/2+5/16, -1/16, 1/2, 1/2, 1/16}, --gate
}
},
on_construct = function(pos)
me2 = minetest.get_node(pos)
meta2 = minetest.get_meta(pos)
2015-06-29 17:55:56 +00:00
meta2:set_int("state", 0)
state2 = 0
end,
mesecons = {effector = {
action_on = (function(pos, node)
punch_gate(pos, node)
end),
}},
on_rightclick = function(pos, node, clicker)
punch_gate(pos, node)
end,
})
local time_to_load= os.clock() - init
print(string.format("[MOD] "..minetest.get_current_modname().." loaded in %.4f s", time_to_load))