1
0
Fork 0
MineClone2-finecraft/mods/ITEMS/mcl_fences/init.lua

279 lines
9.5 KiB
Lua
Raw Normal View History

local init = os.clock()
2015-06-29 19:55:56 +02:00
2017-01-17 02:55:27 +01:00
-- Node box
local p = {-2/16, -1/2, -2/16, 2/16, 1/2, 2/16}
2015-06-29 19:55:56 +02: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 02:55:27 +01: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 19:55:56 +02:00
mcl_fences = {}
mcl_fences.register_fence = function(id, fence_name, texture, groups, connects_to, sounds)
if groups == nil then groups = {} end
groups.fence = 1
groups.deco_block = 1
if connects_to == nil then connects_to = {} end
2017-02-10 05:33:49 +01:00
local fence_id = minetest.get_current_modname()..":"..id
table.insert(connects_to, "group:solid")
2017-02-10 05:33:49 +01:00
table.insert(connects_to, "group:fence_gate")
table.insert(connects_to, fence_id)
minetest.register_node(fence_id, {
description = fence_name,
tiles = {texture},
2017-01-17 04:18:36 +01:00
inventory_image = "mcl_fences_fence_mask.png^" .. texture .. "^mcl_fences_fence_mask.png^[makealpha:255,126,126",
wield_image = "mcl_fences_fence_mask.png^" .. texture .. "^mcl_fences_fence_mask.png^[makealpha:255,126,126",
paramtype = "light",
is_ground_content = false,
groups = groups,
stack_max = 64,
sunlight_propagates = true,
drawtype = "nodebox",
connect_sides = { "front", "back", "left", "right" },
connects_to = connects_to,
node_box = {
type = "connected",
fixed = {p},
connect_front = {z1,z12},
connect_back = {z2,z22,},
connect_left = {x1,x12},
connect_right = {x2,x22},
},
collision_box = {
type = "connected",
fixed = {cp},
connect_front = {cz1},
connect_back = {cz2,},
connect_left = {cx1},
connect_right = {cx2},
},
sounds = sounds,
})
2017-02-21 20:53:43 +01:00
return fence_id
end
2015-06-29 19:55:56 +02:00
mcl_fences.register_fence_gate = function(id, fence_gate_name, texture, groups, sounds, sound_open, sound_close, sound_gain)
local meta2
local state2 = 0
2015-06-29 19:55:56 +02:00
local function update_gate(pos, node)
minetest.set_node(pos, node)
end
2015-06-29 19:55:56 +02:00
local gate_id = minetest.get_current_modname()..":"..id.."_gate"
2017-02-21 20:53:43 +01:00
local open_gate_id = gate_id .. "_open"
2017-02-22 03:57:12 +01:00
if not sound_open then
sound_open = "doors_fencegate_open"
end
if not sound_close then
sound_close = "doors_fencegate_close"
end
if not sound_gain then
sound_gain = 0.3
end
local function punch_gate(pos, node)
meta2 = minetest.get_meta(pos)
state2 = meta2:get_int("state")
local tmp_node2
2015-06-29 19:55:56 +02:00
if state2 == 1 then
state2 = 0
2017-02-22 03:57:12 +01:00
minetest.sound_play(sound_close, {gain = 0.5, max_hear_distance = 10})
tmp_node2 = {name=gate_id, param1=node.param1, param2=node.param2}
2015-06-29 19:55:56 +02:00
else
state2 = 1
2017-02-22 03:57:12 +01:00
minetest.sound_play(sound_open, {gain = 0.5, max_hear_distance = 10})
2017-02-21 20:53:43 +01:00
tmp_node2 = {name=open_gate_id, param1=node.param1, param2=node.param2}
2015-06-29 19:55:56 +02:00
end
update_gate(pos, tmp_node2)
meta2:set_int("state", state2)
end
2015-06-29 19:55:56 +02:00
if groups == nil then groups = {} end
groups.fence_gate = 1
groups.deco_block = 1
2017-02-08 20:26:04 +01:00
groups.mesecon_effector_on = 1
2017-02-10 05:33:49 +01:00
groups.fence_gate = 1
2017-02-21 20:53:43 +01:00
minetest.register_node(open_gate_id, {
tiles = {texture},
paramtype = "light",
paramtype2 = "facedir",
2017-01-17 04:18:36 +01:00
inventory_image = "mcl_fences_fence_gate_mask.png^" .. texture .. "^mcl_fences_fence_gate_mask.png^[makealpha:255,126,126",
wield_image = "mcl_fences_fence_gate_mask.png^" .. texture .. "^mcl_fences_fence_gate_mask.png^[makealpha:255,126,126",
is_ground_content = false,
sunlight_propagates = true,
walkable = true,
groups = groups,
2017-02-22 03:28:25 +01:00
drop = gate_id,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
2015-06-29 19:55:56 +02:00
{-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_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 04:19:37 +01:00
sounds = sounds,
})
2015-06-29 19:55:56 +02:00
groups.mesecon_effector_on = nil
groups.mesecon_effector_off = nil
minetest.register_node(gate_id, {
description = fence_gate_name,
tiles = {texture},
2017-01-17 04:18:36 +01:00
inventory_image = "mcl_fences_fence_gate_mask.png^" .. texture .. "^mcl_fences_fence_gate_mask.png^[makealpha:255,126,126",
wield_image = "mcl_fences_fence_gate_mask.png^" .. texture .. "^mcl_fences_fence_gate_mask.png^[makealpha:255,126,126",
paramtype = "light",
is_ground_content = false,
stack_max = 64,
paramtype2 = "facedir",
sunlight_propagates = true,
walkable = true,
groups = groups,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {
2015-06-29 19:55:56 +02:00
{-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
}
},
2017-01-20 18:31:24 +01:00
collision_box = {
type = "fixed",
fixed = {
{-1/2, -1/2+5/16, -2/16, 1/2, 1, 2/16}, --gate
}
},
selection_box = {
type = "fixed",
fixed = {
2017-01-20 18:31:24 +01:00
{-1/2, -1/2+5/16, -1/16, 1/2, 1/2, 1/16}, --gate
2015-06-29 19:55:56 +02:00
}
},
on_construct = function(pos)
meta2 = minetest.get_meta(pos)
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,
2017-01-17 04:19:37 +01:00
sounds = sounds,
})
2017-02-21 20:53:43 +01:00
return gate_id, open_gate_id
end
mcl_fences.register_fence_and_fence_gate = function(id, fence_name, fence_gate_name, texture, groups, connects_to, sounds, sound_open, sound_close)
local fence_id = mcl_fences.register_fence(id, fence_name, texture, groups, connects_to, sounds)
local gate_id, open_gate_id = mcl_fences.register_fence_gate(id, fence_gate_name, texture, groups, sounds, sound_open, sound_close)
2017-02-21 20:53:43 +01:00
return fence_id, gate_id, open_gate_id
end
local wood_groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=2,fence_wood=1}
2017-02-10 05:33:49 +01:00
local wood_connect = {"group:fence_wood"}
local wood_sounds = mcl_sounds.node_sound_wood_defaults()
local woods = {
{"", "Oak Fence", "Oak Fence Gate", "default_wood.png", "mcl_core:wood"},
{"spruce", "Spruce Fence", "Spruce Fence Gate", "default_sprucewood.png", "mcl_core:sprucewood"},
{"birch", "Birch Fence", "Birch Fence Gate", "default_planks_birch.png", "mcl_core:birchwood"},
{"jungle", "Jungle Fence", "Jungle Fence Gate", "default_junglewood.png", "mcl_core:junglewood"},
{"dark_oak", "Dark Oak Fence", "Dark Oak Fence Gate", "default_planks_big_oak.png", "mcl_core:darkwood"},
{"acacia", "Acacia Fence", "Acacia Fence Gate", "default_acaciawood.png", "mcl_core: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_and_fence_gate(id, wood[2], wood[3], wood[4], wood_groups, wood_connect, wood_sounds)
minetest.register_craft({
output = 'mcl_fences:'..id..' 3',
recipe = {
{wood[5], 'mcl_core:stick', wood[5]},
{wood[5], 'mcl_core:stick', wood[5]},
}
})
minetest.register_craft({
output = 'mcl_fences:'..id_gate,
recipe = {
{'mcl_core:stick', wood[5], 'mcl_core:stick'},
{'mcl_core:stick', wood[5], 'mcl_core:stick'},
}
})
end
2017-02-08 20:26:04 +01:00
-- Nether Brick Fence (without fence gate!)
mcl_fences.register_fence("nether_brick_fence", "Nether Brick Fence", "mcl_nether_nether_brick.png", {cracky=2, deco_block=1, fence_nether_brick=1}, {"group:fence_nether_brick"}, mcl_sounds.node_sound_stone_defaults())
2017-02-08 20:26:04 +01:00
minetest.register_craft({
output = 'mcl_fences:nether_brick_fence 6',
recipe = {
{"mcl_nether:nether_brick", "mcl_nether:nether_brick", "mcl_nether:nether_brick"},
{"mcl_nether:nether_brick", "mcl_nether:nether_brick", "mcl_nether:nether_brick"},
}
})
minetest.register_craft({
type = "fuel",
recipe = "group:fence_wood",
burntime = 15,
2015-06-29 19:55:56 +02:00
})
local time_to_load= os.clock() - init
print(string.format("[MOD] "..minetest.get_current_modname().." loaded in %.4f s", time_to_load))