Generalize fences code and add new fence types

This commit is contained in:
Wuzzy 2017-01-17 04:01:29 +01:00
parent e3600d77c4
commit eb4e776954
1 changed files with 169 additions and 136 deletions

View File

@ -18,76 +18,57 @@ 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 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 local cz2 = {-2/16, -1/2+6/16, 2/16, 2/16, 1, 1/2} --unten(quer) z
minetest.register_node("mcl_fences:fence", { mcl_fences = {}
description = "Oak Fence", mcl_fences.register_fence = function(id, fence_name, fence_gate_name, texture, fence_image, gate_image, groups, connects_to, sounds)
tiles = {"default_wood.png"}, if groups == nil then groups = {} end
inventory_image = "default_fence.png", groups.fence = 1
wield_image = "default_fence.png", if connects_to == nil then connects_to = {} end
paramtype = "light", table.insert(connects_to, "group:solid")
is_ground_content = false, table.insert(connects_to, "group:fence")
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fence=1}, local id_gate = id .. "_gate"
stack_max = 64, minetest.register_node("mcl_fences:"..id, {
sunlight_propagates = true, description = fence_name,
drawtype = "nodebox", tiles = {texture},
connect_sides = { "front", "back", "left", "right" }, inventory_image = fence_image,
connects_to = { "group:solid", "group:fence" }, wield_image = fence_image,
node_box = { paramtype = "light",
type = "connected", is_ground_content = false,
fixed = {p}, groups = groups,
connect_front = {z1,z12}, stack_max = 64,
connect_back = {z2,z22,}, sunlight_propagates = true,
connect_left = {x1,x12}, drawtype = "nodebox",
connect_right = {x2,x22}, connect_sides = { "front", "back", "left", "right" },
}, connects_to = connects_to,
collision_box = { node_box = {
type = "connected", type = "connected",
fixed = {cp}, fixed = {p},
connect_front = {cz1}, connect_front = {z1,z12},
connect_back = {cz2,}, connect_back = {z2,z22,},
connect_left = {cx1}, connect_left = {x1,x12},
connect_right = {cx2}, connect_right = {x2,x22},
}, },
sounds = default.node_sound_wood_defaults(), collision_box = {
}) type = "connected",
fixed = {cp},
connect_front = {cz1},
connect_back = {cz2,},
connect_left = {cx1},
connect_right = {cx2},
},
sounds = sounds,
})
minetest.register_craft({ local meta2
output = 'mcl_fences:fence 3', local state2 = 0
recipe = {
{'default:wood', 'default:stick', 'default:wood'},
{'default:wood', 'default:stick', 'default:wood'},
}
})
minetest.register_craft({ local function update_gate(pos, node)
output = 'mcl_fences:fence_gate', minetest.set_node(pos, node)
recipe = { end
{'default:stick', 'default:wood', 'default:stick'},
{'default:stick', 'default:wood', 'default:stick'},
}
})
minetest.register_craft({ local function punch_gate(pos, node)
type = "fuel", meta2 = minetest.get_meta(pos)
recipe = "mcl_fences:fence", state2 = meta2:get_int("state")
burntime = 15, local tmp_node2
})
minetest.register_craft({
type = "fuel",
recipe = "mcl_fences:fence_gate",
burntime = 15,
})
local meta2
local state2 = 0
local function update_gate(pos, node)
minetest.set_node(pos, node)
end
local function punch_gate(pos, node)
meta2 = minetest.get_meta(pos)
state2 = meta2:get_int("state")
local tmp_node2
if state2 == 1 then if state2 == 1 then
state2 = 0 state2 = 0
minetest.sound_play("door_close", {gain = 0.3, max_hear_distance = 10}) minetest.sound_play("door_close", {gain = 0.3, max_hear_distance = 10})
@ -99,23 +80,24 @@ local function punch_gate(pos, node)
end end
update_gate(pos, tmp_node2) update_gate(pos, tmp_node2)
meta2:set_int("state", state2) meta2:set_int("state", state2)
end end
minetest.register_node("mcl_fences:fence_gate_open", { groups.mesecon_effector_on = 1
tiles = {"default_wood.png"}, minetest.register_node("mcl_fences:"..id_gate.."_open", {
inventory_image = "default_fence.png", tiles = {texture},
wield_image = "default_fence.png", inventory_image = gate_image,
paramtype = "light", wield_image = gate_image,
paramtype2 = "facedir", paramtype = "light",
is_ground_content = false, paramtype2 = "facedir",
sunlight_propagates = true, is_ground_content = false,
walkable = true, sunlight_propagates = true,
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fence=1,not_in_inventory=1,mesecon_effector_on=1}, walkable = true,
drop = 'mcl_fences:fence_gate', groups = groups,
drawtype = "nodebox", drop = 'mcl_fences:fence_gate',
node_box = { drawtype = "nodebox",
type = "fixed", node_box = {
fixed = { type = "fixed",
fixed = {
{-1/2, -1/2+5/16, -1/16, -1/2+2/16, 1/2, 1/16}, --links abschluss {-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-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-4/16, 1/16, -1/2+2/16, 1/2-1/16, 1/2-2/16}, --oben-links(quer) x
@ -125,40 +107,41 @@ minetest.register_node("mcl_fences:fence_gate_open", {
{-1/2, -1/2+6/16, 6/16, -1/2+2/16, 1/2-1/16, 1/2}, --mitte links {-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 {1/2-2/16, 1/2-4/16, 1/2, 1/2, -1/2+9/16, 6/16}, --mitte rechts
} }
}, },
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = { fixed = {
{-1/2, -1/2+5/16, -1/16, 1/2, 1/2, 1/16}, --gate {-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)
on_rightclick = function(pos, node, clicker) punch_gate(pos, node)
punch_gate(pos, node) end,
end, mesecons = {effector = {
mesecons = {effector = { action_on = (function(pos, node)
action_on = (function(pos, node) punch_gate(pos, node)
punch_gate(pos, node) end),
end), }},
}}, })
})
minetest.register_node("mcl_fences:fence_gate", { groups.mesecon_effector_on = nil
description = "Oak Fence Gate", groups.mesecon_effector_off = nil
tiles = {"default_wood.png"}, minetest.register_node("mcl_fences:"..id_gate, {
inventory_image = "mcl_fences_fence_gate.png", description = fence_gate_name,
wield_image = "mcl_fences_fence_gate.png", tiles = {texture},
paramtype = "light", inventory_image = gate_image,
is_ground_content = false, wield_image = gate_image,
stack_max = 16, paramtype = "light",
paramtype2 = "facedir", is_ground_content = false,
sunlight_propagates = true, stack_max = 64,
walkable = true, paramtype2 = "facedir",
groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,mesecon_effector_on=1,fence=1}, sunlight_propagates = true,
drawtype = "nodebox", walkable = true,
node_box = { groups = groups,
type = "fixed", drawtype = "nodebox",
fixed = { 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, -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-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 {-2/16, -1/2+6/16, -1/16, 0, 1/2-1/16, 1/16}, --mitte links
@ -170,28 +153,78 @@ minetest.register_node("mcl_fences:fence_gate", {
p1,p2,p3,p4,p5, p1,p2,p3,p4,p5,
bx1,bx11,bx2,bx21, bx1,bx11,bx2,bx21,
} }
}, },
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = { fixed = {
{-1/2, -1/2+5/16, -1/16, 1/2, 1/2, 1/16}, --gate {-1/2, -1/2+5/16, -1/16, 1/2, 1/2, 1/16}, --gate
} }
}, },
on_construct = function(pos) on_construct = function(pos)
me2 = minetest.get_node(pos) meta2 = minetest.get_meta(pos)
meta2 = minetest.get_meta(pos) meta2:set_int("state", 0)
meta2:set_int("state", 0) state2 = 0
state2 = 0 end,
end, mesecons = {effector = {
mesecons = {effector = { action_on = (function(pos, node)
action_on = (function(pos, node) punch_gate(pos, node)
punch_gate(pos, node) end),
end), }},
}}, on_rightclick = function(pos, node, clicker)
on_rightclick = function(pos, node, clicker) punch_gate(pos, node)
punch_gate(pos, node) end,
end, })
end
local wood_groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fence_wood=1}
local wood_connect = {}
local wood_sounds = default.node_sound_wood_defaults()
local woods = {
{"", "Oak Fence", "Oak Fence Gate", "default_wood.png", "default_fence.png", "mcl_fences_fence_gate.png", "default:wood"},
{"spruce", "Spruce Fence", "Spruce Fence Gate", "default_sprucewood.png", "default_fence.png", "mcl_fences_fence_gate.png", "default:sprucewood"},
{"birch", "Birch Fence", "Birch Fence Gate", "default_planks_birch.png", "default_fence.png", "mcl_fences_fence_gate.png", "default:birchwood"},
{"jungle", "Jungle Fence", "Jungle Fence Gate", "default_junglewood.png", "default_fence.png", "mcl_fences_fence_gate.png", "default:junglewood"},
{"dark_oak", "Dark Oak Fence", "Dark Oak Fence Gate", "default_planks_big_oak.png", "default_fence.png", "mcl_fences_fence_gate.png", "default:darkwood"},
{"acacia", "Acacia Fence", "Acacia Fence Gate", "default_acaciawood.png", "default_fence.png", "mcl_fences_fence_gate.png", "default:acaciawood"},
}
for w=1, #woods do
local wood = woods[w]
local id, id_gate
if wood[1] == "" then
id = "fence"
id_gate = "fence_gate"
else
id = wood[1].."_fence"
id_gate = wood[1].."_fence_gate"
end
mcl_fences.register_fence(id, wood[2], wood[3], wood[4], wood[5], wood[6], wood_groups, wood_connect, wood_sounds)
minetest.register_craft({
output = 'mcl_fences:'..id..' 3',
recipe = {
{wood[7], 'default:stick', wood[7]},
{wood[7], 'default:stick', wood[7]},
}
})
minetest.register_craft({
output = 'mcl_fences:'..id_gate,
recipe = {
{'default:stick', wood[7], 'default:stick'},
{'default:stick', wood[7], 'default:stick'},
}
})
end
minetest.register_craft({
type = "fuel",
recipe = "group:fence_wood",
burntime = 15,
}) })
local time_to_load= os.clock() - init local time_to_load= os.clock() - init
print(string.format("[MOD] "..minetest.get_current_modname().." loaded in %.4f s", time_to_load)) print(string.format("[MOD] "..minetest.get_current_modname().." loaded in %.4f s", time_to_load))