mod-simple_models/samples.lua

303 lines
7.1 KiB
Lua
Raw Permalink Normal View History

2021-08-26 08:50:26 -07:00
local smodel = simple_models
2021-08-24 14:14:19 -07:00
-- cubes
core.register_node("simple_models:node_tall", {
description = "Tall Node",
drawtype = "mesh",
mesh = smodel.cube.mesh,
tiles = {"simple_models_sample_cube_1x2x1_map.png"},
collision_box = {
type = "fixed",
fixed = smodel.cube.box,
},
selection_box = {
type = "fixed",
fixed = smodel.cube.box,
},
2021-08-24 18:04:37 -07:00
paramtype2 = "colorfacedir",
palette = "simple_models_sample_palette.png",
groups = {oddly_breakable_by_hand=1},
})
2021-08-24 14:14:19 -07:00
-- panels
core.register_node("simple_models:panel", {
2021-08-23 15:29:43 -07:00
description = "Front Panel",
drawtype = "mesh",
tiles = {"simple_models_sample_panel_1x2x1_map.png"},
mesh = smodel.panel.mesh,
collision_box = {
type = "fixed",
fixed = smodel.panel.box,
},
selection_box = {
type = "fixed",
fixed = smodel.panel.box,
},
2021-08-24 18:04:37 -07:00
paramtype2 = "colorfacedir",
palette = "simple_models_sample_palette.png",
groups = {oddly_breakable_by_hand=1},
2021-08-24 12:59:04 -07:00
on_rightclick = function(pos, node, clicker, stack, pointed_thing)
core.swap_node(pos, {
name = "simple_models:panel_mid",
param1 = node.param1,
param2 = node.param2,
})
if core.global_exists("sounds") and sounds.woosh then
sounds.woosh()
end
return stack
end,
})
core.register_node("simple_models:panel_mid", {
description = "Mid Panel",
drawtype = "mesh",
tiles = {"simple_models_sample_panel_1x2x1_map.png"},
mesh = smodel.panel_mid.mesh,
collision_box = {
type = "fixed",
fixed = smodel.panel_mid.box,
},
selection_box = {
type = "fixed",
fixed = smodel.panel_mid.box,
},
2021-08-24 18:04:37 -07:00
paramtype2 = "colorfacedir",
palette = "simple_models_sample_palette.png",
2021-08-24 12:59:04 -07:00
groups = {oddly_breakable_by_hand=1},
on_rightclick = function(pos, node, clicker, stack, pointed_thing)
core.swap_node(pos, {
name = "simple_models:panel_rear",
param1 = node.param1,
param2 = node.param2,
})
if core.global_exists("sounds") and sounds.woosh then
sounds.woosh()
end
return stack
end,
})
core.register_node("simple_models:panel_rear", {
2021-08-23 15:29:43 -07:00
description = "Rear Panel",
drawtype = "mesh",
tiles = {"simple_models_sample_panel_1x2x1_map.png"},
mesh = smodel.panel_rear.mesh,
collision_box = {
type = "fixed",
fixed = smodel.panel_rear.box,
},
selection_box = {
type = "fixed",
fixed = smodel.panel_rear.box,
},
2021-08-24 18:04:37 -07:00
paramtype2 = "colorfacedir",
palette = "simple_models_sample_palette.png",
groups = {oddly_breakable_by_hand=1},
on_rightclick = function(pos, node, clicker, stack, pointed_thing)
core.swap_node(pos, {
name="simple_models:panel",
param1 = node.param1,
param2 = node.param2,
})
if core.global_exists("sounds") and sounds.woosh then
sounds.woosh()
end
return stack
end,
})
2021-08-24 14:14:19 -07:00
-- doors
2021-08-24 13:49:42 -07:00
local door_def = {
base = {
drawtype = "mesh",
tiles = {"simple_models_sample_panel_1x2x1_map.png"},
mesh = smodel.panel.mesh,
collision_box = {
type = "fixed",
fixed = smodel.panel.box,
},
selection_box = {
type = "fixed",
fixed = smodel.panel.box,
},
2021-08-24 18:04:37 -07:00
paramtype2 = "colorfacedir",
palette = "simple_models_sample_palette.png",
2021-08-24 13:49:42 -07:00
groups = {oddly_breakable_by_hand=1},
},
2021-08-24 13:49:42 -07:00
["in"] = {
desc = "inward",
func = {
closed = smodel.door_inward_open,
open = smodel.door_inward_close,
},
},
2021-08-24 13:49:42 -07:00
["out"] = {
desc = "outward",
func = {
closed = smodel.door_outward_open,
open = smodel.door_outward_close,
},
},
}
2021-08-24 14:14:19 -07:00
door_def.base_alt = table.copy(door_def.base)
door_def.base_alt.mesh = smodel.panel_rear.mesh
door_def.base_alt.collision_box.fixed = smodel.panel_rear.box
door_def.base_alt.selection_box.fixed = smodel.panel_rear.box
2021-08-24 14:40:05 -07:00
for _, dir in ipairs({"l", "r"}) do
for _, swing in ipairs({"in", "out"}) do
for _, state in ipairs({"closed", "open"}) do
local door_base
if swing == "in" and state == "open" then
door_base = table.copy(door_def.base_alt)
else
door_base = table.copy(door_def.base)
end
local door_aux = door_def[swing]
local door_name = "simple_models:door_" .. dir .. "_" .. swing .. "_" .. state
local invert = dir == "r"
door_base.description = "Door "
if dir == "l" then
door_base.description = door_base.description .. "L"
else
door_base.description = door_base.description .. "R"
end
door_base.description = door_base.description .. " (" .. door_aux.desc .. " opening)"
2021-08-24 14:14:19 -07:00
2021-08-24 14:40:05 -07:00
if state == "closed" then
door_base.on_rightclick = function(pos, node, clicker, stack, pointed_thing)
door_aux.func[state](smodel, pos,
"simple_models:door_" .. dir .. "_" .. swing .. "_open", invert)
if core.global_exists("sounds") and sounds.door_open then
sounds.door_open()
end
2021-08-24 14:40:05 -07:00
return stack
2021-08-24 13:49:42 -07:00
end
2021-08-24 18:04:37 -07:00
door_base.after_place_node = function(pos, placer, stack, pointed_thing)
local node = core.get_node(pos)
node.param2 = node.param2 + (3 * 32)
core.swap_node(pos, {name=node.name, param1=node.param1, param2=node.param2})
end
2021-08-24 14:40:05 -07:00
else
door_base.drop = "simple_models:door_" .. dir .. "_" .. swing .. "_closed"
door_base.groups.not_in_creative_inventory = 1
2021-08-24 14:40:05 -07:00
door_base.on_rightclick = function(pos, node, clicker, stack, pointed_thing)
door_aux.func[state](smodel, pos, door_base.drop, invert)
if core.global_exists("sounds") and sounds.door_close then
sounds.door_close()
end
return stack
2021-08-24 13:49:42 -07:00
end
2021-08-24 14:40:05 -07:00
door_base.after_place_node = function(pos, placer, stack, pointed_thing)
local node = core.get_node(pos)
core.swap_node(pos, {
name = door_base.drop,
param1 = node.param1,
param2 = node.param2,
})
end
end
2021-08-24 14:40:05 -07:00
core.register_node(door_name, door_base)
end
end
end
2021-08-26 06:47:48 -07:00
-- stairs
2021-08-26 13:50:59 -07:00
core.register_node("simple_models:stair_2s", {
description = "Stair (2-step)",
2021-08-26 06:47:48 -07:00
drawtype = "mesh",
2021-08-26 13:50:59 -07:00
tiles = {"simple_models_sample_stair_2s_1x1x1_map.png"},
mesh = smodel.stair_2s.mesh,
2021-08-26 06:47:48 -07:00
collision_box = {
type = "fixed",
2021-08-26 13:50:59 -07:00
fixed = smodel.stair_2s.box,
2021-08-26 06:47:48 -07:00
},
selection_box = {
type = "fixed",
2021-08-26 13:50:59 -07:00
fixed = smodel.stair_2s.box,
2021-08-26 06:47:48 -07:00
},
paramtype2 = "facedir",
groups = {oddly_breakable_by_hand=1, stair=1},
})
2021-08-26 08:40:56 -07:00
2021-08-26 13:50:59 -07:00
core.register_node("simple_models:stair_4s", {
description = "Stair (4-step)",
2021-08-26 13:39:27 -07:00
drawtype = "mesh",
2021-08-26 13:50:59 -07:00
tiles = {"simple_models_sample_stair_4s_1x1x1_map.png"},
mesh = smodel.stair_4s.mesh,
2021-08-26 13:39:27 -07:00
collision_box = {
type = "fixed",
2021-08-26 13:50:59 -07:00
fixed = smodel.stair_4s.box,
2021-08-26 13:39:27 -07:00
},
selection_box = {
type = "fixed",
2021-08-26 13:50:59 -07:00
fixed = smodel.stair_4s.box,
2021-08-26 13:39:27 -07:00
},
paramtype2 = "facedir",
groups = {oddly_breakable_by_hand=1, stair=1},
})
2021-08-26 08:40:56 -07:00
-- slopes
2021-08-26 09:19:01 -07:00
2021-08-26 08:40:56 -07:00
core.register_node("simple_models:slope", {
description = "Slope",
drawtype = "mesh",
tiles = {"simple_models_sample_slope_1x1x1_map.png"},
mesh = smodel.slope.mesh,
collision_box = {
type = "fixed",
fixed = smodel.slope.box,
},
selection_box = {
type = "fixed",
fixed = smodel.slope.box,
},
paramtype2 = "facedir",
groups = {oddly_breakable_by_hand=1, slope=1},
})
2021-08-26 09:19:01 -07:00
core.register_node("simple_models:slope_long", {
description = "Long Slope",
drawtype = "mesh",
2021-08-26 11:02:47 -07:00
tiles = {"simple_models_sample_slope_1x1x2_map.png"},
2021-08-26 09:19:01 -07:00
mesh = smodel.slope_long.mesh,
collision_box = {
type = "fixed",
fixed = smodel.slope_long.box,
},
selection_box = {
type = "fixed",
fixed = smodel.slope_long.box,
},
paramtype2 = "facedir",
groups = {oddly_breakable_by_hand=1, slope=1},
})