UPDATED PIPEWORKS TEST commit: f80dec1220427e1756ab82245a93e0355d7838aa

master
rnd 2015-04-12 09:21:15 +02:00
parent 86bb63ed86
commit 1fc5a371de
310 changed files with 5917 additions and 1085 deletions

1
mods/pipeworks/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*~

View File

@ -1,7 +1,7 @@
This mod uses nodeboxes to supply a complete set of 3D pipes and tubes,
along devices that work with them.
See http://vanessae.github.io/pipeworks/ for detailed information about usage of this mod.
See https://github.com/VanessaE/pipeworks/wiki/ for detailed information about usage of this mod.
Unlike the previous version of this mod, these pipes are rounded, and when
placed, they'll automatically join together as needed. Pipes can go vertically

View File

@ -1,79 +1,239 @@
local autocrafterCache = {} -- caches some recipe data to avoid to call the slow function minetest.get_craft_result() every second
local function make_inventory_cache(invlist)
local l = {}
for _, stack in ipairs(invlist) do
l[stack:get_name()] = (l[stack:get_name()] or 0) + stack:get_count()
local craft_time = 1
local function count_index(invlist)
local index = {}
for _, stack in pairs(invlist) do
if not stack:is_empty() then
local stack_name = stack:get_name()
index[stack_name] = (index[stack_name] or 0) + stack:get_count()
end
end
return l
return index
end
local function autocraft(inventory, pos)
local recipe = inventory:get_list("recipe")
local recipe_last
local result
local new
local function get_item_info(stack)
local name = stack:get_name()
local def = minetest.registered_items[name]
local description = def and def.description or "Unknown item"
return description, name
end
if autocrafterCache[minetest.hash_node_position(pos)] == nil then
recipe_last = {}
for i = 1, 9 do
recipe_last[i] = recipe[i]
recipe[i] = ItemStack({name = recipe[i]:get_name(), count = 1})
end
result, new = minetest.get_craft_result({method = "normal", width = 3, items = recipe})
autocrafterCache[minetest.hash_node_position(pos)] = {["recipe"] = recipe, ["result"] = result, ["new"] = new}
else
local autocrafterCacheEntry = autocrafterCache[minetest.hash_node_position(pos)]
recipe_last = autocrafterCacheEntry["recipe"]
result = autocrafterCacheEntry["result"]
new = autocrafterCacheEntry["new"]
local recipeUnchanged = true
for i = 1, 9 do
if recipe[i]:get_name() ~= recipe_last[i]:get_name() then
recipeUnchanged = false
break
end
if recipe[i]:get_count() ~= recipe_last[i]:get_count() then
recipeUnchanged = false
break
end
end
if recipeUnchanged then
else
for i = 1, 9 do
recipe_last[i] = recipe[i]
recipe[i] = ItemStack({name = recipe[i]:get_name(), count = 1})
end
result, new = minetest.get_craft_result({method = "normal", width = 3, items = recipe})
autocrafterCache[minetest.hash_node_position(pos)] = {["recipe"] = recipe, ["result"] = result, ["new"] = new}
end
local function get_craft(pos, inventory, hash)
local hash = hash or minetest.hash_node_position(pos)
local craft = autocrafterCache[hash]
if not craft then
local recipe = inventory:get_list("recipe")
local output, decremented_input = minetest.get_craft_result({method = "normal", width = 3, items = recipe})
craft = {recipe = recipe, consumption=count_index(recipe), output = output, decremented_input = decremented_input}
autocrafterCache[hash] = craft
end
return craft
end
if result.item:is_empty() then return end
result = result.item
if not inventory:room_for_item("dst", result) then return end
local to_use = {}
for _, item in ipairs(recipe) do
if item~= nil and not item:is_empty() then
if to_use[item:get_name()] == nil then
to_use[item:get_name()] = 1
else
to_use[item:get_name()] = to_use[item:get_name()]+1
end
end
local function autocraft(inventory, craft)
if not craft then return false end
local output_item = craft.output.item
-- check if we have enough room in dst
if not inventory:room_for_item("dst", output_item) then return false end
local consumption = craft.consumption
local inv_index = count_index(inventory:get_list("src"))
-- check if we have enough material available
for itemname, number in pairs(consumption) do
if (not inv_index[itemname]) or inv_index[itemname] < number then return false end
end
local invcache = make_inventory_cache(inventory:get_list("src"))
for itemname, number in pairs(to_use) do
if (not invcache[itemname]) or invcache[itemname] < number then return end
end
for itemname, number in pairs(to_use) do
-- consume material
for itemname, number in pairs(consumption) do
for i = 1, number do -- We have to do that since remove_item does not work if count > stack_max
inventory:remove_item("src", ItemStack(itemname))
end
end
inventory:add_item("dst", result)
-- craft the result into the dst inventory and add any "replacements" as well
inventory:add_item("dst", output_item)
for i = 1, 9 do
inventory:add_item("dst", new.items[i])
inventory:add_item("dst", craft.decremented_input.items[i])
end
return true
end
-- returns false to stop the timer, true to continue running
-- is started only from start_autocrafter(pos) after sanity checks and cached recipe
local function run_autocrafter(pos, elapsed)
local meta = minetest.get_meta(pos)
local inventory = meta:get_inventory()
local craft = get_craft(pos, inventory)
local output_item = craft.output.item
-- only use crafts that have an actual result
if output_item:is_empty() then
meta:set_string("infotext", "unconfigured Autocrafter: unknown recipe")
return false
end
for step = 1, math.floor(elapsed/craft_time) do
local continue = autocraft(inventory, craft)
if not continue then return false end
end
return true
end
local function start_crafter(pos)
local meta = minetest.get_meta(pos)
if meta:get_int("enabled") == 1 then
local timer = minetest.get_node_timer(pos)
if not timer:is_started() then
timer:start(craft_time)
end
end
end
local function after_inventory_change(pos)
start_crafter(pos)
end
-- note, that this function assumes allready being updated to virtual items
-- and doesn't handle recipes with stacksizes > 1
local function after_recipe_change(pos, inventory)
local meta = minetest.get_meta(pos)
-- if we emptied the grid, there's no point in keeping it running or cached
if inventory:is_empty("recipe") then
minetest.get_node_timer(pos):stop()
autocrafterCache[minetest.hash_node_position(pos)] = nil
meta:set_string("infotext", "unconfigured Autocrafter")
return
end
local recipe_changed = false
local recipe = inventory:get_list("recipe")
local hash = minetest.hash_node_position(pos)
local craft = autocrafterCache[hash]
if craft then
-- check if it changed
local cached_recipe = craft.recipe
for i = 1, 9 do
if recipe[i]:get_name() ~= cached_recipe[i]:get_name() then
autocrafterCache[hash] = nil -- invalidate recipe
craft = nil
break
end
end
end
craft = craft or get_craft(pos, inventory, hash)
local output_item = craft.output.item
local description, name = get_item_info(output_item)
meta:set_string("infotext", string.format("'%s' Autocrafter (%s)", description, name))
inventory:set_stack("output", 1, output_item)
after_inventory_change(pos)
end
-- clean out unknown items and groups, which would be handled like unknown items in the crafting grid
-- if minetest supports query by group one day, this might replace them
-- with a canonical version instead
local function normalize(item_list)
for i = 1, #item_list do
local name = item_list[i]
if not minetest.registered_items[name] then
item_list[i] = ""
end
end
return item_list
end
local function on_output_change(pos, inventory, stack)
if not stack then
inventory:set_list("output", {})
inventory:set_list("recipe", {})
else
local input = minetest.get_craft_recipe(stack:get_name())
if not input.items or input.type ~= "normal" then return end
local items, width = normalize(input.items), input.width
local item_idx, width_idx = 1, 1
for i = 1, 9 do
if width_idx <= width then
inventory:set_stack("recipe", i, items[item_idx])
item_idx = item_idx + 1
else
inventory:set_stack("recipe", i, ItemStack(""))
end
width_idx = (width_idx < 3) and (width_idx + 1) or 1
end
-- we'll set the output slot in after_recipe_change to the actual result of the new recipe
end
after_recipe_change(pos, inventory)
end
-- returns false if we shouldn't bother attempting to start the timer again after this
local function update_meta(meta, enabled)
local state = enabled and "on" or "off"
meta:set_int("enabled", enabled and 1 or 0)
meta:set_string("formspec",
"size[8,11]"..
"list[context;recipe;0,0;3,3;]"..
"image[3,1;1,1;gui_hb_bg.png^[colorize:#141318:255]"..
"list[context;output;3,1;1,1;]"..
"image_button[3,2;1,1;pipeworks_button_" .. state .. ".png;" .. state .. ";;;false;pipeworks_button_interm.png]" ..
"list[context;src;0,3.5;8,3;]"..
"list[context;dst;4,0;4,3;]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
default.get_hotbar_bg(0,7) ..
"list[current_player;main;0,7;8,4;]")
-- toggling the button doesn't quite call for running a recipe change check
-- so instead we run a minimal version for infotext setting only
-- this might be more written code, but actually executes less
local output = meta:get_inventory():get_stack("output", 1)
if output:is_empty() then -- doesn't matter if paused or not
meta:set_string("infotext", "unconfigured Autocrafter")
return false
end
local description, name = get_item_info(output)
local infotext = enabled and string.format("'%s' Autocrafter (%s)", description, name)
or string.format("paused '%s' Autocrafter", description)
meta:set_string("infotext", infotext)
return enabled
end
-- 1st version of the autocrafter had actual items in the crafting grid
-- the 2nd replaced these with virtual items, dropped the content on update and set "virtual_items" to string "1"
-- the third added an output inventory, changed the formspec and added a button for enabling/disabling
-- so we work out way backwards on this history and update each single case to the newest version
local function upgrade_autocrafter(pos, meta)
local meta = meta or minetest.get_meta(pos)
local inv = meta:get_inventory()
if inv:get_size("output") == 0 then -- we are version 2 or 1
inv:set_size("output", 1)
-- migrate the old autocrafters into an "enabled" state
update_meta(meta, true)
if meta:get_string("virtual_items") == "1" then -- we are version 2
-- we allready dropped stuff, so lets remove the metadatasetting (we are not being called again for this node)
meta:set_string("virtual_items", "")
else -- we are version 1
local recipe = inv:get_list("recipe")
if not recipe then return end
for idx, stack in ipairs(recipe) do
if not stack:is_empty() then
minetest.item_drop(stack, "", pos)
stack:set_count(1)
stack:set_wear(0)
inv:set_stack("recipe", idx, stack)
end
end
end
-- update the recipe, cache, and start the crafter
autocrafterCache[minetest.hash_node_position(pos)] = nil
after_recipe_change(pos, inv)
end
end
@ -85,7 +245,9 @@ minetest.register_node("pipeworks:autocrafter", {
tube = {insert_object = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:add_item("src", stack)
local added = inv:add_item("src", stack)
after_inventory_change(pos)
return added
end,
can_insert = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
@ -96,36 +258,111 @@ minetest.register_node("pipeworks:autocrafter", {
connect_sides = {left = 1, right = 1, front = 1, back = 1, top = 1, bottom = 1}},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",
"size[8,11]"..
"list[current_name;recipe;0,0;3,3;]"..
"list[current_name;src;0,3.5;8,3;]"..
"list[current_name;dst;4,0;4,3;]"..
"list[current_player;main;0,7;8,4;]")
meta:set_string("infotext", "Autocrafter")
local inv = meta:get_inventory()
inv:set_size("src", 3*8)
inv:set_size("recipe", 3*3)
inv:set_size("dst", 4*3)
end,
can_dig = function(pos, player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return (inv:is_empty("src") and inv:is_empty("recipe") and inv:is_empty("dst"))
end,
after_place_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
inv:set_size("output", 1)
update_meta(meta, false)
end,
on_receive_fields = function(pos, formname, fields, sender)
if not pipeworks.may_configure(pos, sender) then return end
local meta = minetest.get_meta(pos)
if fields.on then
update_meta(meta, false)
minetest.get_node_timer(pos):stop()
elseif fields.off then
if update_meta(meta, true) then
start_crafter(pos)
end
end
end,
can_dig = function(pos, player)
upgrade_autocrafter(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return (inv:is_empty("src") and inv:is_empty("dst"))
end,
after_place_node = pipeworks.scan_for_tube_objects,
after_dig_node = function(pos)
pipeworks.scan_for_tube_objects(pos)
end,
on_destruct = function(pos)
autocrafterCache[minetest.hash_node_position(pos)] = nil
end
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if not pipeworks.may_configure(pos, player) then return 0 end
upgrade_autocrafter(pos)
local inv = minetest.get_meta(pos):get_inventory()
if listname == "recipe" then
stack:set_count(1)
inv:set_stack(listname, index, stack)
after_recipe_change(pos, inv)
return 0
elseif listname == "output" then
on_output_change(pos, inv, stack)
return 0
end
after_inventory_change(pos)
return stack:get_count()
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if not pipeworks.may_configure(pos, player) then
minetest.log("action", string.format("%s attempted to take from autocrafter at %s", player:get_player_name(), minetest.pos_to_string(pos)))
return 0
end
upgrade_autocrafter(pos)
local inv = minetest.get_meta(pos):get_inventory()
if listname == "recipe" then
inv:set_stack(listname, index, ItemStack(""))
after_recipe_change(pos, inv)
return 0
elseif listname == "output" then
on_output_change(pos, inv, nil)
return 0
end
after_inventory_change(pos)
return stack:get_count()
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
if not pipeworks.may_configure(pos, player) then return 0 end
upgrade_autocrafter(pos)
local inv = minetest.get_meta(pos):get_inventory()
local stack = inv:get_stack(from_list, from_index)
if to_list == "output" then
on_output_change(pos, inv, stack)
return 0
elseif from_list == "output" then
on_output_change(pos, inv, nil)
if to_list ~= "recipe" then
return 0
end -- else fall through to recipe list handling
end
if from_list == "recipe" or to_list == "recipe" then
if from_list == "recipe" then
inv:set_stack(from_list, from_index, ItemStack(""))
end
if to_list == "recipe" then
stack:set_count(1)
inv:set_stack(to_list, to_index, stack)
end
after_recipe_change(pos, inv)
return 0
end
after_inventory_change(pos)
return count
end,
on_timer = run_autocrafter
})
minetest.register_abm({nodenames = {"pipeworks:autocrafter"}, interval = 1, chance = 1,
action = function(pos, node)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
autocraft(inv, pos)
end
minetest.register_craft( {
output = "pipeworks:autocrafter 2",
recipe = {
{ "default:steel_ingot", "default:mese_crystal", "default:steel_ingot" },
{ "homedecor:plastic_sheeting", "default:steel_ingot", "homedecor:plastic_sheeting" },
{ "default:steel_ingot", "default:mese_crystal", "default:steel_ingot" }
},
})

View File

@ -9,7 +9,7 @@ local function autoroute_pipes(pos)
local nsurround = pipeworks.scan_pipe_surroundings(pos)
if nsurround == 0 then nsurround = 9 end
minetest.add_node(pos, {name = "pipeworks:pipe_"..tube_table[nsurround]..state,
minetest.swap_node(pos, {name = "pipeworks:pipe_"..tube_table[nsurround]..state,
param2 = tube_table_facedirs[nsurround]})
end

View File

@ -103,24 +103,16 @@ function pipeworks.scan_for_tube_objects(pos)
end
end
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack)
if minetest.registered_items[newnode.name]
and minetest.registered_items[newnode.name].tube
and minetest.registered_items[newnode.name].tube.connect_sides then
pipeworks.scan_for_tube_objects(pos)
end
end)
function pipeworks.after_place(pos)
pipeworks.scan_for_tube_objects(pos)
end
minetest.register_on_dignode(function(pos, oldnode, digger)
if minetest.registered_items[oldnode.name]
and minetest.registered_items[oldnode.name].tube
and minetest.registered_items[oldnode.name].tube.connect_sides then
pipeworks.scan_for_tube_objects(pos)
end
end)
function pipeworks.after_dig(pos)
pipeworks.scan_for_tube_objects(pos)
end
if minetest.get_modpath("mesecons_mvps") then
mesecon:register_on_mvps_move(function(moved_nodes)
mesecon.register_on_mvps_move(function(moved_nodes)
for _, n in ipairs(moved_nodes) do
pipeworks.scan_for_tube_objects(n.pos)
pipeworks.scan_for_tube_objects(n.oldpos)

View File

@ -126,9 +126,20 @@ end
function fs_helpers.cycling_button(meta, base, meta_name, values)
local current_value = meta:get_int(meta_name)
local new_value = (current_value + 1) % (#values)
local text = values[current_value + 1]
local val = values[current_value + 1]
local text
local texture_name = nil
local addopts = nil
--when we get a table, we know the caller wants an image_button
if type(val) == "table" then
text = val["text"]
texture_name = val["texture"]
addopts = val["addopts"]
else
text = val
end
local field = "fs_helpers_cycling:"..new_value..":"..meta_name
return base..";"..field..";"..minetest.formspec_escape(text).."]"
return base..";"..(texture_name and texture_name..";" or "")..field..";"..minetest.formspec_escape(text)..(addopts and ";"..addopts or "").."]"
end
---------

View File

@ -33,6 +33,8 @@ minetest.override_item("default:furnace", {
input_inventory = "dst",
connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1}
},
after_place_node = pipeworks.after_place,
after_dig_node = pipeworks.after_dig
})
minetest.override_item("default:furnace_active", {
@ -76,6 +78,8 @@ minetest.override_item("default:furnace_active", {
input_inventory = "dst",
connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1}
},
after_place_node = pipeworks.after_place,
after_dig_node = pipeworks.after_dig
})
minetest.override_item("default:chest", {
@ -102,6 +106,8 @@ minetest.override_item("default:chest", {
input_inventory = "main",
connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1}
},
after_place_node = pipeworks.after_place,
after_dig_node = pipeworks.after_dig
})
minetest.override_item("default:chest_locked", {
@ -116,15 +122,24 @@ minetest.override_item("default:chest_locked", {
groups = {choppy = 2, oddly_breakable_by_hand = 2, tubedevice = 1, tubedevice_receiver = 1},
tube = {
insert_object = function(pos, node, stack, direction)
local meta = minetest.env:get_meta(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:add_item("main", stack)
end,
can_insert = function(pos, node, stack, direction)
local meta = minetest.env:get_meta(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:room_for_item("main", stack)
end,
connect_sides = {left = 1, right = 1, back = 1, front = 1, bottom = 1, top = 1}
},
after_place_node = function (pos, placer)
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name() or "")
meta:set_string("infotext", "Locked Chest (owned by "..
meta:get_string("owner")..")")
pipeworks.after_place(pos)
end,
after_dig_node = pipeworks.after_dig
})

View File

@ -148,174 +148,4 @@ if minetest.get_modpath("homedecor") == nil then
})
end
minetest.register_craft( {
output = "pipeworks:one_way_tube 2",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "group:stick", "default:mese_crystal", "homedecor:plastic_sheeting" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
minetest.register_craft( {
output = "pipeworks:tube_1 6",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "", "", "" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
minetest.register_craft( {
output = "pipeworks:mese_tube_1 2",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "", "default:mese_crystal", "" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
minetest.register_craft( {
type = "shapeless",
output = "pipeworks:mese_tube_000000",
recipe = {
"pipeworks:tube_1",
"default:mese_crystal_fragment",
"default:mese_crystal_fragment",
"default:mese_crystal_fragment",
"default:mese_crystal_fragment"
},
})
minetest.register_craft( {
output = "pipeworks:conductor_tube_off_1 6",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "mesecons:mesecon", "mesecons:mesecon", "mesecons:mesecon" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
minetest.register_craft( {
output = "pipeworks:detector_tube_off_1 2",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "mesecons:mesecon", "mesecons_materials:silicon", "mesecons:mesecon" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
minetest.register_craft( {
output = "pipeworks:accelerator_tube_1 2",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "default:mese_crystal_fragment", "default:steel_ingot", "default:mese_crystal_fragment" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
minetest.register_craft( {
output = "pipeworks:teleport_tube_1 2",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "default:desert_stone", "default:mese_block", "default:desert_stone" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
minetest.register_craft( {
output = "pipeworks:sand_tube_1 2",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "default:sand", "default:sand", "default:sand" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
minetest.register_craft( {
output = "pipeworks:sand_tube_1 2",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "default:desert_sand", "default:desert_sand", "default:desert_sand" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
minetest.register_craft( {
output = "pipeworks:sand_tube_1",
recipe = {
{ "default:desert_sand", "pipeworks:tube_1", "default:desert_sand" },
},
})
minetest.register_craft( {
output = "pipeworks:mese_sand_tube_1 2",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "default:sand", "default:mese_crystal", "default:sand" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
minetest.register_craft( {
output = "pipeworks:mese_sand_tube_1 2",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "default:desert_sand", "default:mese_crystal", "default:desert_sand" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
minetest.register_craft( {
output = "pipeworks:crossing_tube_1 5",
recipe = {
{ "", "pipeworks:tube_1", "" },
{ "pipeworks:tube_1", "pipeworks:tube_1", "pipeworks:tube_1" },
{ "", "pipeworks:tube_1", "" }
},
})
minetest.register_craft( {
type = "shapeless",
output = "pipeworks:mese_sand_tube_1",
recipe = {
"pipeworks:sand_tube_1",
"default:mese_crystal_fragment",
"default:mese_crystal_fragment",
"default:mese_crystal_fragment",
"default:mese_crystal_fragment"
},
})
-- Various ancillary tube devices
minetest.register_craft( {
output = "pipeworks:filter 2",
recipe = {
{ "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" },
{ "group:stick", "default:mese_crystal", "homedecor:plastic_sheeting" },
{ "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" }
},
})
minetest.register_craft( {
output = "pipeworks:mese_filter 2",
recipe = {
{ "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" },
{ "group:stick", "default:mese", "homedecor:plastic_sheeting" },
{ "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" }
},
})
minetest.register_craft( {
output = "pipeworks:autocrafter 2",
recipe = {
{ "default:steel_ingot", "default:mese_crystal", "default:steel_ingot" },
{ "homedecor:plastic_sheeting", "default:steel_ingot", "homedecor:plastic_sheeting" },
{ "default:steel_ingot", "default:mese_crystal", "default:steel_ingot" }
},
})

View File

@ -0,0 +1,83 @@
local straight = function(pos, node, velocity, stack) return {velocity} end
minetest.register_node("pipeworks:steel_block_embedded_tube", {
description = "Airtight steelblock embedded tube",
tiles = {
"default_steel_block.png", "default_steel_block.png",
"default_steel_block.png", "default_steel_block.png",
"default_steel_block.png^pipeworks_tube_connection_metallic.png",
"default_steel_block.png^pipeworks_tube_connection_metallic.png",
},
paramtype = "light",
paramtype2 = "facedir",
groups = {cracky=1, oddly_breakable_by_hand = 1, tubedevice = 1},
legacy_facedir_simple = true,
sounds = default.node_sound_stone_defaults(),
tube = {
connect_sides = {front = 1, back = 1,},
priority = 50,
can_go = straight,
can_insert = function(pos, node, stack, direction)
local dir = minetest.facedir_to_dir(node.param2)
return vector.equals(dir, direction) or vector.equals(vector.multiply(dir, -1), direction)
end,
},
after_place_node = pipeworks.after_place,
after_dig_node = pipeworks.after_dig,
})
minetest.register_craft( {
output = "pipeworks:steel_block_embedded_tube 1",
recipe = {
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
{ "default:steel_ingot", "pipeworks:tube_1", "default:steel_ingot" },
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" }
},
})
local pane_box = {
type = "fixed",
fixed = {
{ -9/64, -9/64, -8/16, 9/64, 9/64, 8/16 }, -- tube
{ -8/16, -8/16, -1/16, 8/16, 8/16, 1/16 } -- pane
}
}
minetest.register_node("pipeworks:steel_pane_embedded_tube", {
drawtype = "nodebox",
description = "Airtight panel embedded tube ",
tiles = {
"pipeworks_pane_embedded_tube_sides.png^[transformR90",
"pipeworks_pane_embedded_tube_sides.png^[transformR90",
"pipeworks_pane_embedded_tube_sides.png",
"pipeworks_pane_embedded_tube_sides.png",
"pipeworks_pane_embedded_tube_ends.png", "pipeworks_pane_embedded_tube_ends.png",
},
node_box = pane_box,
selection_box = pane_box,
collision_box = pane_box,
paramtype = "light",
paramtype2 = "facedir",
groups = {cracky=1, oddly_breakable_by_hand = 1, tubedevice = 1},
legacy_facedir_simple = true,
sounds = default.node_sound_stone_defaults(),
tube = {
connect_sides = {front = 1, back = 1,},
priority = 50,
can_go = straight,
can_insert = function(pos, node, stack, direction)
local dir = minetest.facedir_to_dir(node.param2)
return vector.equals(dir, direction) or vector.equals(vector.multiply(dir, -1), direction)
end,
},
after_place_node = pipeworks.after_place,
after_dig_node = pipeworks.after_dig,
})
minetest.register_craft( {
output = "pipeworks:steel_pane_embedded_tube 1",
recipe = {
{ "", "default:steel_ingot", "" },
{ "", "pipeworks:tube_1", "" },
{ "", "default:steel_ingot", "" }
},
})

View File

@ -16,4 +16,5 @@ 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

View File

@ -39,7 +39,6 @@ local pipes_devicelist = {
local states = { "on", "off" }
local dgroups = ""
local pumpboxes = {}
for s in ipairs(states) do
@ -49,32 +48,13 @@ for s in ipairs(states) do
dgroups = {snappy=3, pipe=1, not_in_creative_inventory=1}
end
pumpboxes = {}
pipeworks.add_node_box(pumpboxes, pipeworks.pipe_pumpbody)
pipeworks.add_node_box(pumpboxes, pipeworks.pipe_topstub)
minetest.register_node("pipeworks:pump_"..states[s], {
description = "Pump/Intake Module",
drawtype = "nodebox",
tiles = {
"pipeworks_pump_top.png",
"pipeworks_pump_bottom.png",
"pipeworks_pump_sides.png",
"pipeworks_pump_sides.png",
"pipeworks_pump_sides.png",
"pipeworks_pump_"..states[s]..".png"
},
drawtype = "mesh",
mesh = "pipeworks_pump.obj",
tiles = { "pipeworks_pump_"..states[s]..".png" },
paramtype = "light",
paramtype2 = "facedir",
selection_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, 0.5, 0.5 }
},
node_box = {
type = "fixed",
fixed = pumpboxes
},
groups = dgroups,
sounds = default.node_sound_wood_defaults(),
walkable = true,
@ -99,29 +79,11 @@ for s in ipairs(states) do
end
})
local valveboxes = {}
pipeworks.add_node_box(valveboxes, pipeworks.pipe_leftstub)
pipeworks.add_node_box(valveboxes, pipeworks.pipe_valvebody)
if states[s] == "off" then
pipeworks.add_node_box(valveboxes, pipeworks.pipe_valvehandle_off)
else
pipeworks.add_node_box(valveboxes, pipeworks.pipe_valvehandle_on)
end
pipeworks.add_node_box(valveboxes, pipeworks.pipe_rightstub)
local tilex = "pipeworks_valvebody_ends.png"
local tilez = "pipeworks_valvebody_sides.png"
minetest.register_node("pipeworks:valve_"..states[s].."_empty", {
description = "Valve",
drawtype = "nodebox",
tiles = {
"pipeworks_valvebody_top_"..states[s]..".png",
"pipeworks_valvebody_bottom.png",
tilex,
tilex,
tilez,
tilez,
},
drawtype = "mesh",
mesh = "pipeworks_valve_"..states[s]..".obj",
tiles = { "pipeworks_valve.png" },
sunlight_propagates = true,
paramtype = "light",
paramtype2 = "facedir",
@ -129,9 +91,9 @@ for s in ipairs(states) do
type = "fixed",
fixed = { -8/16, -4/16, -5/16, 8/16, 5/16, 5/16 }
},
node_box = {
type = "fixed",
fixed = valveboxes
collision_box = {
type = "fixed",
fixed = { -8/16, -4/16, -5/16, 8/16, 5/16, 5/16 }
},
groups = dgroups,
sounds = default.node_sound_wood_defaults(),
@ -158,23 +120,11 @@ for s in ipairs(states) do
})
end
local valveboxes = {}
pipeworks.add_node_box(valveboxes, pipeworks.pipe_leftstub)
pipeworks.add_node_box(valveboxes, pipeworks.pipe_valvebody)
pipeworks.add_node_box(valveboxes, pipeworks.pipe_rightstub)
pipeworks.add_node_box(valveboxes, pipeworks.pipe_valvehandle_on)
minetest.register_node("pipeworks:valve_on_loaded", {
description = "Valve",
drawtype = "nodebox",
tiles = {
"pipeworks_valvebody_top_on.png",
"pipeworks_valvebody_bottom.png",
"pipeworks_valvebody_ends.png",
"pipeworks_valvebody_ends.png",
"pipeworks_valvebody_sides.png",
"pipeworks_valvebody_sides.png",
},
drawtype = "mesh",
mesh = "pipeworks_valve_on.obj",
tiles = { "pipeworks_valve.png" },
sunlight_propagates = true,
paramtype = "light",
paramtype2 = "facedir",
@ -182,9 +132,9 @@ minetest.register_node("pipeworks:valve_on_loaded", {
type = "fixed",
fixed = { -8/16, -4/16, -5/16, 8/16, 5/16, 5/16 }
},
node_box = {
type = "fixed",
fixed = valveboxes
collision_box = {
type = "fixed",
fixed = { -8/16, -4/16, -5/16, 8/16, 5/16, 5/16 }
},
groups = {snappy=3, pipe=1, not_in_creative_inventory=1},
sounds = default.node_sound_wood_defaults(),
@ -237,28 +187,11 @@ minetest.register_node("pipeworks:grating", {
-- outlet spigot
local spigotboxes = {}
pipeworks.add_node_box(spigotboxes, pipeworks.pipe_backstub)
pipeworks.add_node_box(spigotboxes, pipeworks.spigot_bottomstub)
pipeworks.add_node_box(spigotboxes, pipeworks.pipe_bendsphere)
local spigotboxes_pouring = {}
pipeworks.add_node_box(spigotboxes_pouring, pipeworks.spigot_stream)
pipeworks.add_node_box(spigotboxes_pouring, pipeworks.pipe_backstub)
pipeworks.add_node_box(spigotboxes_pouring, pipeworks.spigot_bottomstub)
pipeworks.add_node_box(spigotboxes_pouring, pipeworks.pipe_bendsphere)
minetest.register_node("pipeworks:spigot", {
description = "Spigot outlet",
drawtype = "nodebox",
tiles = {
"pipeworks_spigot_sides.png",
"pipeworks_pipe_end_empty.png",
"pipeworks_spigot_sides.png",
"pipeworks_spigot_sides.png",
"pipeworks_pipe_end_empty.png",
"pipeworks_spigot_sides.png"
},
drawtype = "mesh",
mesh = "pipeworks_spigot.obj",
tiles = { "pipeworks_spigot.png" },
sunlight_propagates = true,
paramtype = "light",
paramtype2 = "facedir",
@ -271,54 +204,31 @@ minetest.register_node("pipeworks:spigot", {
after_dig_node = function(pos)
pipeworks.scan_for_pipe_objects(pos)
end,
node_box = {
type = "fixed",
fixed = spigotboxes,
},
selection_box = {
type = "fixed",
fixed = { -2/16, -6/16, -2/16, 2/16, 2/16, 8/16 }
},
collision_box = {
type = "fixed",
fixed = { -2/16, -6/16, -2/16, 2/16, 2/16, 8/16 }
}
})
minetest.register_node("pipeworks:spigot_pouring", {
description = "Spigot outlet",
drawtype = "nodebox",
drawtype = "mesh",
mesh = "pipeworks_spigot_pouring.obj",
tiles = {
"pipeworks_spigot_sides.png",
"default_water.png^pipeworks_spigot_bottom2.png",
{ name = "default_water_flowing_animated.png^pipeworks_spigot_sides2.png",
{
name = "default_water_flowing_animated.png",
animation = {
type = "vertical_frames",
aspect_w=16,
aspect_h=16,
length=0.8
}
},
{ name = "default_water_flowing_animated.png^pipeworks_spigot_sides2.png",
animation = {
type = "vertical_frames",
aspect_w=16,
aspect_h=16,
length=0.8
}
},
{ name = "default_water_flowing_animated.png^pipeworks_spigot_sides2.png",
animation = {
type = "vertical_frames",
aspect_w=16,
aspect_h=16,
length=0.8
}
},
{ name = "default_water_flowing_animated.png^pipeworks_spigot_sides2.png",
animation = {
type = "vertical_frames",
aspect_w=16,
aspect_h=16,
length=0.8
}
aspect_w = 16,
aspect_h = 16,
length = 0.8,
},
},
{ name = "pipeworks_spigot.png" }
},
sunlight_propagates = true,
paramtype = "light",
@ -332,36 +242,33 @@ minetest.register_node("pipeworks:spigot_pouring", {
after_dig_node = function(pos)
pipeworks.scan_for_pipe_objects(pos)
end,
node_box = {
type = "fixed",
fixed = spigotboxes_pouring,
},
selection_box = {
type = "fixed",
fixed = { -2/16, -6/16, -2/16, 2/16, 2/16, 8/16 }
},
collision_box = {
type = "fixed",
fixed = { -2/16, -6/16, -2/16, 2/16, 2/16, 8/16 }
},
drop = "pipeworks:spigot",
})
-- sealed pipe entry/exit (horizontal pipe passing through a metal
-- wall, for use in places where walls should look like they're airtight)
local airtightboxes = {}
pipeworks.add_node_box(airtightboxes, pipeworks.pipe_frontstub)
pipeworks.add_node_box(airtightboxes, pipeworks.pipe_backstub)
pipeworks.add_node_box(airtightboxes, pipeworks.entry_panel)
local panel_cbox = {
type = "fixed",
fixed = {
{ -2/16, -2/16, -8/16, 2/16, 2/16, 8/16 },
{ -8/16, -8/16, -1/16, 8/16, 8/16, 1/16 }
}
}
minetest.register_node("pipeworks:entry_panel_empty", {
description = "Airtight Pipe entry/exit",
drawtype = "nodebox",
tiles = {
"pipeworks_plain.png",
"pipeworks_plain.png",
"pipeworks_plain.png",
"pipeworks_plain.png",
"pipeworks_pipe_end_empty.png",
"pipeworks_pipe_end_empty.png"
},
drawtype = "mesh",
mesh = "pipeworks_entry_panel.obj",
tiles = { "pipeworks_entry_panel.png" },
paramtype = "light",
paramtype2 = "facedir",
groups = {snappy=3, pipe=1},
@ -373,20 +280,12 @@ minetest.register_node("pipeworks:entry_panel_empty", {
after_dig_node = function(pos)
pipeworks.scan_for_pipe_objects(pos)
end,
node_box = {
type = "fixed",
fixed = airtightboxes,
},
selection_box = {
type = "fixed",
fixed = {
{ -2/16, -2/16, -8/16, 2/16, 2/16, 8/16 },
{ -8/16, -8/16, -1/16, 8/16, 8/16, 1/16 }
}
},
selection_box = panel_cbox,
collision_box = panel_cbox,
on_place = function(itemstack, placer, pointed_thing)
if not pipeworks.node_is_owned(pointed_thing.under, placer)
and not pipeworks.node_is_owned(pointed_thing.above, placer) then
local playername = placer:get_player_name()
if not minetest.is_protected(pointed_thing.under, playername)
and not minetest.is_protected(pointed_thing.above, playername) then
local node = minetest.get_node(pointed_thing.under)
if not minetest.registered_nodes[node.name]
@ -439,15 +338,9 @@ minetest.register_node("pipeworks:entry_panel_empty", {
minetest.register_node("pipeworks:entry_panel_loaded", {
description = "Airtight Pipe entry/exit",
drawtype = "nodebox",
tiles = {
"pipeworks_plain.png",
"pipeworks_plain.png",
"pipeworks_plain.png",
"pipeworks_plain.png",
"pipeworks_pipe_end_empty.png",
"pipeworks_pipe_end_empty.png"
},
drawtype = "mesh",
mesh = "pipeworks_entry_panel.obj",
tiles = { "pipeworks_entry_panel.png" },
paramtype = "light",
paramtype2 = "facedir",
groups = {snappy=3, pipe=1, not_in_creative_inventory=1},
@ -459,36 +352,16 @@ minetest.register_node("pipeworks:entry_panel_loaded", {
after_dig_node = function(pos)
pipeworks.scan_for_pipe_objects(pos)
end,
node_box = {
type = "fixed",
fixed = airtightboxes,
},
selection_box = {
type = "fixed",
fixed = {
{ -2/16, -2/16, -8/16, 2/16, 2/16, 8/16 },
{ -8/16, -8/16, -1/16, 8/16, 8/16, 1/16 }
}
},
selection_box = panel_cbox,
collision_box = panel_cbox,
drop = "pipeworks:entry_panel_empty"
})
local sensorboxes = {}
pipeworks.add_node_box(sensorboxes, pipeworks.pipe_leftstub)
pipeworks.add_node_box(sensorboxes, pipeworks.pipe_sensorbody)
pipeworks.add_node_box(sensorboxes, pipeworks.pipe_rightstub)
minetest.register_node("pipeworks:flow_sensor_empty", {
description = "Flow Sensor",
drawtype = "nodebox",
tiles = {
"pipeworks_plain.png",
"pipeworks_plain.png",
"pipeworks_plain.png",
"pipeworks_plain.png",
"pipeworks_windowed_empty.png",
"pipeworks_windowed_empty.png"
},
drawtype = "mesh",
mesh = "pipeworks_flow_sensor.obj",
tiles = { "pipeworks_flow_sensor_off.png" },
sunlight_propagates = true,
paramtype = "light",
paramtype2 = "facedir",
@ -503,17 +376,21 @@ minetest.register_node("pipeworks:flow_sensor_empty", {
end,
on_construct = function(pos)
if mesecon then
mesecon:receptor_off(pos, rules)
mesecon.receptor_off(pos, rules)
end
end,
node_box = {
type = "fixed",
fixed = sensorboxes,
},
selection_box = {
type = "fixed",
fixed = {
{ -8/16, -2/16, -2/16, 8/16, 2/16, 2/16 },
{ -4/16, -3/16, -3/16, 4/16, 3/16, 3/16 },
}
},
collision_box = {
type = "fixed",
fixed = {
{ -8/16, -2/16, -2/16, 8/16, 2/16, 2/16 },
{ -4/16, -3/16, -3/16, 4/16, 3/16, 3/16 },
}
},
mesecons = pipereceptor_off
@ -521,15 +398,9 @@ minetest.register_node("pipeworks:flow_sensor_empty", {
minetest.register_node("pipeworks:flow_sensor_loaded", {
description = "Flow sensor (on)",
drawtype = "nodebox",
tiles = {
"pipeworks_plain.png",
"pipeworks_plain.png",
"pipeworks_plain.png",
"pipeworks_plain.png",
"pipeworks_sensor_sides_on.png",
"pipeworks_sensor_sides_on.png"
},
drawtype = "mesh",
mesh = "pipeworks_flow_sensor.obj",
tiles = { "pipeworks_flow_sensor_on.png" },
sunlight_propagates = true,
paramtype = "light",
paramtype2 = "facedir",
@ -544,17 +415,21 @@ minetest.register_node("pipeworks:flow_sensor_loaded", {
end,
on_construct = function(pos)
if mesecon then
mesecon:receptor_on(pos, rules)
mesecon.receptor_on(pos, rules)
end
end,
node_box = {
type = "fixed",
fixed = sensorboxes,
},
selection_box = {
type = "fixed",
fixed = {
{ -8/16, -2/16, -2/16, 8/16, 2/16, 2/16 },
{ -4/16, -3/16, -3/16, 4/16, 3/16, 3/16 },
}
},
collision_box = {
type = "fixed",
fixed = {
{ -8/16, -2/16, -2/16, 8/16, 2/16, 2/16 },
{ -4/16, -3/16, -3/16, 4/16, 3/16, 3/16 },
}
},
drop = "pipeworks:flow_sensor_empty",
@ -631,12 +506,9 @@ end
minetest.register_node("pipeworks:fountainhead", {
description = "Fountainhead",
drawtype = "nodebox",
tiles = {
"pipeworks_fountainhead_top.png",
"pipeworks_pipe_end.png",
"pipeworks_plain.png",
},
drawtype = "mesh",
mesh = "pipeworks_fountainhead.obj",
tiles = { "pipeworks_fountainhead.png" },
sunlight_propagates = true,
paramtype = "light",
groups = {snappy=3, pipe=1},
@ -650,27 +522,24 @@ minetest.register_node("pipeworks:fountainhead", {
end,
on_construct = function(pos)
if mesecon then
mesecon:receptor_on(pos, rules)
mesecon.receptor_on(pos, rules)
end
end,
node_box = {
type = "fixed",
fixed = pipeworks.fountainhead_model ,
},
selection_box = {
type = "fixed",
fixed = { -2/16, -8/16, -2/16, 2/16, 8/16, 2/16 }
},
collision_box = {
type = "fixed",
fixed = { -2/16, -8/16, -2/16, 2/16, 8/16, 2/16 }
},
})
minetest.register_node("pipeworks:fountainhead_pouring", {
description = "Fountainhead",
drawtype = "nodebox",
tiles = {
"pipeworks_fountainhead_top.png",
"pipeworks_pipe_end.png",
"pipeworks_plain.png",
},
drawtype = "mesh",
mesh = "pipeworks_fountainhead.obj",
tiles = { "pipeworks_fountainhead.png" },
sunlight_propagates = true,
paramtype = "light",
groups = {snappy=3, pipe=1, not_in_creative_inventory=1},
@ -684,19 +553,20 @@ minetest.register_node("pipeworks:fountainhead_pouring", {
end,
on_construct = function(pos)
if mesecon then
mesecon:receptor_on(pos, rules)
mesecon.receptor_on(pos, rules)
end
end,
node_box = {
type = "fixed",
fixed = pipeworks.fountainhead_model,
},
selection_box = {
type = "fixed",
fixed = { -2/16, -8/16, -2/16, 2/16, 8/16, 2/16 },
fixed = { -2/16, -8/16, -2/16, 2/16, 8/16, 2/16 }
},
collision_box = {
type = "fixed",
fixed = { -2/16, -8/16, -2/16, 2/16, 8/16, 2/16 }
},
drop = "pipeworks:fountainhead"
})
minetest.register_alias("pipeworks:valve_off_loaded", "pipeworks:valve_off_empty")
minetest.register_alias("pipeworks:entry_panel", "pipeworks:entry_panel_empty")

View File

@ -0,0 +1,238 @@
local function delay(x)
return (function() return x end)
end
local function set_filter_infotext(data, meta)
local infotext = data.wise_desc.." Filter-Injector"
if meta:get_int("slotseq_mode") == 2 then
infotext = infotext .. " (slot #"..meta:get_int("slotseq_index").." next)"
end
meta:set_string("infotext", infotext)
end
local function set_filter_formspec(data, meta)
local itemname = data.wise_desc.." Filter-Injector"
local formspec = "size[8,8.5]"..
"item_image[0,0;1,1;pipeworks:"..data.name.."]"..
"label[1,0;"..minetest.formspec_escape(itemname).."]"..
"label[0,1;Prefer item types:]"..
"list[context;main;0,1.5;8,2;]"..
fs_helpers.cycling_button(meta, "button[0,3.5;4,1", "slotseq_mode",
{"Sequence slots by Priority",
"Sequence slots Randomly",
"Sequence slots by Rotation"})..
"list[current_player;main;0,4.5;8,4;]"
meta:set_string("formspec", formspec)
end
-- todo SOON: this function has *way too many* parameters
local function grabAndFire(data,slotseq_mode,filtmeta,frominv,frominvname,frompos,fromnode,filterfor,fromtube,fromdef,dir,fakePlayer,all)
local sposes = {}
for spos,stack in ipairs(frominv:get_list(frominvname)) do
local matches
if filterfor == "" then
matches = stack:get_name() ~= ""
else
matches = stack:get_name() == filterfor.name
end
if matches then table.insert(sposes, spos) end
end
if #sposes == 0 then return false end
if slotseq_mode == 1 then
for i = #sposes, 2, -1 do
local j = math.random(i)
local t = sposes[j]
sposes[j] = sposes[i]
sposes[i] = t
end
elseif slotseq_mode == 2 then
local headpos = filtmeta:get_int("slotseq_index")
table.sort(sposes, function (a, b)
if a >= headpos then
if b < headpos then return true end
else
if b >= headpos then return false end
end
return a < b
end)
end
for _, spos in ipairs(sposes) do
local stack = frominv:get_stack(frominvname, spos)
local doRemove = stack:get_count()
if fromtube.can_remove then
doRemove = fromtube.can_remove(frompos, fromnode, stack, dir)
elseif fromdef.allow_metadata_inventory_take then
doRemove = fromdef.allow_metadata_inventory_take(frompos, frominvname,spos, stack, fakePlayer)
end
-- stupid lack of continue statements grumble
if doRemove > 0 then
if slotseq_mode == 2 then
local nextpos = spos + 1
if nextpos > frominv:get_size(frominvname) then
nextpos = 1
end
filtmeta:set_int("slotseq_index", nextpos)
set_filter_infotext(data, filtmeta)
end
local item
local count
if all then
count = math.min(stack:get_count(), doRemove)
if filterfor.count and filterfor.count > 1 then
count = math.min(filterfor.count, count)
end
else
count = 1
end
if fromtube.remove_items then
-- it could be the entire stack...
item = fromtube.remove_items(frompos, fromnode, stack, dir, count)
else
item = stack:take_item(count)
frominv:set_stack(frominvname, spos, stack)
if fromdef.on_metadata_inventory_take then
fromdef.on_metadata_inventory_take(frompos, frominvname, spos, item, fakePlayer)
end
end
local pos = vector.add(frompos, vector.multiply(dir, 1.4))
local start_pos = vector.add(frompos, dir)
local item1 = pipeworks.tube_inject_item(pos, start_pos, dir, item)
return true-- only fire one item, please
end
end
return false
end
local function punch_filter(data, filtpos, filtnode)
local filtmeta = minetest.get_meta(filtpos)
local filtinv = filtmeta:get_inventory()
local owner = filtmeta:get_string("owner")
local fakePlayer = {
get_player_name = delay(owner),
} -- TODO: use a mechanism as the wielder one
local dir = minetest.facedir_to_right_dir(filtnode.param2)
local frompos = vector.subtract(filtpos, dir)
local fromnode = minetest.get_node(frompos)
if not fromnode then return end
local fromdef = minetest.registered_nodes[fromnode.name]
if not fromdef then return end
local fromtube = fromdef.tube
if not (fromtube and fromtube.input_inventory) then return end
local filters = {}
for _, filterstack in ipairs(filtinv:get_list("main")) do
local filtername = filterstack:get_name()
local filtercount = filterstack:get_count()
if filtername ~= "" then table.insert(filters, {name = filtername, count = filtercount}) end
end
if #filters == 0 then table.insert(filters, "") end
local slotseq_mode = filtmeta:get_int("slotseq_mode")
local frommeta = minetest.get_meta(frompos)
local frominv = frommeta:get_inventory()
if fromtube.before_filter then fromtube.before_filter(frompos) end
for _, frominvname in ipairs(type(fromtube.input_inventory) == "table" and fromtube.input_inventory or {fromtube.input_inventory}) do
local done = false
for _, filterfor in ipairs(filters) do
if grabAndFire(data, slotseq_mode, filtmeta, frominv, frominvname, frompos, fromnode, filterfor, fromtube, fromdef, dir, fakePlayer, data.stackwise) then
done = true
break
end
end
if done then break end
end
if fromtube.after_filter then fromtube.after_filter(frompos) end
end
for _, data in ipairs({
{
name = "filter",
wise_desc = "Itemwise",
stackwise = false,
},
{
name = "mese_filter",
wise_desc = "Stackwise",
stackwise = true,
},
}) do
minetest.register_node("pipeworks:"..data.name, {
description = data.wise_desc.." Filter-Injector",
tiles = {
"pipeworks_"..data.name.."_top.png",
"pipeworks_"..data.name.."_top.png",
"pipeworks_"..data.name.."_output.png",
"pipeworks_"..data.name.."_input.png",
"pipeworks_"..data.name.."_side.png",
"pipeworks_"..data.name.."_top.png",
},
paramtype2 = "facedir",
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, mesecon = 2},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
set_filter_formspec(data, meta)
set_filter_infotext(data, meta)
local inv = meta:get_inventory()
inv:set_size("main", 8*2)
end,
after_place_node = function (pos, placer)
minetest.get_meta(pos):set_string("owner", placer:get_player_name())
pipeworks.after_place(pos)
end,
after_dig_node = pipeworks.after_dig,
on_receive_fields = function(pos, formname, fields, sender)
if not pipeworks.may_configure(pos, sender) then return end
fs_helpers.on_receive_fields(pos, fields)
local meta = minetest.get_meta(pos)
meta:set_int("slotseq_index", 1)
set_filter_formspec(data, meta)
set_filter_infotext(data, meta)
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if not pipeworks.may_configure(pos, player) then return 0 end
return stack:get_count()
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if not pipeworks.may_configure(pos, player) then return 0 end
return stack:get_count()
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
if not pipeworks.may_configure(pos, player) then return 0 end
return count
end,
can_dig = function(pos, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
mesecons = {
effector = {
action_on = function(pos, node)
punch_filter(data, pos, node)
end,
},
},
tube = {connect_sides = {right = 1}},
on_punch = function (pos, node, puncher)
punch_filter(data, pos, node)
end,
})
end
minetest.register_craft( {
output = "pipeworks:filter 2",
recipe = {
{ "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" },
{ "group:stick", "default:mese_crystal", "homedecor:plastic_sheeting" },
{ "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" }
},
})
minetest.register_craft( {
output = "pipeworks:mese_filter 2",
recipe = {
{ "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" },
{ "group:stick", "default:mese", "homedecor:plastic_sheeting" },
{ "default:steel_ingot", "default:steel_ingot", "homedecor:plastic_sheeting" }
},
})

View File

@ -51,42 +51,21 @@ function pipeworks.fix_image_names(table, replacement)
end
function pipeworks.add_node_box(t, b)
if not t or not b then return end
for i in ipairs(b)
do table.insert(t, b[i])
end
end
function pipeworks.node_is_owned(pos, placer)
local ownername = false
if type(IsPlayerNodeOwner) == "function" then -- node_ownership mod
if HasOwner(pos, placer) then -- returns true if the node is owned
if not IsPlayerNodeOwner(pos, placer:get_player_name()) then
if type(getLastOwner) == "function" then -- ...is an old version
ownername = getLastOwner(pos)
elseif type(GetNodeOwnerName) == "function" then -- ...is a recent version
ownername = GetNodeOwnerName(pos)
else
ownername = S("someone")
end
end
end
function pipeworks.may_configure(pos, player)
local name = player:get_player_name()
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
elseif type(isprotect)=="function" then -- glomie's protection mod
if not isprotect(5, pos, placer) then
ownername = S("someone")
end
elseif type(protector)=="table" and type(protector.can_dig)=="function" then -- Zeg9's protection mod
if not protector.can_dig(5, pos, placer) then
ownername = S("someone")
end
end
if ownername ~= false then
minetest.chat_send_player( placer:get_player_name(), S("Sorry, %s owns that spot."):format(ownername) )
return true
else
return false
if owner ~= "" then -- wielders and filters
return owner == name
end
return not minetest.is_protected(pos, name)
end
function pipeworks.replace_name(tbl,tr,name)
@ -114,7 +93,13 @@ dofile(pipeworks.modpath.."/luaentity.lua")
dofile(pipeworks.modpath.."/item_transport.lua")
dofile(pipeworks.modpath.."/flowing_logic.lua")
dofile(pipeworks.modpath.."/crafts.lua")
dofile(pipeworks.modpath.."/tubes.lua")
dofile(pipeworks.modpath.."/tube_registration.lua")
dofile(pipeworks.modpath.."/routing_tubes.lua")
dofile(pipeworks.modpath.."/sorting_tubes.lua")
dofile(pipeworks.modpath.."/vacuum_tubes.lua")
dofile(pipeworks.modpath.."/signal_tubes.lua")
dofile(pipeworks.modpath.."/decorative_tubes.lua")
dofile(pipeworks.modpath.."/filter-injector.lua")
dofile(pipeworks.modpath.."/trashcan.lua")
dofile(pipeworks.modpath.."/wielder.lua")

View File

@ -1,9 +1,3 @@
local fakePlayer = {
get_player_name = function() return ":pipeworks" end,
-- any other player functions called by allow_metadata_inventory_take anywhere...
-- perhaps a custom metaclass that errors specially when fakePlayer.<property> is not found?
}
function pipeworks.tube_item(pos, item)
error("obsolete pipeworks.tube_item() called; change caller to use pipeworks.tube_inject_item() instead")
end
@ -25,197 +19,6 @@ end
-- both optional w/ sensible defaults and fallback to normal allow_* function
-- XXX: possibly change insert_object to insert_item
local function set_filter_infotext(data, meta)
local infotext = data.wise_desc.." Filter-Injector"
if meta:get_int("slotseq_mode") == 2 then
infotext = infotext .. " (slot #"..meta:get_int("slotseq_index").." next)"
end
meta:set_string("infotext", infotext)
end
local function set_filter_formspec(data, meta)
local itemname = data.wise_desc.." Filter-Injector"
local formspec = "size[8,8.5]"..
"item_image[0,0;1,1;pipeworks:"..data.name.."]"..
"label[1,0;"..minetest.formspec_escape(itemname).."]"..
"label[0,1;Prefer item types:]"..
"list[current_name;main;0,1.5;8,2;]"..
fs_helpers.cycling_button(meta, "button[0,3.5;4,1", "slotseq_mode",
{"Sequence slots by Priority",
"Sequence slots Randomly",
"Sequence slots by Rotation"})..
"list[current_player;main;0,4.5;8,4;]"
meta:set_string("formspec", formspec)
end
-- todo SOON: this function has *way too many* parameters
local function grabAndFire(data,slotseq_mode,filtmeta,frominv,frominvname,frompos,fromnode,filtername,fromtube,fromdef,dir,all)
local sposes = {}
for spos,stack in ipairs(frominv:get_list(frominvname)) do
local matches
if filtername == "" then
matches = stack:get_name() ~= ""
else
matches = stack:get_name() == filtername
end
if matches then table.insert(sposes, spos) end
end
if #sposes == 0 then return false end
if slotseq_mode == 1 then
for i = #sposes, 2, -1 do
local j = math.random(i)
local t = sposes[j]
sposes[j] = sposes[i]
sposes[i] = t
end
elseif slotseq_mode == 2 then
local headpos = filtmeta:get_int("slotseq_index")
table.sort(sposes, function (a, b)
if a >= headpos then
if b < headpos then return true end
else
if b >= headpos then return false end
end
return a < b
end)
end
for _, spos in ipairs(sposes) do
local stack = frominv:get_stack(frominvname, spos)
local doRemove = stack:get_count()
if fromtube.can_remove then
doRemove = fromtube.can_remove(frompos, fromnode, stack, dir)
elseif fromdef.allow_metadata_inventory_take then
doRemove = fromdef.allow_metadata_inventory_take(frompos, frominvname,spos, stack, fakePlayer)
end
-- stupid lack of continue statements grumble
if doRemove > 0 then
if slotseq_mode == 2 then
local nextpos = spos + 1
if nextpos > frominv:get_size(frominvname) then
nextpos = 1
end
filtmeta:set_int("slotseq_index", nextpos)
set_filter_infotext(data, filtmeta)
end
local item
local count
if all then
count = math.min(stack:get_count(), doRemove)
else
count = 1
end
if fromtube.remove_items then
-- it could be the entire stack...
item = fromtube.remove_items(frompos, fromnode, stack, dir, count)
else
item = stack:take_item(count)
frominv:set_stack(frominvname, spos, stack)
if fromdef.on_metadata_inventory_take then
fromdef.on_metadata_inventory_take(frompos, frominvname, spos, item, fakePlayer)
end
end
local pos = vector.add(frompos, vector.multiply(dir, 1.4))
local start_pos = vector.add(frompos, dir)
local item1 = pipeworks.tube_inject_item(pos, start_pos, dir, item)
return true-- only fire one item, please
end
end
return false
end
local function punch_filter(data, filtpos, filtnode)
local filtmeta = minetest.get_meta(filtpos)
local filtinv = filtmeta:get_inventory()
local dir = minetest.facedir_to_right_dir(filtnode.param2)
local frompos = vector.subtract(filtpos, dir)
local fromnode = minetest.get_node(frompos)
if not fromnode then return end
local fromdef = minetest.registered_nodes[fromnode.name]
if not fromdef then return end
local fromtube = fromdef.tube
if not (fromtube and fromtube.input_inventory) then return end
local filters = {}
for _, filterstack in ipairs(filtinv:get_list("main")) do
local filtername = filterstack:get_name()
if filtername ~= "" then table.insert(filters, filtername) end
end
if #filters == 0 then table.insert(filters, "") end
local slotseq_mode = filtmeta:get_int("slotseq_mode")
local frommeta = minetest.get_meta(frompos)
local frominv = frommeta:get_inventory()
if fromtube.before_filter then fromtube.before_filter(frompos) end
for _, frominvname in ipairs(type(fromtube.input_inventory) == "table" and fromtube.input_inventory or {fromtube.input_inventory}) do
local done = false
for _, filtername in ipairs(filters) do
if grabAndFire(data, slotseq_mode, filtmeta, frominv, frominvname, frompos, fromnode, filtername, fromtube, fromdef, dir, data.stackwise) then
done = true
break
end
end
if done then break end
end
if fromtube.after_filter then fromtube.after_filter(frompos) end
end
for _, data in ipairs({
{
name = "filter",
wise_desc = "Itemwise",
stackwise = false,
},
{
name = "mese_filter",
wise_desc = "Stackwise",
stackwise = true,
},
}) do
minetest.register_node("pipeworks:"..data.name, {
description = data.wise_desc.." Filter-Injector",
tiles = {
"pipeworks_"..data.name.."_top.png",
"pipeworks_"..data.name.."_top.png",
"pipeworks_"..data.name.."_output.png",
"pipeworks_"..data.name.."_input.png",
"pipeworks_"..data.name.."_side.png",
"pipeworks_"..data.name.."_top.png",
},
paramtype2 = "facedir",
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, mesecon = 2},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
set_filter_formspec(data, meta)
set_filter_infotext(data, meta)
local inv = meta:get_inventory()
inv:set_size("main", 8*2)
end,
on_receive_fields = function(pos, formname, fields, sender)
fs_helpers.on_receive_fields(pos, fields)
local meta = minetest.get_meta(pos)
meta:set_int("slotseq_index", 1)
set_filter_formspec(data, meta)
set_filter_infotext(data, meta)
end,
can_dig = function(pos, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
mesecons = {
effector = {
action_on = function(pos, node)
punch_filter(data, pos, node)
end,
},
},
tube = {connect_sides = {right = 1}},
on_punch = function (pos, node, puncher)
punch_filter(data, pos, node)
end,
})
end
local adjlist={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=0,y=1,z=0},{x=0,y=-1,z=0},{x=1,y=0,z=0},{x=-1,y=0,z=0}}
function pipeworks.notvel(tbl, vel)
@ -460,9 +263,9 @@ luaentity.register_entity("pipeworks:tubed_item", {
})
if minetest.get_modpath("mesecons_mvps") then
mesecon:register_mvps_unmov("pipeworks:tubed_item")
mesecon:register_mvps_unmov("pipeworks:color_entity")
mesecon:register_on_mvps_move(function(moved_nodes)
mesecon.register_mvps_unmov("pipeworks:tubed_item")
mesecon.register_mvps_unmov("pipeworks:color_entity")
mesecon.register_on_mvps_move(function(moved_nodes)
local moved = {}
for _, n in ipairs(moved_nodes) do
moved[minetest.hash_node_position(n.oldpos)] = vector.subtract(n.pos, n.oldpos)

View File

@ -26,7 +26,6 @@ if not minetest.get_modpath("auto_tree_tap") and
is_ground_content = true,
paramtype2 = "facedir",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1, not_in_creative_inventory=1 },
mesecons= {effector={rules=pipeworks.rules_all,action_on=node_breaker_on, action_off=node_breaker_off}},
sounds = default.node_sound_stone_defaults(),
tube = {connect_sides={back=1}},
on_construct = function(pos)

View File

@ -1,87 +1,5 @@
---------------------
-- The various models
-- Pipe models
pipeworks.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 }
}
pipeworks.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 }
}
pipeworks.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 }
}
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 }
}
pipeworks.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 }
}
pipeworks.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 },
{ -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 }
}
pipeworks.pipe_boxes = {pipeworks.pipe_leftstub, pipeworks.pipe_rightstub, pipeworks.pipe_bottomstub, pipeworks.pipe_topstub, pipeworks.pipe_frontstub, pipeworks.pipe_backstub}
-----------------------------------
-- The various pipe select boxes
pipeworks.pipe_selectboxes = {
{ -32/64, -8/64, -8/64, 8/64, 8/64, 8/64 },
@ -92,13 +10,6 @@ pipeworks.pipe_selectboxes = {
{ -8/64 , -8/64, -8/64, 8/64, 8/64, 32/64 }
}
pipeworks.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 }
}
-- Tube models
pipeworks.tube_leftstub = {
@ -136,67 +47,3 @@ pipeworks.tube_selectboxes = {
{ -10/64 , -10/64, -10/64, 10/64, 10/64, 32/64 }
}
-- Device models
pipeworks.pipe_pumpbody = {
{ -7/16, -6/16, -7/16, 7/16, 5/16, 7/16 },
{ -8/16, -8/16, -8/16, 8/16, -6/16, 8/16 }
}
pipeworks.pipe_valvebody = {
{ -4/16, -4/16, -4/16, 4/16, 4/16, 4/16 }
}
pipeworks.pipe_valvehandle_on = {
{ -5/16, 4/16, -1/16, 0, 5/16, 1/16 }
}
pipeworks.pipe_valvehandle_off = {
{ -1/16, 4/16, -5/16, 1/16, 5/16, 0 }
}
pipeworks.pipe_sensorbody = {
{ -3/16, -2/16, -2/16, 3/16, 2/16, 2/16 }
}
pipeworks.spigot_bottomstub = {
{ -2/64, -16/64, -6/64, 2/64, 1/64, 6/64 }, -- pipe segment against -Y face
{ -4/64, -16/64, -5/64, 4/64, 1/64, 5/64 },
{ -5/64, -16/64, -4/64, 5/64, 1/64, 4/64 },
{ -6/64, -16/64, -2/64, 6/64, 1/64, 2/64 },
{ -3/64, -16/64, -8/64, 3/64, -14/64, 8/64 }, -- (the flange for it)
{ -5/64, -16/64, -7/64, 5/64, -14/64, 7/64 },
{ -6/64, -16/64, -6/64, 6/64, -14/64, 6/64 },
{ -7/64, -16/64, -5/64, 7/64, -14/64, 5/64 },
{ -8/64, -16/64, -3/64, 8/64, -14/64, 3/64 }
}
pipeworks.spigot_stream = {
{ -3/64, (-41/64)-0.01, -5/64, 3/64, -16/64, 5/64 },
{ -4/64, (-41/64)-0.01, -4/64, 4/64, -16/64, 4/64 },
{ -5/64, (-41/64)-0.01, -3/64, 5/64, -16/64, 3/64 }
}
pipeworks.entry_panel = {
{ -8/16, -8/16, -1/16, 8/16, 8/16, 1/16 }
}
pipeworks.fountainhead_model = {
{ -2/64, -32/64, -6/64, 2/64, 21/64, 6/64 }, -- main segment
{ -4/64, -32/64, -5/64, 4/64, 21/64, 5/64 },
{ -5/64, -32/64, -4/64, 5/64, 21/64, 4/64 },
{ -6/64, -32/64, -2/64, 6/64, 21/64, 2/64 },
{ -3/64, -32/64, -8/64, 3/64, -30/64, 8/64 }, -- bottom flange
{ -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 },
{ -3/64, 20/64, -8/64, 3/64, 32/64, 8/64 }, -- top flange/outlet
{ -5/64, 20/64, -7/64, 5/64, 32/64, 7/64 },
{ -6/64, 20/64, -6/64, 6/64, 32/64, 6/64 },
{ -7/64, 20/64, -5/64, 7/64, 32/64, 5/64 },
{ -8/64, 20/64, -3/64, 8/64, 32/64, 3/64 }
}

View File

@ -8,13 +8,7 @@ local pipes_full_nodenames = {}
local vti = {4, 3, 2, 1, 6, 5}
local cconnects = {{}, {1}, {1, 2}, {1, 3}, {1, 3, 5}, {1, 2, 3}, {1, 2, 3, 5}, {1, 2, 3, 4}, {1, 2, 3, 4, 5}, {1, 2, 3, 4, 5, 6}}
for index, connects in ipairs(cconnects) do
local outboxes = {}
local outsel = {}
local outimgs = {}
for i = 1, 6 do
outimgs[vti[i]] = "pipeworks_plain.png"
end
local jx = 0
local jy = 0
@ -27,24 +21,12 @@ for index, connects in ipairs(cconnects) do
else
jz = jz + 1
end
pipeworks.add_node_box(outboxes, pipeworks.pipe_boxes[v])
table.insert(outsel, pipeworks.pipe_selectboxes[v])
outimgs[vti[v]] = "pipeworks_pipe_end.png"
end
if #connects == 1 then
local v = connects[1]
v = v-1 + 2*(v%2) -- Opposite side
outimgs[vti[v]] = "^pipeworks_plain.png"
end
if #connects >= 2 then
pipeworks.add_node_box(outboxes, pipeworks.pipe_bendsphere)
end
if jx == 2 and jy ~= 2 and jz ~= 2 then
outimgs[5] = pipeworks.liquid_texture.."^pipeworks_windowed_XXXXX.png"
outimgs[6] = outimgs[5]
end
local pgroups = {snappy = 3, pipe = 1, not_in_creative_inventory = 1}
@ -57,24 +39,37 @@ for index, connects in ipairs(cconnects) do
image = "pipeworks_pipe_inv.png"
end
--table.insert(pipeworks.tubenodes, name.."_"..tname)
local outimg_e = { "pipeworks_pipe_plain.png" }
local outimg_l = { "pipeworks_pipe_plain.png" }
if index == 3 then
outimg_e = { "pipeworks_pipe_3_empty.png" }
outimg_l = { "pipeworks_pipe_3_loaded.png" }
end
local mesh = "pipeworks_pipe_"..index..".obj"
if index == 1 then
mesh = "pipeworks_pipe_3.obj"
end
minetest.register_node("pipeworks:pipe_"..index.."_empty", {
description = pipedesc,
drawtype = "nodebox",
tiles = pipeworks.fix_image_names(outimgs, "_empty"),
drawtype = "mesh",
mesh = mesh,
tiles = outimg_e,
sunlight_propagates = true,
inventory_image = image,
wield_image = image,
paramtype = "light",
paramtype2 = "facedir",
selection_box = {
type = "fixed",
type = "fixed",
fixed = outsel
},
node_box = {
collision_box = {
type = "fixed",
fixed = outboxes
fixed = outsel
},
groups = pgroups,
sounds = default.node_sound_wood_defaults(),
@ -92,18 +87,19 @@ for index, connects in ipairs(cconnects) do
minetest.register_node("pipeworks:pipe_"..index.."_loaded", {
description = pipedesc,
drawtype = "nodebox",
tiles = pipeworks.fix_image_names(outimgs, "_loaded"),
drawtype = "mesh",
mesh = mesh,
tiles = outimg_l,
sunlight_propagates = true,
paramtype = "light",
paramtype2 = "facedir",
selection_box = {
type = "fixed",
type = "fixed",
fixed = outsel
},
node_box = {
collision_box = {
type = "fixed",
fixed = outboxes
fixed = outsel
},
groups = pgroups,
sounds = default.node_sound_wood_defaults(),

View File

@ -0,0 +1,119 @@
-- the default tube and default textures
pipeworks.register_tube("pipeworks:tube", "Pneumatic tube segment")
minetest.register_craft( {
output = "pipeworks:tube_1 6",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "", "", "" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
-- the high priority tube is a low-cpu replacement for sorting tubes in situations
-- where players would use them for simple routing (turning off paths)
-- without doing actual sorting, like at outputs of tubedevices that might both accept and eject items
if pipeworks.enable_priority_tube then
local color = "#ff3030:128"
pipeworks.register_tube("pipeworks:priority_tube", {
description = "High Priority Tube Segment",
inventory_image = "pipeworks_tube_inv.png^[colorize:" .. color,
plain = { "pipeworks_tube_plain.png^[colorize:" .. color },
noctr = { "pipeworks_tube_noctr.png^[colorize:" .. color },
ends = { "pipeworks_tube_end.png^[colorize:" .. color },
short = "pipeworks_tube_short.png^[colorize:" .. color,
node_def = {
tube = { priority = 150 } -- higher than tubedevices (100)
},
})
minetest.register_craft( {
output = "pipeworks:priority_tube_1 6",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "default:gold_ingot", "", "default:gold_ingot" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
end
if pipeworks.enable_accelerator_tube then
pipeworks.register_tube("pipeworks:accelerator_tube", {
description = "Accelerating Pneumatic Tube Segment",
inventory_image = "pipeworks_accelerator_tube_inv.png",
plain = { "pipeworks_accelerator_tube_plain.png" },
noctr = { "pipeworks_accelerator_tube_noctr.png" },
ends = { "pipeworks_accelerator_tube_end.png" },
short = "pipeworks_accelerator_tube_short.png",
node_def = {
tube = {can_go = function(pos, node, velocity, stack)
velocity.speed = velocity.speed+1
return pipeworks.notvel(pipeworks.meseadjlist, velocity)
end}
},
})
minetest.register_craft( {
output = "pipeworks:accelerator_tube_1 2",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "default:mese_crystal_fragment", "default:steel_ingot", "default:mese_crystal_fragment" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
end
if pipeworks.enable_crossing_tube then
pipeworks.register_tube("pipeworks:crossing_tube", {
description = "Crossing Pneumatic Tube Segment",
inventory_image = "pipeworks_crossing_tube_inv.png",
plain = { "pipeworks_crossing_tube_plain.png" },
noctr = { "pipeworks_crossing_tube_noctr.png" },
ends = { "pipeworks_crossing_tube_end.png" },
short = "pipeworks_crossing_tube_short.png",
node_def = {
tube = {can_go = function(pos, node, velocity, stack) return {velocity} end }
},
})
minetest.register_craft( {
output = "pipeworks:crossing_tube_1 5",
recipe = {
{ "", "pipeworks:tube_1", "" },
{ "pipeworks:tube_1", "pipeworks:tube_1", "pipeworks:tube_1" },
{ "", "pipeworks:tube_1", "" }
},
})
end
if pipeworks.enable_one_way_tube then
minetest.register_node("pipeworks:one_way_tube", {
description = "One way tube",
tiles = {"pipeworks_one_way_tube_top.png", "pipeworks_one_way_tube_top.png", "pipeworks_one_way_tube_output.png",
"pipeworks_one_way_tube_input.png", "pipeworks_one_way_tube_side.png", "pipeworks_one_way_tube_top.png"},
paramtype2 = "facedir",
drawtype = "nodebox",
paramtype = "light",
node_box = {type = "fixed",
fixed = {{-1/2, -9/64, -9/64, 1/2, 9/64, 9/64}}},
groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 2, tubedevice = 1},
sounds = default.node_sound_wood_defaults(),
tube = {
connect_sides = {left = 1, right = 1},
can_go = function(pos, node, velocity, stack)
return {velocity}
end,
can_insert = function(pos, node, stack, direction)
local dir = minetest.facedir_to_right_dir(node.param2)
return vector.equals(dir, direction)
end,
priority = 75 -- Higher than normal tubes, but lower than receivers
},
after_place_node = pipeworks.after_place,
after_dig_node = pipeworks.after_dig,
})
minetest.register_craft({
output = "pipeworks:one_way_tube 2",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "group:stick", "default:mese_crystal", "homedecor:plastic_sheeting" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
end

View File

@ -0,0 +1,111 @@
if pipeworks.enable_detector_tube then
local detector_tube_step = 2 * tonumber(minetest.setting_get("dedicated_server_step"))
pipeworks.register_tube("pipeworks:detector_tube_on", {
description = "Detecting Pneumatic Tube Segment on (you hacker you)",
inventory_image = "pipeworks_detector_tube_inv.png",
plain = { "pipeworks_detector_tube_plain.png" },
node_def = {
tube = {can_go = function(pos, node, velocity, stack)
local meta = minetest.get_meta(pos)
local name = minetest.get_node(pos).name
local nitems = meta:get_int("nitems")+1
meta:set_int("nitems", nitems)
local saved_pos = vector.new(pos)
minetest.after(detector_tube_step, minetest.registered_nodes[name].item_exit, saved_pos)
return pipeworks.notvel(pipeworks.meseadjlist,velocity)
end},
groups = {mesecon = 2, not_in_creative_inventory = 1},
drop = "pipeworks:detector_tube_off_1",
mesecons = {receptor = {state = "on", rules = pipeworks.mesecons_rules}},
item_exit = function(pos)
local meta = minetest.get_meta(pos)
local nitems = meta:get_int("nitems")-1
local node = minetest.get_node(pos)
local name = node.name
local fdir = node.param2
if nitems == 0 then
minetest.set_node(pos, {name = string.gsub(name, "on", "off"), param2 = fdir})
mesecon.receptor_off(pos, pipeworks.mesecons_rules)
else
meta:set_int("nitems", nitems)
end
end,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("nitems", 1)
local name = minetest.get_node(pos).name
local saved_pos = vector.new(pos)
minetest.after(detector_tube_step, minetest.registered_nodes[name].item_exit, saved_pos)
end,
},
})
pipeworks.register_tube("pipeworks:detector_tube_off", {
description = "Detecting Pneumatic Tube Segment",
inventory_image = "pipeworks_detector_tube_inv.png",
plain = { "pipeworks_detector_tube_plain.png" },
node_def = {
tube = {can_go = function(pos, node, velocity, stack)
local node = minetest.get_node(pos)
local name = node.name
local fdir = node.param2
minetest.set_node(pos,{name = string.gsub(name, "off", "on"), param2 = fdir})
mesecon.receptor_on(pos, pipeworks.mesecons_rules)
return pipeworks.notvel(pipeworks.meseadjlist, velocity)
end},
groups = {mesecon = 2},
mesecons = {receptor = {state = "off", rules = pipeworks.mesecons_rules }},
},
})
minetest.register_craft( {
output = "pipeworks:conductor_tube_off_1 6",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "mesecons:mesecon", "mesecons:mesecon", "mesecons:mesecon" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
end
if pipeworks.enable_conductor_tube then
pipeworks.register_tube("pipeworks:conductor_tube_off", {
description = "Conducting Pneumatic Tube Segment",
inventory_image = "pipeworks_conductor_tube_inv.png",
short = "pipeworks_conductor_tube_short.png",
plain = { "pipeworks_conductor_tube_plain.png" },
noctr = { "pipeworks_conductor_tube_noctr.png" },
ends = { "pipeworks_conductor_tube_end.png" },
node_def = {
groups = {mesecon = 2},
mesecons = {conductor = {state = "off",
rules = pipeworks.mesecons_rules,
onstate = "pipeworks:conductor_tube_on_#id"}}
},
})
pipeworks.register_tube("pipeworks:conductor_tube_on", {
description = "Conducting Pneumatic Tube Segment on (you hacker you)",
inventory_image = "pipeworks_conductor_tube_inv.png",
short = "pipeworks_conductor_tube_short.png",
plain = { "pipeworks_conductor_tube_on_plain.png" },
noctr = { "pipeworks_conductor_tube_on_noctr.png" },
ends = { "pipeworks_conductor_tube_on_end.png" },
node_def = {
groups = {mesecon = 2, not_in_creative_inventory = 1},
drop = "pipeworks:conductor_tube_off_1",
mesecons = {conductor = {state = "on",
rules = pipeworks.mesecons_rules,
offstate = "pipeworks:conductor_tube_off_#id"}}
},
})
minetest.register_craft( {
output = "pipeworks:detector_tube_off_1 2",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "mesecons:mesecon", "mesecons_materials:silicon", "mesecons:mesecon" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
end

View File

@ -0,0 +1,148 @@
if pipeworks.enable_mese_tube then
local function update_formspec(pos)
local meta = minetest.get_meta(pos)
local old_formspec = meta:get_string("formspec")
if string.find(old_formspec, "button1") then -- Old version
local inv = meta:get_inventory()
for i = 1, 6 do
for _, stack in ipairs(inv:get_list("line"..i)) do
minetest.item_drop(stack, "", pos)
end
end
end
local buttons_formspec = ""
for i = 0, 5 do
buttons_formspec = buttons_formspec .. fs_helpers.cycling_button(meta,
"image_button[7,"..(i)..";1,1", "l"..(i+1).."s",
{{text="",texture="pipeworks_button_off.png", addopts="false;false;pipeworks_button_interm.png"}, {text="",texture="pipeworks_button_on.png", addopts="false;false;pipeworks_button_interm.png"}})
end
meta:set_string("formspec",
"size[8,11]"..
"list[context;line1;1,0;6,1;]"..
"list[context;line2;1,1;6,1;]"..
"list[context;line3;1,2;6,1;]"..
"list[context;line4;1,3;6,1;]"..
"list[context;line5;1,4;6,1;]"..
"list[context;line6;1,5;6,1;]"..
"image[0,0;1,1;pipeworks_white.png]"..
"image[0,1;1,1;pipeworks_black.png]"..
"image[0,2;1,1;pipeworks_green.png]"..
"image[0,3;1,1;pipeworks_yellow.png]"..
"image[0,4;1,1;pipeworks_blue.png]"..
"image[0,5;1,1;pipeworks_red.png]"..
buttons_formspec..
"list[current_player;main;0,7;8,4;]")
end
pipeworks.register_tube("pipeworks:mese_tube", {
description = "Sorting Pneumatic Tube Segment",
inventory_image = "pipeworks_mese_tube_inv.png",
noctr = {"pipeworks_mese_tube_noctr_1.png", "pipeworks_mese_tube_noctr_2.png", "pipeworks_mese_tube_noctr_3.png",
"pipeworks_mese_tube_noctr_4.png", "pipeworks_mese_tube_noctr_5.png", "pipeworks_mese_tube_noctr_6.png"},
plain = {"pipeworks_mese_tube_plain_1.png", "pipeworks_mese_tube_plain_2.png", "pipeworks_mese_tube_plain_3.png",
"pipeworks_mese_tube_plain_4.png", "pipeworks_mese_tube_plain_5.png", "pipeworks_mese_tube_plain_6.png"},
ends = { "pipeworks_mese_tube_end.png" },
short = "pipeworks_mese_tube_short.png",
no_facedir = true, -- Must use old tubes, since the textures are rotated with 6d ones
node_def = {
tube = {can_go = function(pos, node, velocity, stack)
local tbl, tbln = {}, 0
local found, foundn = {}, 0
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local name = stack:get_name()
for i, vect in ipairs(pipeworks.meseadjlist) do
local npos = vector.add(pos, vect)
local node = minetest.get_node(npos)
local reg_node = minetest.registered_nodes[node.name]
if meta:get_int("l"..i.."s") == 1 and reg_node then
local tube_def = reg_node.tube
if not tube_def or not tube_def.can_insert or
tube_def.can_insert(npos, node, stack, vect) then
local invname = "line"..i
local is_empty = true
for _, st in ipairs(inv:get_list(invname)) do
if not st:is_empty() then
is_empty = false
if st:get_name() == name then
foundn = foundn + 1
found[foundn] = vect
end
end
end
if is_empty then
tbln = tbln + 1
tbl[tbln] = vect
end
end
end
end
return (foundn > 0) and found or tbl
end},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
for i = 1, 6 do
meta:set_int("l"..tostring(i).."s", 1)
inv:set_size("line"..tostring(i), 6*1)
end
update_formspec(pos)
meta:set_string("infotext", "Sorting pneumatic tube")
end,
on_punch = update_formspec,
on_receive_fields = function(pos, formname, fields, sender)
if not pipeworks.may_configure(pos, sender) then return end
fs_helpers.on_receive_fields(pos, fields)
update_formspec(pos)
end,
can_dig = function(pos, player)
update_formspec(pos) -- so non-virtual items would be dropped for old tubes
return true
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if not pipeworks.may_configure(pos, player) then return 0 end
update_formspec(pos) -- For old tubes
local inv = minetest.get_meta(pos):get_inventory()
local stack_copy = ItemStack(stack)
stack_copy:set_count(1)
inv:set_stack(listname, index, stack_copy)
return 0
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if not pipeworks.may_configure(pos, player) then return 0 end
update_formspec(pos) -- For old tubes
local inv = minetest.get_meta(pos):get_inventory()
inv:set_stack(listname, index, ItemStack(""))
return 0
end,
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
if not pipeworks.may_configure(pos, player) then return 0 end
update_formspec(pos) -- For old tubes
local inv = minetest.get_meta(pos):get_inventory()
inv:set_stack(from_list, from_index, ItemStack(""))
return 0
end,
},
})
minetest.register_craft( {
output = "pipeworks:mese_tube_000000 2",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "", "default:mese_crystal", "" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
minetest.register_craft( {
type = "shapeless",
output = "pipeworks:mese_tube_000000",
recipe = {
"pipeworks:tube_1",
"default:mese_crystal_fragment",
"default:mese_crystal_fragment",
"default:mese_crystal_fragment",
"default:mese_crystal_fragment"
},
})
end

View File

@ -1,53 +1,76 @@
local filename=minetest.get_worldpath() .. "/teleport_tubes"
local function read_file()
local f = io.open(filename, "r")
if f == nil then return {} end
local t = f:read("*all")
f:close()
if t == "" or t == nil then return {} end
return minetest.deserialize(t)
local tp_tube_db = nil -- nil forces a read
local tp_tube_db_version = 2.0
local function hash(pos)
return string.format("%d", minetest.hash_node_position(pos))
end
local function write_file(tbl)
local f = io.open(filename, "w")
f:write(minetest.serialize(tbl))
f:close()
local function save_tube_db()
local file, err = io.open(filename, "w")
if file then
tp_tube_db.version = tp_tube_db_version
file:write(minetest.serialize(tp_tube_db))
tp_tube_db.version = nil
io.close(file)
else
error(err)
end
end
local function update_pos_in_file(pos)
local tbl=read_file()
for _, val in ipairs(tbl) do
if val.x == pos.x and val.y == pos.y and val.z == pos.z then
local meta = minetest.get_meta(val)
val.channel = meta:get_string("channel")
val.cr = meta:get_int("can_receive")
local function migrate_tube_db()
local tmp_db = {}
tp_tube_db.version = nil
for key, val in pairs(tp_tube_db) do
if(val.channel ~= "") then -- skip unconfigured tubes
tmp_db[hash(val)] = val
end
end
tp_tube_db = tmp_db
save_tube_db()
end
local function read_tube_db()
local file = io.open(filename, "r")
if file ~= nil then
local file_content = file:read("*all")
io.close(file)
if file_content and file_content ~= "" then
tp_tube_db = minetest.deserialize(file_content)
if(not tp_tube_db.version or tonumber(tp_tube_db.version) < tp_tube_db_version) then
migrate_tube_db()
end
tp_tube_db.version = nil -- we add it back when saving
return tp_tube_db -- we read sucessfully
end
end
write_file(tbl)
tp_tube_db = {}
return tp_tube_db
end
local function add_tube_in_file(pos,channel, cr)
local tbl=read_file()
for _,val in ipairs(tbl) do
if val.x==pos.x and val.y==pos.y and val.z==pos.z then
return
end
-- updates or adds a tube
local function set_tube(pos, channel, can_receive)
local tubes = tp_tube_db or read_tube_db()
local hash = hash(pos)
local tube = tubes[hash]
if tube then
tube.channel = channel
tube.cr = can_receive
save_tube_db()
return
end
table.insert(tbl,{x=pos.x,y=pos.y,z=pos.z,channel=channel,cr=cr})
write_file(tbl)
-- we haven't found any tp tube to update, so lets add it
tp_tube_db[hash] = {x=pos.x,y=pos.y,z=pos.z,channel=channel,cr=can_receive}
save_tube_db()
end
local function remove_tube_in_file(pos)
local tbl = read_file()
local newtbl = {}
for _, val in ipairs(tbl) do
if val.x ~= pos.x or val.y ~= pos.y or val.z ~= pos.z then
table.insert(newtbl, val)
end
end
write_file(newtbl)
local function remove_tube(pos)
local tubes = tp_tube_db or read_tube_db()
tubes[hash(pos)] = nil
save_tube_db()
end
local function read_node_with_vm(pos)
@ -58,123 +81,161 @@ local function read_node_with_vm(pos)
return minetest.get_name_from_content_id(data[area:index(pos.x, pos.y, pos.z)])
end
local function get_tubes_in_file(pos,channel)
local tbl = read_file()
local newtbl = {}
local changed = false
for _, val in ipairs(tbl) do
local meta = minetest.get_meta(val)
local name = read_node_with_vm(val)
local is_loaded = (minetest.get_node_or_nil(val) ~= nil)
local is_teleport_tube = minetest.registered_nodes[name] and minetest.registered_nodes[name].is_teleport_tube
if is_teleport_tube then
if is_loaded and (val.channel ~= meta:get_string("channel") or val.cr ~= meta:get_int("can_receive")) then
val.channel = meta:get_string("channel")
val.cr = meta:get_int("can_receive")
changed = true
end
if val.cr == 1 and val.channel == channel and (val.x ~= pos.x or val.y ~= pos.y or val.z ~= pos.z) then
table.insert(newtbl, val)
end
else
val.to_remove = true
changed = true
end
end
if changed then
local updated = {}
for _, val in ipairs(tbl) do
if not val.to_remove then
table.insert(updated, val)
local function get_receivers(pos, channel)
local tubes = tp_tube_db or read_tube_db()
local receivers = {}
local dirty = false
for key, val in pairs(tubes) do
-- skip all non-receivers and the tube that it came from as early as possible, as this is called often
if (val.cr == 1 and val.channel == channel and (val.x ~= pos.x or val.y ~= pos.y or val.z ~= pos.z)) then
local is_loaded = (minetest.get_node_or_nil(val) ~= nil)
local node_name = is_loaded and minetest.get_node(pos).name or read_node_with_vm(val)
if minetest.registered_nodes[node_name] and minetest.registered_nodes[node_name].is_teleport_tube then
table.insert(receivers, val)
else
tp_tube_db[key] = nil
dirty = true
end
end
write_file(updated)
end
return newtbl
if dirty then
save_tube_db()
end
return receivers
end
local teleport_noctr_textures={"pipeworks_teleport_tube_noctr.png","pipeworks_teleport_tube_noctr.png","pipeworks_teleport_tube_noctr.png",
"pipeworks_teleport_tube_noctr.png","pipeworks_teleport_tube_noctr.png","pipeworks_teleport_tube_noctr.png"}
local teleport_plain_textures={"pipeworks_teleport_tube_plain.png","pipeworks_teleport_tube_plain.png","pipeworks_teleport_tube_plain.png",
"pipeworks_teleport_tube_plain.png","pipeworks_teleport_tube_plain.png","pipeworks_teleport_tube_plain.png"}
local teleport_end_textures={"pipeworks_teleport_tube_end.png","pipeworks_teleport_tube_end.png","pipeworks_teleport_tube_end.png",
"pipeworks_teleport_tube_end.png","pipeworks_teleport_tube_end.png","pipeworks_teleport_tube_end.png"}
local teleport_short_texture="pipeworks_teleport_tube_short.png"
local teleport_inv_texture="pipeworks_teleport_tube_inv.png"
local function set_teleport_tube_formspec(meta)
local cr = meta:get_int("can_receive") ~= 0
meta:set_string("formspec","size[10.5,1;]"..
"field[0,0.5;7,1;channel;Channel:;${channel}]"..
"button[8,0;2.5,1;"..(cr and "cr0" or "cr1")..";"..
(cr and "Send and Receive" or "Send only").."]")
local function update_meta(meta, can_receive)
meta:set_int("can_receive", can_receive and 1 or 0)
local cr_state = can_receive and "on" or "off"
meta:set_string("formspec","size[8.6,2.2]"..
"field[0.6,0.6;7,1;channel;Channel:;${channel}]"..
"label[7.3,0;Receive]"..
"image_button[7.3,0.3;1,1;pipeworks_button_" .. cr_state .. ".png;cr" .. (can_receive and 0 or 1) .. ";;;false;pipeworks_button_interm.png]"..
"image[0.3,1.3;1,1;pipeworks_teleport_tube_inv.png]"..
"label[1.6,1.2;channels are public by default]" ..
"label[1.6,1.5;use <player>:<channel> for fully private channels]" ..
"label[1.6,1.8;use <player>\\;<channel> for private receivers]" ..
default.gui_bg..
default.gui_bg_img)
end
pipeworks.register_tube("pipeworks:teleport_tube","Teleporting Pneumatic Tube Segment",teleport_plain_textures,
teleport_noctr_textures,teleport_end_textures,teleport_short_texture,teleport_inv_texture, {
is_teleport_tube = true,
tube = {
can_go = function(pos,node,velocity,stack)
velocity.x = 0
velocity.y = 0
velocity.z = 0
pipeworks.register_tube("pipeworks:teleport_tube", {
description = "Teleporting Pneumatic Tube Segment",
inventory_image = "pipeworks_teleport_tube_inv.png",
noctr = { "pipeworks_teleport_tube_noctr.png" },
plain = { "pipeworks_teleport_tube_plain.png" },
ends = { "pipeworks_teleport_tube_end.png" },
short = "pipeworks_teleport_tube_short.png",
node_def = {
is_teleport_tube = true,
tube = {
can_go = function(pos,node,velocity,stack)
velocity.x = 0
velocity.y = 0
velocity.z = 0
local channel = minetest.get_meta(pos):get_string("channel")
if channel == "" then return {} end
local target = get_receivers(pos, channel)
if target[1] == nil then return {} end
local d = math.random(1,#target)
pos.x = target[d].x
pos.y = target[d].y
pos.z = target[d].z
return pipeworks.meseadjlist
end
},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local channel = meta:get_string("channel")
local target = get_tubes_in_file(pos,channel)
if target[1] == nil then return {} end
local d = math.random(1,#target)
pos.x = target[d].x
pos.y = target[d].y
pos.z = target[d].z
return pipeworks.meseadjlist
end
},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("channel","")
meta:set_int("can_receive",1)
add_tube_in_file(pos,"")
set_teleport_tube_formspec(meta)
end,
on_receive_fields = function(pos,formname,fields,sender)
local meta = minetest.get_meta(pos)
--check for private channels
if fields.channel ~= nil then
local name, mode = fields.channel:match("^([^:;]+)([:;])")
if name and mode and name ~= sender:get_player_name() then
update_meta(meta, true)
meta:set_string("infotext", "unconfigured Teleportation Tube")
end,
on_receive_fields = function(pos,formname,fields,sender)
if not fields.channel -- ignore escaping or clientside manipulation of the form
or not pipeworks.may_configure(pos, sender) then
return
end
local new_channel = tostring(fields.channel):trim()
local meta = minetest.get_meta(pos)
local can_receive = meta:get_int("can_receive")
-- check for private channels each time before actually changing anything
-- to not even allow switching between can_receive states of private channels
if new_channel ~= "" then
local sender_name = sender:get_player_name()
local name, mode = new_channel:match("^([^:;]+)([:;])")
if name and mode and name ~= sender_name then
--channels starting with '[name]:' can only be used by the named player
if mode == ":" then
minetest.chat_send_player(sender_name, "Sorry, channel '"..new_channel.."' is reserved for exclusive use by "..name)
return
--channels starting with '[name]:' can only be used by the named player
if mode == ":" then
minetest.chat_send_player(sender:get_player_name(), "Sorry, channel '"..fields.channel.."' is reserved for exclusive use by "..name)
return
--channels starting with '[name];' can be used by other players, but cannot be received from
elseif mode == ";" and (fields.cr1 or (meta:get_int("can_receive") ~= 0 and not fields.cr0)) then
minetest.chat_send_player(sender:get_player_name(), "Sorry, receiving from channel '"..fields.channel.."' is reserved for "..name)
return
--channels starting with '[name];' can be used by other players, but cannot be received from
elseif mode == ";" and (fields.cr1 or (can_receive ~= 0 and not fields.cr0)) then
minetest.chat_send_player(sender_name, "Sorry, receiving from channel '"..new_channel.."' is reserved for "..name)
return
end
end
end
local dirty = false
-- was the channel changed?
local channel = meta:get_string("channel")
if new_channel ~= channel then
channel = new_channel
meta:set_string("channel", channel)
dirty = true
end
-- test if a can_receive button was pressed
if fields.cr0 and can_receive ~= 0 then
can_receive = 0
update_meta(meta, false)
dirty = true
elseif fields.cr1 and can_receive ~= 1 then
can_receive = 1
update_meta(meta, true)
dirty = true
end
-- save if we changed something, handle the empty channel while we're at it
if dirty then
if channel ~= "" then
set_tube(pos, channel, can_receive)
local cr_description = (can_receive == 1) and "sending and receiving" or "sending"
meta:set_string("infotext", string.format("Teleportation Tube %s on '%s'", cr_description, channel))
else
-- remove empty channel tubes, to not have to search through them
remove_tube(pos)
meta:set_string("infotext", "unconfigured Teleportation Tube")
end
end
end,
on_destruct = function(pos)
remove_tube(pos)
end
if fields.channel==nil then fields.channel=meta:get_string("channel") end
meta:set_string("channel",fields.channel)
remove_tube_in_file(pos)
if fields.cr0 then meta:set_int("can_receive", 0) end
if fields.cr1 then meta:set_int("can_receive", 1) end
local cr = meta:get_int("can_receive")
add_tube_in_file(pos, fields.channel, meta:get_int("can_receive"))
set_teleport_tube_formspec(meta)
end,
on_destruct = function(pos)
remove_tube_in_file(pos)
end})
},
})
minetest.register_craft( {
output = "pipeworks:teleport_tube_1 2",
recipe = {
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
{ "default:desert_stone", "default:mese", "default:desert_stone" },
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
},
})
if minetest.get_modpath("mesecons_mvps") ~= nil then
mesecon:register_on_mvps_move(function(moved_nodes)
mesecon.register_on_mvps_move(function(moved_nodes)
for _, n in ipairs(moved_nodes) do
if string.find(n.node.name, "pipeworks:teleport_tube") ~= nil then
update_pos_in_file(n.pos)
local meta = minetest.get_meta(n.pos)
set_tube(n.pos, meta:get_string("channel"), meta:get_int("can_receive"))
end
end
end)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 383 B

After

Width:  |  Height:  |  Size: 289 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 600 B

After

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 380 B

After

Width:  |  Height:  |  Size: 293 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 721 B

After

Width:  |  Height:  |  Size: 693 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 B

After

Width:  |  Height:  |  Size: 83 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 B

After

Width:  |  Height:  |  Size: 83 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 839 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 642 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1005 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 755 B

After

Width:  |  Height:  |  Size: 575 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 512 B

After

Width:  |  Height:  |  Size: 275 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 819 B

After

Width:  |  Height:  |  Size: 801 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 841 B

After

Width:  |  Height:  |  Size: 823 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 841 B

After

Width:  |  Height:  |  Size: 823 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 841 B

After

Width:  |  Height:  |  Size: 823 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 819 B

After

Width:  |  Height:  |  Size: 801 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 853 B

After

Width:  |  Height:  |  Size: 828 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 892 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 760 B

After

Width:  |  Height:  |  Size: 526 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 B

After

Width:  |  Height:  |  Size: 83 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 699 B

After

Width:  |  Height:  |  Size: 602 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 628 B

After

Width:  |  Height:  |  Size: 572 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 721 B

After

Width:  |  Height:  |  Size: 693 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 651 B

After

Width:  |  Height:  |  Size: 633 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 657 B

After

Width:  |  Height:  |  Size: 637 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 660 B

After

Width:  |  Height:  |  Size: 640 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 607 B

After

Width:  |  Height:  |  Size: 587 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 563 B

After

Width:  |  Height:  |  Size: 544 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 598 B

After

Width:  |  Height:  |  Size: 581 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 608 B

After

Width:  |  Height:  |  Size: 589 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 601 B

After

Width:  |  Height:  |  Size: 581 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 610 B

After

Width:  |  Height:  |  Size: 589 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 656 B

After

Width:  |  Height:  |  Size: 637 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 659 B

After

Width:  |  Height:  |  Size: 640 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 839 B

After

Width:  |  Height:  |  Size: 513 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 839 B

After

Width:  |  Height:  |  Size: 513 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 869 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 873 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 B

After

Width:  |  Height:  |  Size: 83 B

Some files were not shown because too many files have changed in this diff Show More