From c0af95716782720994055ce1bfd693bf730d4151 Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Sat, 13 Jul 2013 22:39:25 -0400 Subject: added ability to disable most components via config file in world folder moved pipes out of init.lua and into a separate file. some minor formatting changes --- init.lua | 345 +++++++++------------------------------------------------------ 1 file changed, 49 insertions(+), 296 deletions(-) (limited to 'init.lua') diff --git a/init.lua b/init.lua index b592d01..020db12 100644 --- a/init.lua +++ b/init.lua @@ -1,115 +1,35 @@ --- Pipeworks mod by Vanessa Ezekowitz - 2012-08-05 +-- Pipeworks mod by Vanessa Ezekowitz - 2013-07-13 -- --- Entirely my own code. This mod supplies various shapes of pipes --- and devices that they can connect to such as pumps, valves, etc. --- All pipes autoconnect as you lay them out, and devices will auto- --- connect to them. +-- This mod supplies various steel pipes and plastic pneumatic tubes +-- and devices that they can connect to. -- -- License: WTFPL -- -minetest.register_alias("pipeworks:pipe", "pipeworks:pipe_110000_empty") -local DEBUG = false -local CYCLIC = true - -pipeworks_liquid_texture = "default_water.png" - -pipe_leftstub = { - { -32/64, -2/64, -6/64, 1/64, 2/64, 6/64 }, -- pipe segment against -X face - { -32/64, -4/64, -5/64, 1/64, 4/64, 5/64 }, - { -32/64, -5/64, -4/64, 1/64, 5/64, 4/64 }, - { -32/64, -6/64, -2/64, 1/64, 6/64, 2/64 }, - - { -32/64, -3/64, -8/64, -30/64, 3/64, 8/64 }, -- (the flange for it) - { -32/64, -5/64, -7/64, -30/64, 5/64, 7/64 }, - { -32/64, -6/64, -6/64, -30/64, 6/64, 6/64 }, - { -32/64, -7/64, -5/64, -30/64, 7/64, 5/64 }, - { -32/64, -8/64, -3/64, -30/64, 8/64, 3/64 } -} - -pipe_rightstub = { - { -1/64, -2/64, -6/64, 32/64, 2/64, 6/64 }, -- pipe segment against +X face - { -1/64, -4/64, -5/64, 32/64, 4/64, 5/64 }, - { -1/64, -5/64, -4/64, 32/64, 5/64, 4/64 }, - { -1/64, -6/64, -2/64, 32/64, 6/64, 2/64 }, - - { 30/64, -3/64, -8/64, 32/64, 3/64, 8/64 }, -- (the flange for it) - { 30/64, -5/64, -7/64, 32/64, 5/64, 7/64 }, - { 30/64, -6/64, -6/64, 32/64, 6/64, 6/64 }, - { 30/64, -7/64, -5/64, 32/64, 7/64, 5/64 }, - { 30/64, -8/64, -3/64, 32/64, 8/64, 3/64 } -} - -pipe_bottomstub = { - { -2/64, -32/64, -6/64, 2/64, 1/64, 6/64 }, -- pipe segment against -Y face - { -4/64, -32/64, -5/64, 4/64, 1/64, 5/64 }, - { -5/64, -32/64, -4/64, 5/64, 1/64, 4/64 }, - { -6/64, -32/64, -2/64, 6/64, 1/64, 2/64 }, - - { -3/64, -32/64, -8/64, 3/64, -30/64, 8/64 }, -- (the flange for it) - { -5/64, -32/64, -7/64, 5/64, -30/64, 7/64 }, - { -6/64, -32/64, -6/64, 6/64, -30/64, 6/64 }, - { -7/64, -32/64, -5/64, 7/64, -30/64, 5/64 }, - { -8/64, -32/64, -3/64, 8/64, -30/64, 3/64 } -} +-- Copy and/or read the config file +local worldpath = minetest.get_worldpath() +local modpath = minetest.get_modpath("pipeworks") -pipe_topstub = { - { -2/64, -1/64, -6/64, 2/64, 32/64, 6/64 }, -- pipe segment against +Y face - { -4/64, -1/64, -5/64, 4/64, 32/64, 5/64 }, - { -5/64, -1/64, -4/64, 5/64, 32/64, 4/64 }, - { -6/64, -1/64, -2/64, 6/64, 32/64, 2/64 }, - - { -3/64, 30/64, -8/64, 3/64, 32/64, 8/64 }, -- (the flange for it) - { -5/64, 30/64, -7/64, 5/64, 32/64, 7/64 }, - { -6/64, 30/64, -6/64, 6/64, 32/64, 6/64 }, - { -7/64, 30/64, -5/64, 7/64, 32/64, 5/64 }, - { -8/64, 30/64, -3/64, 8/64, 32/64, 3/64 } -} - -pipe_frontstub = { - { -6/64, -2/64, -32/64, 6/64, 2/64, 1/64 }, -- pipe segment against -Z face - { -5/64, -4/64, -32/64, 5/64, 4/64, 1/64 }, - { -4/64, -5/64, -32/64, 4/64, 5/64, 1/64 }, - { -2/64, -6/64, -32/64, 2/64, 6/64, 1/64 }, - - { -8/64, -3/64, -32/64, 8/64, 3/64, -30/64 }, -- (the flange for it) - { -7/64, -5/64, -32/64, 7/64, 5/64, -30/64 }, - { -6/64, -6/64, -32/64, 6/64, 6/64, -30/64 }, - { -5/64, -7/64, -32/64, 5/64, 7/64, -30/64 }, - { -3/64, -8/64, -32/64, 3/64, 8/64, -30/64 } -} +if io.open(worldpath.."/pipeworks_settings.txt","r") == nil then -pipe_backstub = { - { -6/64, -2/64, -1/64, 6/64, 2/64, 32/64 }, -- pipe segment against -Z face - { -5/64, -4/64, -1/64, 5/64, 4/64, 32/64 }, - { -4/64, -5/64, -1/64, 4/64, 5/64, 32/64 }, - { -2/64, -6/64, -1/64, 2/64, 6/64, 32/64 }, + dofile(modpath.."/default_settings.txt") - { -8/64, -3/64, 30/64, 8/64, 3/64, 32/64 }, -- (the flange for it) - { -7/64, -5/64, 30/64, 7/64, 5/64, 32/64 }, - { -6/64, -6/64, 30/64, 6/64, 6/64, 32/64 }, - { -5/64, -7/64, 30/64, 5/64, 7/64, 32/64 }, - { -3/64, -8/64, 30/64, 3/64, 8/64, 32/64 } -} + io.input(modpath.."/default_settings.txt") + io.output(worldpath.."/pipeworks_settings.txt") -pipe_selectboxes = { - { -32/64, -8/64, -8/64, 8/64, 8/64, 8/64 }, - { -8/64 , -8/64, -8/64, 32/64, 8/64, 8/64 }, - { -8/64 , -32/64, -8/64, 8/64, 8/64, 8/64 }, - { -8/64 , -8/64, -8/64, 8/64, 32/64, 8/64 }, - { -8/64 , -8/64, -32/64, 8/64, 8/64, 8/64 }, - { -8/64 , -8/64, -8/64, 8/64, 8/64, 32/64 } -} + local size = 2^13 -- good buffer size (8K) + while true do + local block = io.read(size) + if not block then break end + io.write(block) + end -pipe_bendsphere = { - { -4/64, -4/64, -4/64, 4/64, 4/64, 4/64 }, - { -5/64, -3/64, -3/64, 5/64, 3/64, 3/64 }, - { -3/64, -5/64, -3/64, 3/64, 5/64, 3/64 }, - { -3/64, -3/64, -5/64, 3/64, 3/64, 5/64 } -} +else + dofile(worldpath.."/pipeworks_settings.txt") +end --- Functions +-- Helper functions if minetest.get_modpath("unified_inventory") or not minetest.setting_getbool("creative_mode") then pipeworks_expect_infinite_stacks = false @@ -117,13 +37,7 @@ else pipeworks_expect_infinite_stacks = true end -dbg = function(s) - if DEBUG then - print('[PIPEWORKS] ' .. s) - end -end - -function pipes_fix_image_names(table, replacement) +function pipeworks_fix_image_names(table, replacement) outtable={} for i in ipairs(table) do outtable[i]=string.gsub(table[i], "_XXXXX", replacement) @@ -132,7 +46,7 @@ function pipes_fix_image_names(table, replacement) return outtable end -function pipe_addbox(t, b) +function pipeworks_add_pipebox(t, b) for i in ipairs(b) do table.insert(t, b[i]) end @@ -171,200 +85,39 @@ function pipeworks_node_is_owned(pos, placer) end end --- now define the nodes! - -pipes_empty_nodenames = {} -pipes_full_nodenames = {} - -for xm = 0, 1 do -for xp = 0, 1 do -for ym = 0, 1 do -for yp = 0, 1 do -for zm = 0, 1 do -for zp = 0, 1 do - local outboxes = {} - local outsel = {} - local outimgs = {} - - if yp==1 then - pipe_addbox(outboxes, pipe_topstub) - table.insert(outsel, pipe_selectboxes[4]) - table.insert(outimgs, "pipeworks_pipe_end.png") - else - table.insert(outimgs, "pipeworks_plain.png") - end - if ym==1 then - pipe_addbox(outboxes, pipe_bottomstub) - table.insert(outsel, pipe_selectboxes[3]) - table.insert(outimgs, "pipeworks_pipe_end.png") - else - table.insert(outimgs, "pipeworks_plain.png") - end - if xp==1 then - pipe_addbox(outboxes, pipe_rightstub) - table.insert(outsel, pipe_selectboxes[2]) - table.insert(outimgs, "pipeworks_pipe_end.png") - else - table.insert(outimgs, "pipeworks_plain.png") - end - if xm==1 then - pipe_addbox(outboxes, pipe_leftstub) - table.insert(outsel, pipe_selectboxes[1]) - table.insert(outimgs, "pipeworks_pipe_end.png") - else - table.insert(outimgs, "pipeworks_plain.png") - end - if zp==1 then - pipe_addbox(outboxes, pipe_backstub) - table.insert(outsel, pipe_selectboxes[6]) - table.insert(outimgs, "pipeworks_pipe_end.png") - else - table.insert(outimgs, "pipeworks_plain.png") - end - if zm==1 then - pipe_addbox(outboxes, pipe_frontstub) - table.insert(outsel, pipe_selectboxes[5]) - table.insert(outimgs, "pipeworks_pipe_end.png") - else - table.insert(outimgs, "pipeworks_plain.png") - end - - local jx = xp+xm - local jy = yp+ym - local jz = zp+zm - - if (jx+jy+jz) == 1 then - if xm == 1 then - table.remove(outimgs, 3) - table.insert(outimgs, 3, "^pipeworks_plain.png") +function pipeworks_replace_name(tbl,tr,name) + local ntbl={} + for key,i in pairs(tbl) do + if type(i)=="string" then + ntbl[key]=string.gsub(i,tr,name) + elseif type(i)=="table" then + ntbl[key]=pipeworks_replace_name(i,tr,name) + else + ntbl[key]=i end - if xp == 1 then - table.remove(outimgs, 4) - table.insert(outimgs, 4, "^pipeworks_plain.png") - end - if ym == 1 then - table.remove(outimgs, 1) - table.insert(outimgs, 1, "^pipeworks_plain.png") - end - if xp == 1 then - table.remove(outimgs, 2) - table.insert(outimgs, 2, "^pipeworks_plain.png") - end - if zm == 1 then - table.remove(outimgs, 5) - table.insert(outimgs, 5, "^pipeworks_plain.png") - end - if zp == 1 then - table.remove(outimgs, 6) - table.insert(outimgs, 6, "^pipeworks_plain.png") - end - end - - if jx+jy+jz >= 2 then - pipe_addbox(outboxes, pipe_bendsphere) - end - - if (jx==2 and jy~=2 and jz~=2) then - table.remove(outimgs, 5) - table.remove(outimgs, 5) - table.insert(outimgs, 5, pipeworks_liquid_texture.."^pipeworks_windowed_XXXXX.png") - table.insert(outimgs, 5, pipeworks_liquid_texture.."^pipeworks_windowed_XXXXX.png") end - - if (jx~=2 and jy~=2 and jz==2) or (jx~=2 and jy==2 and jz~=2) then - table.remove(outimgs, 3) - table.remove(outimgs, 3) - table.insert(outimgs, 3, pipeworks_liquid_texture.."^pipeworks_windowed_XXXXX.png") - table.insert(outimgs, 3, pipeworks_liquid_texture.."^pipeworks_windowed_XXXXX.png") - end - - local pname = xm..xp..ym..yp..zm..zp - local pgroups = "" - - if pname ~= "110000" then - pgroups = {snappy=3, pipe=1, not_in_creative_inventory=1} - pipedesc = "Pipe segment (empty, "..pname..")... You hacker, you." - image = "pipeworks_plain.png" - else - pgroups = {snappy=3, pipe=1} - pipedesc = "Pipe segment" - image = nil - end - - minetest.register_node("pipeworks:pipe_"..pname.."_empty", { - description = pipedesc, - drawtype = "nodebox", - tiles = pipes_fix_image_names(outimgs, "_empty"), - inventory_image = image, - sunlight_propagates=true, - paramtype = "light", - selection_box = { - type = "fixed", - fixed = outsel - }, - node_box = { - type = "fixed", - fixed = outboxes - }, - groups = pgroups, - sounds = default.node_sound_wood_defaults(), - walkable = true, - drop = "pipeworks:pipe_110000_empty", - after_place_node = function(pos) - pipe_scanforobjects(pos) - end, - after_dig_node = function(pos) - pipe_scanforobjects(pos) - end, - }) - - minetest.register_node("pipeworks:pipe_"..pname.."_loaded", { - description = "Pipe segment (loaded, "..pname..")... You hacker, you.", - drawtype = "nodebox", - tiles = pipes_fix_image_names(outimgs, "_loaded"), - inventory_image = image, - sunlight_propagates = true, - paramtype = "light", - selection_box = { - type = "fixed", - fixed = outsel - }, - node_box = { - type = "fixed", - fixed = outboxes - }, - groups = {snappy=3, pipe=1, not_in_creative_inventory=1}, - sounds = default.node_sound_wood_defaults(), - walkable = true, - drop = "pipeworks:pipe_110000_empty", - after_place_node = function(pos) - pipe_scanforobjects(pos) - end, - after_dig_node = function(pos) - pipe_scanforobjects(pos) - end - }) - table.insert(pipes_empty_nodenames,"pipeworks:pipe_"..pname.."_empty") -- for the abms - table.insert(pipes_full_nodenames,"pipeworks:pipe_"..pname.."_loaded") -- for bacon -end -end -end -end -end + return ntbl end -local modpath = minetest.get_modpath("pipeworks") +-- Load the various parts of the mod -dofile(modpath.."/tubes.lua") -dofile(modpath.."/teleport_tube.lua") -dofile(modpath.."/devices.lua") dofile(modpath.."/autoplace.lua") -dofile(modpath.."/crafts.lua") -dofile(modpath.."/flowing_logic.lua") -dofile(modpath.."/compat.lua") dofile(modpath.."/item_transport.lua") -dofile(modpath.."/autocrafter.lua") -dofile(modpath.."/deployer.lua") -dofile(modpath.."/node_breaker.lua") +dofile(modpath.."/flowing_logic.lua") +dofile(modpath.."/crafts.lua") + +dofile(modpath.."/tubes.lua") + +if enable_pipes then dofile(modpath.."/pipes.lua") end +if enable_teleport_tube then dofile(modpath.."/teleport_tube.lua") end +if enable_pipe_devices then dofile(modpath.."/devices.lua") end +if enable_redefines then dofile(modpath.."/compat.lua") end +if enable_autocrafter then dofile(modpath.."/autocrafter.lua") end +if enable_deployer then dofile(modpath.."/deployer.lua") end +if enable_node_breaker then dofile(modpath.."/node_breaker.lua") end + +minetest.register_alias("pipeworks:pipe", "pipeworks:pipe_110000_empty") +local DEBUG = false +local CYCLIC = true print("Pipeworks loaded!") -- cgit v1.2.3