Nice settings (#171)

* improve style

* do something

* make settingtypes nicer

* fix settingtypes new lines

* fix it and so make it work 🐈
This commit is contained in:
DS 2017-04-14 03:13:30 +02:00 committed by Vanessa Ezekowitz
parent 3679943620
commit d82227942d
5 changed files with 146 additions and 64 deletions

40
default_settings.lua Normal file

@ -0,0 +1,40 @@
-- Various settings
local prefix = "pipeworks_"
local settings = {
enable_pipes = true,
enable_autocrafter = true,
enable_deployer = true,
enable_dispenser = true,
enable_node_breaker = true,
enable_teleport_tube = true,
enable_pipe_devices = true,
enable_redefines = true,
enable_mese_tube = true,
enable_detector_tube = true,
enable_digiline_detector_tube = true,
enable_conductor_tube = true,
enable_accelerator_tube = true,
enable_crossing_tube = true,
enable_sand_tube = true,
enable_mese_sand_tube = true,
enable_one_way_tube = true,
enable_priority_tube = true,
enable_cyclic_mode = true,
drop_on_routing_fail = false,
delete_item_on_clearobject = true,
}
for name, value in pairs(settings) do
local setting_type = type(value)
if setting_type == "boolean" then
pipeworks[name] = minetest.setting_getbool(prefix..name)
if pipeworks[name] == nil then
pipeworks[name] = value
end
else
pipeworks[name] = value
end
end

@ -1,24 +0,0 @@
-- Various settings
pipeworks.enable_pipes = true
pipeworks.enable_autocrafter = true
pipeworks.enable_deployer = true
pipeworks.enable_dispenser = true
pipeworks.enable_node_breaker = true
pipeworks.enable_teleport_tube = true
pipeworks.enable_pipe_devices = true
pipeworks.enable_redefines = true
pipeworks.enable_mese_tube = true
pipeworks.enable_detector_tube = true
pipeworks.enable_digiline_detector_tube = true
pipeworks.enable_conductor_tube = true
pipeworks.enable_accelerator_tube = true
pipeworks.enable_crossing_tube = true
pipeworks.enable_sand_tube = true
pipeworks.enable_mese_sand_tube = true
pipeworks.enable_one_way_tube = true
pipeworks.enable_priority_tube = true
pipeworks.enable_cyclic_mode = true
pipeworks.drop_on_routing_fail = false
pipeworks.delete_item_on_clearobject = true

@ -13,7 +13,7 @@ local DEBUG = false
pipeworks.worldpath = minetest.get_worldpath() pipeworks.worldpath = minetest.get_worldpath()
pipeworks.modpath = minetest.get_modpath("pipeworks") pipeworks.modpath = minetest.get_modpath("pipeworks")
dofile(pipeworks.modpath.."/default_settings.txt") dofile(pipeworks.modpath.."/default_settings.lua")
-- Read the external config file if it exists. -- Read the external config file if it exists.
local worldsettingspath = pipeworks.worldpath.."/pipeworks_settings.txt" local worldsettingspath = pipeworks.worldpath.."/pipeworks_settings.txt"

70
settingtypes.txt Normal file

@ -0,0 +1,70 @@
#Enable pipes.
pipeworks_enable_pipes (Enable Pipes) bool true
#Enable autocrafter.
pipeworks_enable_autocrafter (Enable Autocrafter) bool true
#Enable deployer.
pipeworks_enable_deployer (Enable Deployer) bool true
#Enable dispenser.
pipeworks_enable_dispenser (Enable Dispenser) bool true
#Enable node breaker.
pipeworks_enable_node_breaker (Enable Node Breaker) bool true
#Enable teleport tube.
pipeworks_enable_teleport_tube (Enable Teleport Tube) bool true
#Enable pipe devices.
pipeworks_enable_pipe_devices (Enable Pipe Devices) bool true
#Enable redefines.
pipeworks_enable_redefines (Enable Node Redefines) bool true
#Enable sorting tube.
pipeworks_enable_mese_tube (Enable Sorting Tube) bool true
#Enable detector tube.
pipeworks_enable_detector_tube (Enable Detector Tube) bool true
#Enable digiline detector tube.
pipeworks_enable_digiline_detector_tube (Enable Digiline Detector Tube) bool true
#Enable mesecon signal conducting tube.
pipeworks_enable_conductor_tube (Enable Conductor Tube) bool true
#Enable accelerator tube.
pipeworks_enable_accelerator_tube (Enable Accelerator Tube) bool true
#Enable crossing tube.
#It sends all incoming items to the other side, or if there is no other tube, it sends them back.
pipeworks_enable_crossing_tube (Enable Crossing Tube) bool true
#Enable vacuum tube.
#It picks up all items that lay around next to it.
pipeworks_enable_sand_tube (Enable Vacuum Tube) bool true
#Enable mese vacuum tube.
#It's like the normal vacuum tube with the
#differance that you can set the radius up to 8 nodes.
pipeworks_enable_mese_sand_tube (Enable Mese Vacuum Tube) bool true
#Enable one way tube.
#It sends items only in one direction.
#Use it to drop items out of tubes.
pipeworks_enable_one_way_tube (Enable One Way Tube) bool true
#Enable high priority tube.
#It has a very high priority and so, on crossings, the items will
#always go to it if there are multible ways.
pipeworks_enable_priority_tube (Enable High Priority Tube) bool true
#Enable cyclic mode.
pipeworks_enable_cyclic_mode (Enable Cyclic Mode) bool true
#Drop on routing fail.
pipeworks_drop_on_routing_fail (Drop On Routing Fail) bool false
#Delete item on clearobject.
pipeworks_delete_item_on_clearobject (Delete Item On Clearobject) bool true

@ -1,27 +1,27 @@
if pipeworks.enable_sand_tube then if pipeworks.enable_sand_tube then
pipeworks.register_tube("pipeworks:sand_tube", { pipeworks.register_tube("pipeworks:sand_tube", {
description = "Vacuuming Pneumatic Tube Segment", description = "Vacuuming Pneumatic Tube Segment",
inventory_image = "pipeworks_sand_tube_inv.png", inventory_image = "pipeworks_sand_tube_inv.png",
short = "pipeworks_sand_tube_short.png", short = "pipeworks_sand_tube_short.png",
noctr = { "pipeworks_sand_tube_noctr.png" }, noctr = {"pipeworks_sand_tube_noctr.png"},
plain = { "pipeworks_sand_tube_plain.png" }, plain = {"pipeworks_sand_tube_plain.png"},
ends = { "pipeworks_sand_tube_end.png" }, ends = {"pipeworks_sand_tube_end.png"},
node_def = { groups = {vacuum_tube = 1}}, node_def = {groups = {vacuum_tube = 1}},
}) })
minetest.register_craft( { minetest.register_craft( {
output = "pipeworks:sand_tube_1 2", output = "pipeworks:sand_tube_1 2",
recipe = { recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }, {"homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting"},
{ "group:sand", "group:sand", "group:sand" }, {"group:sand", "group:sand", "group:sand"},
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" } {"homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting"}
}, },
}) })
minetest.register_craft( { minetest.register_craft( {
output = "pipeworks:sand_tube_1", output = "pipeworks:sand_tube_1",
recipe = { recipe = {
{ "group:sand", "pipeworks:tube_1", "group:sand" }, {"group:sand", "pipeworks:tube_1", "group:sand"},
}, },
}) })
end end
@ -31,9 +31,9 @@ if pipeworks.enable_mese_sand_tube then
description = "Adjustable Vacuuming Pneumatic Tube Segment", description = "Adjustable Vacuuming Pneumatic Tube Segment",
inventory_image = "pipeworks_mese_sand_tube_inv.png", inventory_image = "pipeworks_mese_sand_tube_inv.png",
short = "pipeworks_mese_sand_tube_short.png", short = "pipeworks_mese_sand_tube_short.png",
noctr = { "pipeworks_mese_sand_tube_noctr.png" }, noctr = {"pipeworks_mese_sand_tube_noctr.png"},
plain = { "pipeworks_mese_sand_tube_plain.png" }, plain = {"pipeworks_mese_sand_tube_plain.png"},
ends = { "pipeworks_mese_sand_tube_end.png" }, ends = {"pipeworks_mese_sand_tube_end.png"},
node_def = { node_def = {
groups = {vacuum_tube = 1}, groups = {vacuum_tube = 1},
on_construct = function(pos) on_construct = function(pos)
@ -63,9 +63,9 @@ if pipeworks.enable_mese_sand_tube then
minetest.register_craft( { minetest.register_craft( {
output = "pipeworks:mese_sand_tube_1 2", output = "pipeworks:mese_sand_tube_1 2",
recipe = { recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }, {"homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "group:sand", "default:mese_crystal", "group:sand" }, {"group:sand", "default:mese_crystal", "group:sand" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" } {"homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
}, },
}) })
@ -82,23 +82,19 @@ if pipeworks.enable_mese_sand_tube then
}) })
end end
local sqrt_3 = math.sqrt(3)
local tube_inject_item = pipeworks.tube_inject_item
local get_objects_inside_radius = minetest.get_objects_inside_radius
local function vacuum(pos, radius) local function vacuum(pos, radius)
radius = radius + 0.5 radius = radius + 0.5
for _, object in pairs(get_objects_inside_radius(pos, sqrt_3 * radius)) do for _, object in pairs(minetest.get_objects_inside_radius(pos, math.sqrt(3) * radius)) do
local lua_entity = object:get_luaentity() local lua_entity = object:get_luaentity()
if not object:is_player() and lua_entity and lua_entity.name == "__builtin:item" then if not object:is_player() and lua_entity and lua_entity.name == "__builtin:item" then
local obj_pos = object:getpos() local obj_pos = object:getpos()
local x1, y1, z1 = pos.x, pos.y, pos.z local minpos = vector.subtract(pos, radius)
local x2, y2, z2 = obj_pos.x, obj_pos.y, obj_pos.z local maxpos = vector.add(pos, radius)
if obj_pos.x >= minpos.x and obj_pos.x <= maxpos.x
if x1 - radius <= x2 and x2 <= x1 + radius and obj_pos.y >= minpos.y and obj_pos.y <= maxpos.y
and y1 - radius <= y2 and y2 <= y1 + radius and obj_pos.z >= minpos.z and obj_pos.z <= maxpos.z then
and z1 - radius <= z2 and z2 <= z1 + radius then
if lua_entity.itemstring ~= "" then if lua_entity.itemstring ~= "" then
tube_inject_item(pos, pos, vector.new(0, 0, 0), lua_entity.itemstring) pipeworks.tube_inject_item(pos, pos, vector.new(0, 0, 0), lua_entity.itemstring)
lua_entity.itemstring = "" lua_entity.itemstring = ""
end end
object:remove() object:remove()
@ -108,15 +104,15 @@ local function vacuum(pos, radius)
end end
minetest.register_abm({nodenames = {"group:vacuum_tube"}, minetest.register_abm({nodenames = {"group:vacuum_tube"},
interval = 1, interval = 1,
chance = 1, chance = 1,
label = "Vacuum tubes", label = "Vacuum tubes",
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
if node.name:find("pipeworks:sand_tube") then if node.name:find("pipeworks:sand_tube") then
vacuum(pos, 2) vacuum(pos, 2)
else else
local radius = minetest.get_meta(pos):get_int("dist") local radius = minetest.get_meta(pos):get_int("dist")
vacuum(pos, radius) vacuum(pos, radius)
end end
end end
}) })