mirror of
https://github.com/mt-mods/pipeworks.git
synced 2025-07-17 15:50:30 +02:00
Compare commits
28 Commits
repair-fix
...
2f9f9a7b54
Author | SHA1 | Date | |
---|---|---|---|
2f9f9a7b54 | |||
02322855d5 | |||
b11cb37123 | |||
503c1190ed | |||
5bba517b03 | |||
66070dd801 | |||
7ee74133e1 | |||
c01bd7b888 | |||
e2fdcc4fb2 | |||
e4db1e885e | |||
f7839444cd | |||
93f5fb3d87 | |||
a535bebd2e | |||
be2776fc46 | |||
ee03959a65 | |||
4dd30df37a | |||
946da11206 | |||
77c8026400 | |||
70b521c721 | |||
6d795b7d34 | |||
92249b7941 | |||
e04fb691ad | |||
ac80224371 | |||
34262ed8d5 | |||
5cfe8d893f | |||
975e20f704 | |||
2693e2ecbb | |||
c93df73a5c |
13
.github/workflows/luacheck.yml
vendored
13
.github/workflows/luacheck.yml
vendored
@ -1,10 +1,13 @@
|
||||
name: luacheck
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
luacheck:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@master
|
||||
- name: Luacheck
|
||||
uses: lunarmodules/luacheck@master
|
||||
- uses: actions/checkout@master
|
||||
- name: apt
|
||||
run: sudo apt-get install -y luarocks
|
||||
- name: luacheck install
|
||||
run: luarocks install --local luacheck
|
||||
- name: luacheck run
|
||||
run: $HOME/.luarocks/bin/luacheck ./
|
||||
|
282
autocrafter.lua
282
autocrafter.lua
@ -1,14 +1,11 @@
|
||||
local S = minetest.get_translator("pipeworks")
|
||||
-- cache some recipe data to avoid calling the slow function
|
||||
-- minetest.get_craft_result() every second
|
||||
local autocrafterCache = {}
|
||||
local autocrafterCache = {} -- caches some recipe data to avoid to call the slow function minetest.get_craft_result() every second
|
||||
|
||||
local craft_time = 1
|
||||
|
||||
local function count_index(invlist)
|
||||
local index = {}
|
||||
for _, stack in pairs(invlist) do
|
||||
stack = ItemStack(stack)
|
||||
if not stack:is_empty() then
|
||||
local stack_name = stack:get_name()
|
||||
index[stack_name] = (index[stack_name] or 0) + stack:get_count()
|
||||
@ -24,152 +21,41 @@ local function get_item_info(stack)
|
||||
return description, name
|
||||
end
|
||||
|
||||
-- Get best matching recipe for what user has put in crafting grid.
|
||||
-- This function does not consider crafting method (mix vs craft)
|
||||
local function get_matching_craft(output_name, example_recipe)
|
||||
local recipes = minetest.get_all_craft_recipes(output_name)
|
||||
if not recipes then
|
||||
return example_recipe
|
||||
end
|
||||
|
||||
if 1 == #recipes then
|
||||
return recipes[1].items
|
||||
end
|
||||
|
||||
local index_example = count_index(example_recipe)
|
||||
local best_score = 0
|
||||
local index_recipe, best_index, score, group
|
||||
for i = 1, #recipes do
|
||||
score = 0
|
||||
index_recipe = count_index(recipes[i].items)
|
||||
for recipe_item_name, _ in pairs(index_recipe) do
|
||||
if index_example[recipe_item_name] then
|
||||
score = score + 1
|
||||
elseif recipe_item_name:sub(1, 6) == "group:" then
|
||||
group = recipe_item_name:sub(7)
|
||||
for example_item_name, _ in pairs(index_example) do
|
||||
if minetest.get_item_group(example_item_name, group) > 0 then
|
||||
score = score + 1
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if best_score < score then
|
||||
best_index = i
|
||||
end
|
||||
end
|
||||
|
||||
return best_index and recipes[best_index].items or example_recipe
|
||||
end
|
||||
|
||||
local function get_craft(pos, inventory, hash)
|
||||
local hash = hash or minetest.hash_node_position(pos)
|
||||
local craft = autocrafterCache[hash]
|
||||
if craft then return craft end
|
||||
|
||||
local example_recipe = inventory:get_list("recipe")
|
||||
local output, decremented_input = minetest.get_craft_result({
|
||||
method = "normal", width = 3, items = example_recipe
|
||||
})
|
||||
|
||||
local recipe = example_recipe
|
||||
if output and not output.item:is_empty() then
|
||||
recipe = get_matching_craft(output.item:get_name(), example_recipe)
|
||||
end
|
||||
|
||||
craft = {
|
||||
recipe = recipe,
|
||||
consumption = count_index(recipe),
|
||||
output = output,
|
||||
decremented_input = decremented_input.items
|
||||
}
|
||||
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
|
||||
|
||||
-- From a consumption table with groups and an inventory index, build
|
||||
-- a consumption table without groups
|
||||
local function calculate_consumption(inv_index, consumption_with_groups)
|
||||
inv_index = table.copy(inv_index)
|
||||
consumption_with_groups = table.copy(consumption_with_groups)
|
||||
|
||||
local consumption = {}
|
||||
local groups = {}
|
||||
|
||||
-- First consume all non-group requirements
|
||||
-- This is done to avoid consuming a non-group item which is also
|
||||
-- in a group
|
||||
for key, count in pairs(consumption_with_groups) do
|
||||
if key:sub(1, 6) == "group:" then
|
||||
groups[#groups + 1] = key:sub(7, #key)
|
||||
else
|
||||
if not inv_index[key] or inv_index[key] < count then
|
||||
return nil
|
||||
local function autocraft(inventory, craft)
|
||||
if not craft then return false end
|
||||
-- check if we have enough material available
|
||||
local inv_index = count_index(inventory:get_list("src"))
|
||||
for itemname, number in pairs(craft.consumption) do
|
||||
if (not inv_index[itemname]) or inv_index[itemname] < number then return false end
|
||||
end
|
||||
|
||||
consumption[key] = (consumption[key] or 0) + count
|
||||
consumption_with_groups[key] = consumption_with_groups[key] - count
|
||||
assert(consumption_with_groups[key] == 0)
|
||||
consumption_with_groups[key] = nil
|
||||
inv_index[key] = inv_index[key] - count
|
||||
assert(inv_index[key] >= 0)
|
||||
end
|
||||
end
|
||||
|
||||
-- Next, resolve groups using the remaining items in the inventory
|
||||
local take
|
||||
if #groups > 0 then
|
||||
for itemname, count in pairs(inv_index) do
|
||||
if count > 0 then
|
||||
local def = minetest.registered_items[itemname]
|
||||
local item_groups = def and def.groups or {}
|
||||
for i = 1, #groups do
|
||||
local group = groups[i]
|
||||
local groupname = "group:" .. group
|
||||
if item_groups[group] and item_groups[group] >= 1
|
||||
and consumption_with_groups[groupname] > 0
|
||||
then
|
||||
take = math.min(count, consumption_with_groups[groupname])
|
||||
consumption_with_groups[groupname] =
|
||||
consumption_with_groups[groupname] - take
|
||||
|
||||
assert(consumption_with_groups[groupname] >= 0)
|
||||
consumption[itemname] =
|
||||
(consumption[itemname] or 0) + take
|
||||
|
||||
inv_index[itemname] = inv_index[itemname] - take
|
||||
assert(inv_index[itemname] >= 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Finally, check everything has been consumed
|
||||
for key, count in pairs(consumption_with_groups) do
|
||||
if count > 0 then
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
return consumption
|
||||
end
|
||||
|
||||
local function has_room_for_output(list_output, index_output)
|
||||
local name
|
||||
-- check if output and all replacements fit in dst
|
||||
local output = craft.output.item
|
||||
local out_items = count_index(craft.decremented_input.items)
|
||||
out_items[output:get_name()] = (out_items[output:get_name()] or 0) + output:get_count()
|
||||
local empty_count = 0
|
||||
for _, item in pairs(list_output) do
|
||||
for _,item in pairs(inventory:get_list("dst")) do
|
||||
if item:is_empty() then
|
||||
empty_count = empty_count + 1
|
||||
else
|
||||
name = item:get_name()
|
||||
if index_output[name] then
|
||||
index_output[name] = index_output[name] - item:get_free_space()
|
||||
local name = item:get_name()
|
||||
if out_items[name] then
|
||||
out_items[name] = out_items[name] - item:get_free_space()
|
||||
end
|
||||
end
|
||||
end
|
||||
for _, count in pairs(index_output) do
|
||||
for _,count in pairs(out_items) do
|
||||
if count > 0 then
|
||||
empty_count = empty_count - 1
|
||||
end
|
||||
@ -177,61 +63,32 @@ local function has_room_for_output(list_output, index_output)
|
||||
if empty_count < 0 then
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
local function autocraft(inventory, craft)
|
||||
if not craft then return false end
|
||||
|
||||
-- check if output and all replacements fit in dst
|
||||
local output = craft.output.item
|
||||
local out_items = count_index(craft.decremented_input)
|
||||
out_items[output:get_name()] =
|
||||
(out_items[output:get_name()] or 0) + output:get_count()
|
||||
|
||||
if not has_room_for_output(inventory:get_list("dst"), out_items) then
|
||||
return false
|
||||
end
|
||||
|
||||
-- check if we have enough material available
|
||||
local inv_index = count_index(inventory:get_list("src"))
|
||||
local consumption = calculate_consumption(inv_index, craft.consumption)
|
||||
if not consumption then
|
||||
return false
|
||||
end
|
||||
|
||||
-- consume material
|
||||
for itemname, number in pairs(consumption) do
|
||||
-- We have to do that since remove_item does not work if count > stack_max
|
||||
for _ = 1, number do
|
||||
for itemname, number in pairs(craft.consumption) do
|
||||
for _ = 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
|
||||
|
||||
-- craft the result into the dst inventory and add any "replacements" as well
|
||||
inventory:add_item("dst", output)
|
||||
local leftover
|
||||
for i = 1, 9 do
|
||||
leftover = inventory:add_item("dst", craft.decremented_input[i])
|
||||
if leftover and not leftover:is_empty() then
|
||||
minetest.log("warning", "[pipeworks] autocrafter didn't " ..
|
||||
"calculate output space correctly.")
|
||||
end
|
||||
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
|
||||
-- recipe is cached
|
||||
-- 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
|
||||
-- NALC: existence de limitgroup ?
|
||||
local limitcraft = minetest.get_item_group(output_item:get_name(), "limitcraft") or 0
|
||||
-- only use crafts that have an actual result
|
||||
if output_item:is_empty() then
|
||||
-- NALC: ou si l'item n'est pas dans le group limitcraft
|
||||
if output_item:is_empty() or limitcraft > 0 then
|
||||
meta:set_string("infotext", S("unconfigured Autocrafter: unknown recipe"))
|
||||
return false
|
||||
end
|
||||
@ -260,17 +117,33 @@ 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 hash = minetest.hash_node_position(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
autocrafterCache[hash] = nil
|
||||
-- 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", S("unconfigured Autocrafter"))
|
||||
inventory:set_stack("output", 1, "")
|
||||
return
|
||||
end
|
||||
local craft = get_craft(pos, inventory, hash)
|
||||
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", S("'@1' Autocrafter (@2)", description, name))
|
||||
@ -279,8 +152,7 @@ local function after_recipe_change(pos, inventory)
|
||||
after_inventory_change(pos)
|
||||
end
|
||||
|
||||
-- clean out unknown items and groups, which would be handled like unknown
|
||||
-- items in the crafting grid
|
||||
-- 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)
|
||||
@ -311,14 +183,12 @@ local function on_output_change(pos, inventory, stack)
|
||||
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
|
||||
-- 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
|
||||
-- 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)
|
||||
@ -327,20 +197,17 @@ local function update_meta(meta, enabled)
|
||||
list_backgrounds = "style_type[box;colors=#666]"
|
||||
for i=0, 2 do
|
||||
for j=0, 2 do
|
||||
list_backgrounds = list_backgrounds .. "box[" ..
|
||||
0.22 + (i * 1.25) .. "," .. 0.22 + (j * 1.25) .. ";1,1;]"
|
||||
list_backgrounds = list_backgrounds .. "box[".. 0.22+(i*1.25) ..",".. 0.22+(j*1.25) ..";1,1;]"
|
||||
end
|
||||
end
|
||||
for i=0, 3 do
|
||||
for j=0, 2 do
|
||||
list_backgrounds = list_backgrounds .. "box[" ..
|
||||
5.28 + (i * 1.25) .. "," .. 0.22 + (j * 1.25) .. ";1,1;]"
|
||||
list_backgrounds = list_backgrounds .. "box[".. 5.28+(i*1.25) ..",".. 0.22+(j*1.25) ..";1,1;]"
|
||||
end
|
||||
end
|
||||
for i=0, 7 do
|
||||
for j=0, 2 do
|
||||
list_backgrounds = list_backgrounds .. "box[" ..
|
||||
0.22 + (i * 1.25) .. "," .. 5 + (j * 1.25) .. ";1,1;]"
|
||||
list_backgrounds = list_backgrounds .. "box[".. 0.22+(i*1.25) ..",".. 5+(j*1.25) ..";1,1;]"
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -353,8 +220,7 @@ local function update_meta(meta, enabled)
|
||||
"list[context;recipe;0.22,0.22;3,3;]"..
|
||||
"image[4,1.45;1,1;[combine:16x16^[noalpha^[colorize:#141318:255]"..
|
||||
"list[context;output;4,1.45;1,1;]"..
|
||||
"image_button[4,2.6;1,0.6;pipeworks_button_" .. state .. ".png;" ..
|
||||
state .. ";;;false;pipeworks_button_interm.png]" ..
|
||||
"image_button[4,2.6;1,0.6;pipeworks_button_" .. state .. ".png;" .. state .. ";;;false;pipeworks_button_interm.png]" ..
|
||||
"list[context;dst;5.28,0.22;4,3;]"..
|
||||
"list[context;src;0.22,5;8,3;]"..
|
||||
pipeworks.fs_helpers.get_inv(9)..
|
||||
@ -364,8 +230,7 @@ local function update_meta(meta, enabled)
|
||||
"listring[context;dst]" ..
|
||||
"listring[current_player;main]"
|
||||
if minetest.get_modpath("digilines") then
|
||||
fs = fs .. "field[0.22,4.1;4.5,0.75;channel;" .. S("Channel") ..
|
||||
";${channel}]" ..
|
||||
fs = fs.."field[0.22,4.1;4.5,0.75;channel;"..S("Channel")..";${channel}]"..
|
||||
"button[5,4.1;1.5,0.75;set_channel;"..S("Set").."]"..
|
||||
"button_exit[6.8,4.1;2,0.75;close;"..S("Close").."]"
|
||||
end
|
||||
@ -389,12 +254,9 @@ local function update_meta(meta, 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
|
||||
-- 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()
|
||||
@ -405,8 +267,7 @@ local function upgrade_autocrafter(pos, meta)
|
||||
update_meta(meta, true)
|
||||
|
||||
if meta:get_string("virtual_items") == "1" then -- we are version 2
|
||||
-- we already dropped stuff, so lets remove the metadatasetting
|
||||
-- (we are not being called again for this node)
|
||||
-- we already 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")
|
||||
@ -446,10 +307,7 @@ minetest.register_node("pipeworks:autocrafter", {
|
||||
return inv:room_for_item("src", stack)
|
||||
end,
|
||||
input_inventory = "dst",
|
||||
connect_sides = {
|
||||
left = 1, right = 1, front = 1, back = 1, top = 1, bottom = 1
|
||||
}
|
||||
},
|
||||
connect_sides = {left = 1, right = 1, front = 1, back = 1, top = 1, bottom = 1}},
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
@ -460,9 +318,7 @@ minetest.register_node("pipeworks:autocrafter", {
|
||||
update_meta(meta, false)
|
||||
end,
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
if (fields.quit and not fields.key_enter_field)
|
||||
or not pipeworks.may_configure(pos, sender)
|
||||
then
|
||||
if (fields.quit and not fields.key_enter_field) or not pipeworks.may_configure(pos, sender) then
|
||||
return
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
@ -509,9 +365,7 @@ minetest.register_node("pipeworks:autocrafter", {
|
||||
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)))
|
||||
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)
|
||||
@ -527,9 +381,7 @@ minetest.register_node("pipeworks:autocrafter", {
|
||||
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)
|
||||
|
||||
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()
|
||||
@ -574,8 +426,7 @@ minetest.register_node("pipeworks:autocrafter", {
|
||||
for x=1,3,1 do
|
||||
local slot = y*3+x
|
||||
if minetest.registered_items[msg[y+1][x]] then
|
||||
inv:set_stack("recipe", slot, ItemStack(
|
||||
msg[y + 1][x]))
|
||||
inv:set_stack("recipe",slot,ItemStack(msg[y+1][x]))
|
||||
else
|
||||
inv:set_stack("recipe",slot,ItemStack(""))
|
||||
end
|
||||
@ -590,8 +441,7 @@ minetest.register_node("pipeworks:autocrafter", {
|
||||
local row = {}
|
||||
for x=1,3,1 do
|
||||
local slot = y*3+x
|
||||
table.insert(row, inv:get_stack(
|
||||
"recipe", slot):get_name())
|
||||
table.insert(row, inv:get_stack("recipe",slot):get_name())
|
||||
end
|
||||
table.insert(recipe, row)
|
||||
end
|
||||
|
@ -3,60 +3,6 @@ Changelog
|
||||
|
||||
|
||||
|
||||
2023-06-22 (SwissalpS, rubenwardy)
|
||||
groups support in recipe. Set recipe as usual via recipe formspec or digilines.
|
||||
Autocrafter now resolves matching recipe using groups so that items in input
|
||||
inventory are used, that match group and no longer only strictly what user
|
||||
has in recipe-inventory
|
||||
|
||||
|
||||
|
||||
2023-06-21 (OgelGames, BuckarooBanzay)
|
||||
fix autocrafter destroying replacement items (OG)
|
||||
remove facedir debugging logs (BB)
|
||||
|
||||
|
||||
|
||||
2023-05-28 (SwissalpS)
|
||||
support setting 'can_receive' for teleport tubes via digiline
|
||||
|
||||
|
||||
|
||||
2023-05-19 (fluxionary, OgelGames)
|
||||
log items going through teleport tubes
|
||||
|
||||
|
||||
|
||||
2022-12-02 (wsor4035)
|
||||
bring back compatibility with mineclone2
|
||||
|
||||
|
||||
|
||||
2022-11-11 (OgelGames)
|
||||
prevent tp- and sand-tubes from breaking themselves and refactor part of code
|
||||
|
||||
2022-09-18 (fluxionary)
|
||||
protection checks before break-/placeing a node -> less violation logs
|
||||
|
||||
|
||||
2022-08-14 (wsor4035)
|
||||
prevent tubes from connecting to furnace front
|
||||
|
||||
|
||||
|
||||
2022-08-13 (TurkeyMcMac)
|
||||
moved teleport-tube database to mod-storage
|
||||
|
||||
|
||||
|
||||
2022-06-23 (S-S-X)
|
||||
on_repair tweak, improved repairing tubes
|
||||
|
||||
|
||||
* many updates not mentioned here *
|
||||
|
||||
|
||||
|
||||
2017-10-19 (thetaepsilon)
|
||||
Directional flowables are now implemented.
|
||||
All devices for which it is relevant (valve, flow sensor etc.) have been converted so that they only flow on their connecting sides, so pressure propogation now works as expected for these devices when pressure logic is enabled.
|
||||
|
319
common.lua
319
common.lua
@ -1,96 +1,3 @@
|
||||
local S = minetest.get_translator("pipeworks")
|
||||
|
||||
-- Random variables
|
||||
|
||||
pipeworks.expect_infinite_stacks = true
|
||||
if minetest.get_modpath("unified_inventory") or not minetest.settings:get_bool("creative_mode") then
|
||||
pipeworks.expect_infinite_stacks = false
|
||||
end
|
||||
|
||||
pipeworks.meseadjlist={{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}}
|
||||
|
||||
pipeworks.rules_all = {{x=0, y=0, z=1},{x=0, y=0, z=-1},{x=1, y=0, z=0},{x=-1, y=0, z=0},
|
||||
{x=0, y=1, z=1},{x=0, y=1, z=-1},{x=1, y=1, z=0},{x=-1, y=1, z=0},
|
||||
{x=0, y=-1, z=1},{x=0, y=-1, z=-1},{x=1, y=-1, z=0},{x=-1, y=-1, z=0},
|
||||
{x=0, y=1, z=0}, {x=0, y=-1, z=0}}
|
||||
|
||||
pipeworks.mesecons_rules={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=1,z=0},{x=0,y=-1,z=0}}
|
||||
pipeworks.digilines_rules={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=1,z=0},{x=0,y=-1,z=0}}
|
||||
|
||||
pipeworks.liquid_texture = minetest.registered_nodes[pipeworks.liquids.water.flowing].tiles[1]
|
||||
if type(pipeworks.liquid_texture) == "table" then pipeworks.liquid_texture = pipeworks.liquid_texture.name end
|
||||
|
||||
pipeworks.button_off = {text="", texture="pipeworks_button_off.png", addopts="false;false;pipeworks_button_interm.png"}
|
||||
pipeworks.button_on = {text="", texture="pipeworks_button_on.png", addopts="false;false;pipeworks_button_interm.png"}
|
||||
pipeworks.button_base = "image_button[0,4.3;1,0.6"
|
||||
pipeworks.button_label = "label[0.9,4.31;"..S("Allow splitting incoming stacks from tubes").."]"
|
||||
|
||||
-- Helper functions
|
||||
|
||||
function pipeworks.fix_image_names(table, replacement)
|
||||
local outtable={}
|
||||
for i in ipairs(table) do
|
||||
outtable[i]=string.gsub(table[i], "_XXXXX", replacement)
|
||||
end
|
||||
|
||||
return outtable
|
||||
end
|
||||
|
||||
local function overlay_tube_texture(texture)
|
||||
-- The texture appears the first time to be colorized as the opaque background.
|
||||
return ("(%s)^[noalpha^[colorize:#dadada^(%s)"):format(texture, texture)
|
||||
end
|
||||
|
||||
function pipeworks.make_tube_tile(tile)
|
||||
if pipeworks.use_real_entities then
|
||||
return tile
|
||||
elseif type(tile) == "string" then
|
||||
return overlay_tube_texture(tile)
|
||||
else
|
||||
tile = table.copy(tile)
|
||||
if tile.color then
|
||||
-- Won't work 100% of the time, but good enough.
|
||||
tile.name = tile.name .. "^[multiply:" .. minetest.colorspec_to_colorstring(tile.color)
|
||||
tile.color = nil
|
||||
end
|
||||
tile.name = overlay_tube_texture(tile.name)
|
||||
tile.backface_culling = nil -- The texture is opaque
|
||||
return tile
|
||||
end
|
||||
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.may_configure(pos, player)
|
||||
local name = player:get_player_name()
|
||||
local meta = minetest.get_meta(pos)
|
||||
local owner = meta:get_string("owner")
|
||||
|
||||
if owner ~= "" and owner == name then -- wielders and filters
|
||||
return true
|
||||
end
|
||||
return not minetest.is_protected(pos, name)
|
||||
end
|
||||
|
||||
function pipeworks.replace_name(tbl,tr,name)
|
||||
local ntbl={}
|
||||
for key,i in pairs(tbl) do
|
||||
if type(i)=="string" then
|
||||
ntbl[key]=string.gsub(i,tr,name)
|
||||
elseif type(i)=="table" then
|
||||
ntbl[key]=pipeworks.replace_name(i,tr,name)
|
||||
else
|
||||
ntbl[key]=i
|
||||
end
|
||||
end
|
||||
return ntbl
|
||||
end
|
||||
|
||||
----------------------
|
||||
-- Vector functions --
|
||||
----------------------
|
||||
@ -341,183 +248,6 @@ local function get_set_wrap(name, is_dynamic)
|
||||
end)
|
||||
end
|
||||
|
||||
local fake_player_metatable = {
|
||||
is_player = delay(true),
|
||||
is_fake_player = true,
|
||||
|
||||
-- dummy implementation of the rest of the player API:
|
||||
add_player_velocity = delay(), -- deprecated
|
||||
add_velocity = delay(),
|
||||
get_acceleration = delay(), -- no-op for players
|
||||
get_animation = delay({x = 0, y = 0}, 0, 0, false),
|
||||
get_armor_groups = delay({}),
|
||||
get_attach = delay(),
|
||||
get_attribute = delay(), -- deprecated
|
||||
get_bone_position = delay(vector.zero(), vector.zero()),
|
||||
get_children = delay({}),
|
||||
get_clouds = delay({
|
||||
ambient = { r = 0, b = 0, g = 0, a = 0 },
|
||||
color = { r = 0, b = 0, g = 0, a = 0 },
|
||||
density = 0,
|
||||
height = 120,
|
||||
thickness = 10,
|
||||
speed = vector.zero(),
|
||||
}),
|
||||
get_day_night_ratio = delay(),
|
||||
get_entity_name = delay(),
|
||||
get_formspec_prepend = delay(""),
|
||||
get_fov = delay(0, false, 0),
|
||||
get_lighting = delay({
|
||||
exposure = {
|
||||
center_weight_power = 1,
|
||||
exposure_correction = 0,
|
||||
luminance_max = -3,
|
||||
luminance_min = -3,
|
||||
speed_bright_dark = 1000,
|
||||
speed_dark_bright = 1000,
|
||||
},
|
||||
saturation = 1,
|
||||
shadows = {
|
||||
intensity = .6212,
|
||||
},
|
||||
}),
|
||||
get_local_animation = delay({x = 0, y = 0}, {x = 0, y = 0}, {x = 0, y = 0}, {x = 0, y = 0}, 30),
|
||||
get_luaentity = delay(),
|
||||
get_meta = delay({
|
||||
contains = delay(false),
|
||||
get = delay(),
|
||||
set_string = delay(),
|
||||
get_string = delay(""),
|
||||
set_int = delay(),
|
||||
get_int = delay(0),
|
||||
set_float = delay(),
|
||||
get_float = delay(0),
|
||||
get_keys = delay({}),
|
||||
to_table = delay({fields = {}}),
|
||||
from_table = delay(false),
|
||||
equals = delay(false),
|
||||
}),
|
||||
get_moon = delay({
|
||||
scale = 1,
|
||||
texture = "",
|
||||
tonemap = "",
|
||||
visible = false,
|
||||
}),
|
||||
get_physics_override = delay({
|
||||
acceleration_air = 1,
|
||||
acceleration_default = 1,
|
||||
gravity = 1,
|
||||
jump = 1,
|
||||
liquid_fluidity = 1,
|
||||
liquid_fluidity_smooth = 1,
|
||||
liquid_sink = 1,
|
||||
new_move = true,
|
||||
sneak = true,
|
||||
sneak_glitch = false,
|
||||
speed = 1,
|
||||
speed_climb = 1,
|
||||
speed_crouch = 1,
|
||||
}),
|
||||
get_player_velocity = vector.zero, -- deprecated
|
||||
get_rotation = delay(), -- no-op for players
|
||||
get_sky = delay({ r = 0, g = 0, b = 0, a = 0 }, "regular", {}, true),
|
||||
get_sky_color = delay({
|
||||
dawn_horizon = { r = 0, g = 0, b = 0, a = 0 },
|
||||
dawn_sky = { r = 0, g = 0, b = 0, a = 0 },
|
||||
day_horizon = { r = 0, g = 0, b = 0, a = 0 },
|
||||
day_sky = { r = 0, g = 0, b = 0, a = 0 },
|
||||
fog_moon_tint = { r = 0, g = 0, b = 0, a = 0 },
|
||||
fog_sun_tint = { r = 0, g = 0, b = 0, a = 0 },
|
||||
fog_tint_type = "default",
|
||||
indoors = { r = 0, g = 0, b = 0, a = 0 },
|
||||
night_horizon = { r = 0, g = 0, b = 0, a = 0 },
|
||||
night_sky = { r = 0, g = 0, b = 0, a = 0 },
|
||||
}),
|
||||
get_stars = delay({
|
||||
count = 1000,
|
||||
day_opacity = 0,
|
||||
scale = 1,
|
||||
star_color = { r = 0, g = 0, b = 0, a = 0 },
|
||||
visible = true,
|
||||
}),
|
||||
get_sun = delay({
|
||||
scale = 1,
|
||||
sunrise = "",
|
||||
sunrise_visible = true,
|
||||
texture = "",
|
||||
tonemap = "",
|
||||
visible = true,
|
||||
}),
|
||||
get_texture_mod = delay(), -- no-op for players
|
||||
get_velocity = vector.zero,
|
||||
get_yaw = delay(), -- no-op for players
|
||||
getacceleration = delay(), -- backward compatibility
|
||||
getvelocity = vector.zero, -- backward compatibility
|
||||
getyaw = delay(), -- backward compatibility
|
||||
hud_add = delay(),
|
||||
hud_change = delay(),
|
||||
hud_get = delay(),
|
||||
hud_get_flags = delay({
|
||||
basic_debug = false,
|
||||
breathbar = false,
|
||||
chat = false,
|
||||
crosshair = false,
|
||||
healthbar = false,
|
||||
hotbar = false,
|
||||
minimap = false,
|
||||
minimap_radar = false,
|
||||
wielditem = false,
|
||||
}),
|
||||
hud_get_hotbar_image = delay(""),
|
||||
hud_get_hotbar_itemcount = delay(1),
|
||||
hud_get_hotbar_selected_image = delay(""),
|
||||
hud_remove = delay(),
|
||||
hud_set_flags = delay(),
|
||||
hud_set_hotbar_image = delay(),
|
||||
hud_set_hotbar_itemcount = delay(),
|
||||
hud_set_hotbar_selected_image = delay(),
|
||||
override_day_night_ratio = delay(),
|
||||
punch = delay(),
|
||||
remove = delay(),
|
||||
respawn = delay(),
|
||||
right_click = delay(),
|
||||
send_mapblock = delay(),
|
||||
set_acceleration = delay(),
|
||||
set_animation = delay(),
|
||||
set_animation_frame_speed = delay(),
|
||||
set_armor_groups = delay(),
|
||||
set_attach = delay(),
|
||||
set_attribute = delay(), -- deprecated
|
||||
set_bone_position = delay(),
|
||||
set_clouds = delay(),
|
||||
set_detach = delay(),
|
||||
set_formspec_prepend = delay(),
|
||||
set_fov = delay(),
|
||||
set_lighting = delay(),
|
||||
set_local_animation = delay(),
|
||||
set_look_horizontal = delay(),
|
||||
set_look_pitch = delay(),
|
||||
set_look_vertical = delay(),
|
||||
set_look_yaw = delay(),
|
||||
set_minimap_modes = delay(),
|
||||
set_moon = delay(),
|
||||
set_nametag_attributes = delay(),
|
||||
set_physics_override = delay(),
|
||||
set_rotation = delay(), -- no-op for players
|
||||
set_sky = delay(),
|
||||
set_sprite = delay(), -- no-op for players
|
||||
set_stars = delay(),
|
||||
set_sun = delay(),
|
||||
set_texture_mod = delay(), -- no-op for players
|
||||
set_velocity = delay(), -- no-op for players
|
||||
set_yaw = delay(), -- no-op for players
|
||||
setacceleration = delay(), -- backward compatibility
|
||||
setsprite = delay(), -- backward compatibility
|
||||
settexturemod = delay(), -- backward compatibility
|
||||
setvelocity = delay(), -- backward compatibility
|
||||
setyaw = delay(), -- backward compatibility
|
||||
}
|
||||
|
||||
function pipeworks.create_fake_player(def, is_dynamic)
|
||||
local wielded_item = ItemStack("")
|
||||
if def.inventory and def.wield_list then
|
||||
@ -525,6 +255,8 @@ function pipeworks.create_fake_player(def, is_dynamic)
|
||||
end
|
||||
local p = {
|
||||
get_player_name = delay(def.name),
|
||||
is_player = delay(true),
|
||||
is_fake_player = true,
|
||||
|
||||
_formspec = def.formspec or "",
|
||||
_hp = def.hp or 20,
|
||||
@ -545,11 +277,12 @@ function pipeworks.create_fake_player(def, is_dynamic)
|
||||
get_eye_offset = function(self)
|
||||
return self._eye_offset1, self._eye_offset3
|
||||
end,
|
||||
get_look_dir = delay(def.look_dir or vector.new()),
|
||||
get_look_dir = delay(def.look_dir or {x=0, y=0, z=1}),
|
||||
get_look_pitch = delay(def.look_pitch or 0),
|
||||
get_look_yaw = delay(def.look_yaw or 0),
|
||||
get_look_horizontal = delay(def.look_yaw or 0),
|
||||
get_look_vertical = delay(-(def.look_pitch or 0)),
|
||||
set_animation = delay(),
|
||||
|
||||
-- Controls
|
||||
get_player_control = delay({
|
||||
@ -575,11 +308,14 @@ function pipeworks.create_fake_player(def, is_dynamic)
|
||||
return ItemStack(self._wielded_item)
|
||||
end,
|
||||
get_wield_list = delay(def.wield_list),
|
||||
get_nametag_attributes = delay({
|
||||
bgcolor = false,
|
||||
color = { r = 0, g = 0, b = 0, a = 0 },
|
||||
text = def.name,
|
||||
}),
|
||||
|
||||
punch = delay(),
|
||||
remove = delay(),
|
||||
right_click = delay(),
|
||||
set_attach = delay(),
|
||||
set_detach = delay(),
|
||||
set_bone_position = delay(),
|
||||
hud_change = delay(),
|
||||
}
|
||||
-- Getter & setter functions
|
||||
p.get_inventory_formspec, p.set_inventory_formspec
|
||||
@ -593,10 +329,37 @@ function pipeworks.create_fake_player(def, is_dynamic)
|
||||
-- For players, move_to and get_pos do the same
|
||||
p.move_to = p.get_pos
|
||||
|
||||
-- Backwards compatibility
|
||||
-- Backwards compatibilty
|
||||
p.getpos = p.get_pos
|
||||
p.setpos = p.set_pos
|
||||
p.moveto = p.move_to
|
||||
setmetatable(p, { __index = fake_player_metatable })
|
||||
|
||||
-- TODO "implement" all these
|
||||
-- set_armor_groups
|
||||
-- get_armor_groups
|
||||
-- get_animation
|
||||
-- get_bone_position
|
||||
-- get_player_velocity
|
||||
-- set_look_pitch
|
||||
-- set_look_yaw
|
||||
-- set_physics_override
|
||||
-- get_physics_override
|
||||
-- hud_add
|
||||
-- hud_remove
|
||||
-- hud_get
|
||||
-- hud_set_flags
|
||||
-- hud_get_flags
|
||||
-- hud_set_hotbar_itemcount
|
||||
-- hud_get_hotbar_itemcount
|
||||
-- hud_set_hotbar_image
|
||||
-- hud_get_hotbar_image
|
||||
-- hud_set_hotbar_selected_image
|
||||
-- hud_get_hotbar_selected_image
|
||||
-- hud_replace_builtin
|
||||
-- set_sky
|
||||
-- get_sky
|
||||
-- override_day_night_ratio
|
||||
-- get_day_night_ratio
|
||||
-- set_local_animation
|
||||
return p
|
||||
end
|
||||
|
76
crafts.lua
76
crafts.lua
@ -1,5 +1,70 @@
|
||||
local materials = {
|
||||
stone = "default:stone",
|
||||
desert_stone = "default:desert_stone",
|
||||
desert_sand = "default:desert_sand",
|
||||
chest = "default:chest",
|
||||
copper_ingot = "default:copper_ingot",
|
||||
steel_ingot = "default:steel_ingot",
|
||||
gold_ingot = "default:gold_ingot",
|
||||
mese = "default:mese",
|
||||
mese_crystal = "default:mese_crystal",
|
||||
mese_crystal_fragment = "default:mese_crystal_fragment",
|
||||
teleporter = "default:mese",
|
||||
glass = "default:glass",
|
||||
}
|
||||
|
||||
if minetest.get_modpath("mcl_core") then
|
||||
materials = {
|
||||
stone = "mcl_core:stone",
|
||||
desert_stone = "mcl_core:redsandstone",
|
||||
desert_sand = "mcl_core:sand",
|
||||
chest = "mcl_chests:chest",
|
||||
steel_ingot = "mcl_core:iron_ingot",
|
||||
gold_ingot = "mcl_core:gold_ingot",
|
||||
mese = "mesecons_torch:redstoneblock",
|
||||
mese_crystal = "mesecons:redstone",
|
||||
mese_crystal_fragment = "mesecons:redstone",
|
||||
teleporter = "mesecons_torch:redstoneblock",
|
||||
copper_ingot = "mcl_copper:copper_ingot",
|
||||
glass = "mcl_core:glass",
|
||||
}
|
||||
elseif minetest.get_modpath("fl_ores") and minetest.get_modpath("fl_stone") then
|
||||
materials = {
|
||||
stone = "fl_stone:stone",
|
||||
desert_stone = "fl_stone:desert_stone",
|
||||
desert_sand = "fl_stone:desert_sand",
|
||||
chest = "fl_storage:wood_chest",
|
||||
steel_ingot = "fl_ores:iron_ingot",
|
||||
gold_ingot = "fl_ores:gold_ingot",
|
||||
mese = "fl_ores:iron_ingot",
|
||||
mese_crystal = "fl_ores:iron_ingot",
|
||||
mese_crystal_fragment = "fl_ores:iron_ingot",
|
||||
teleporter = "fl_ores:iron_ingot",
|
||||
copper_ingot = "fl_ores:copper_ingot",
|
||||
glass = "fl_glass:framed_glass",
|
||||
}
|
||||
elseif minetest.get_modpath("hades_core") then
|
||||
materials = {
|
||||
stone = "hades_core:stone",
|
||||
desert_stone = "hades_core:stone_baked",
|
||||
desert_sand = "hades_core:volcanic_sand",
|
||||
chest = "hades_chests:chest";
|
||||
steel_ingot = "hades_core:steel_ingot",
|
||||
gold_ingot = "hades_core:gold_ingot",
|
||||
mese = "hades_core:mese",
|
||||
mese_crystal = "hades_core:mese_crystal",
|
||||
mese_crystal_fragment = "hades_core:mese_crystal_fragment",
|
||||
teleporter = "hades_materials:teleporter_device",
|
||||
copper_ingot = "hades_core:copper_ingot",
|
||||
tin_ingot = "hades_core:tin_ingot",
|
||||
glass = "hades_core:glass",
|
||||
}
|
||||
if minetest.get_modpath("hades_default") then
|
||||
materials.desert_sand = "hades_default:desert_sand"
|
||||
end
|
||||
end
|
||||
|
||||
-- Crafting recipes for pipes
|
||||
local materials = ...
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:pipe_1_empty 12",
|
||||
@ -129,6 +194,15 @@ minetest.register_craft( {
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:steel_block_embedded_tube 1",
|
||||
recipe = {
|
||||
{ materials.steel_ingot, materials.steel_ingot, materials.steel_ingot },
|
||||
{ materials.steel_ingot, "pipeworks:tube_1", materials.steel_ingot },
|
||||
{ materials.steel_ingot, materials.steel_ingot, materials.steel_ingot }
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = "pipeworks:steel_pane_embedded_tube 1",
|
||||
recipe = {
|
||||
|
@ -1,6 +1,39 @@
|
||||
local S = minetest.get_translator("pipeworks")
|
||||
|
||||
local straight = function(pos, node, velocity, stack) return {velocity} end
|
||||
local steel_tex = "[combine:16x16^[noalpha^[colorize:#D3D3D3"
|
||||
if minetest.get_modpath("default") then steel_tex = "default_steel_block.png" end
|
||||
|
||||
minetest.register_node("pipeworks:steel_block_embedded_tube", {
|
||||
description = S("Airtight steelblock embedded tube"),
|
||||
tiles = {
|
||||
steel_tex, steel_tex,
|
||||
steel_tex, steel_tex,
|
||||
steel_tex .. "^pipeworks_tube_connection_metallic.png",
|
||||
steel_tex .. "^pipeworks_tube_connection_metallic.png",
|
||||
},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=1, oddly_breakable_by_hand = 1, tubedevice = 1, dig_glass = 2, pickaxey=1, handy=1},
|
||||
_mcl_hardness=0.8,
|
||||
legacy_facedir_simple = true,
|
||||
_sound_def = {
|
||||
key = "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,
|
||||
on_rotate = pipeworks.on_rotate,
|
||||
})
|
||||
pipeworks.ui_cat_tube_list[#pipeworks.ui_cat_tube_list+1] = "pipeworks:steel_block_embedded_tube"
|
||||
|
||||
local pane_box = {
|
||||
type = "fixed",
|
147
init.lua
147
init.lua
@ -4,21 +4,22 @@
|
||||
-- and devices that they can connect to.
|
||||
--
|
||||
|
||||
pipeworks = {
|
||||
ui_cat_tube_list = {},
|
||||
worldpath = minetest.get_worldpath(),
|
||||
modpath = minetest.get_modpath("pipeworks"),
|
||||
liquids = {
|
||||
water = {
|
||||
pipeworks = {}
|
||||
pipeworks.ui_cat_tube_list = {}
|
||||
|
||||
pipeworks.worldpath = minetest.get_worldpath()
|
||||
pipeworks.modpath = minetest.get_modpath("pipeworks")
|
||||
local S = minetest.get_translator("pipeworks")
|
||||
|
||||
pipeworks.liquids = {}
|
||||
pipeworks.liquids.water = {
|
||||
source = minetest.registered_nodes["mapgen_water_source"].name,
|
||||
flowing = minetest.registered_nodes["mapgen_water_source"].liquid_alternative_flowing
|
||||
},
|
||||
river_water = {
|
||||
}
|
||||
pipeworks.liquids.river_water = {
|
||||
source = minetest.registered_nodes["mapgen_river_water_source"].name,
|
||||
flowing = minetest.registered_nodes["mapgen_river_water_source"].liquid_alternative_flowing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dofile(pipeworks.modpath.."/default_settings.lua")
|
||||
-- Read the external config file if it exists.
|
||||
@ -35,6 +36,97 @@ if pipeworks.entity_update_interval >= 0.2 and pipeworks.enable_accelerator_tube
|
||||
minetest.log("warning", "pipeworks accelerator tubes will not entirely work with an entity update interval 0.2 or above.")
|
||||
end
|
||||
|
||||
-- Random variables
|
||||
|
||||
pipeworks.expect_infinite_stacks = true
|
||||
if minetest.get_modpath("unified_inventory") or not minetest.settings:get_bool("creative_mode") then
|
||||
pipeworks.expect_infinite_stacks = false
|
||||
end
|
||||
|
||||
pipeworks.meseadjlist={{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}}
|
||||
|
||||
pipeworks.rules_all = {{x=0, y=0, z=1},{x=0, y=0, z=-1},{x=1, y=0, z=0},{x=-1, y=0, z=0},
|
||||
{x=0, y=1, z=1},{x=0, y=1, z=-1},{x=1, y=1, z=0},{x=-1, y=1, z=0},
|
||||
{x=0, y=-1, z=1},{x=0, y=-1, z=-1},{x=1, y=-1, z=0},{x=-1, y=-1, z=0},
|
||||
{x=0, y=1, z=0}, {x=0, y=-1, z=0}}
|
||||
|
||||
pipeworks.mesecons_rules={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=1,z=0},{x=0,y=-1,z=0}}
|
||||
pipeworks.digilines_rules={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=1,z=0},{x=0,y=-1,z=0}}
|
||||
|
||||
pipeworks.liquid_texture = minetest.registered_nodes[pipeworks.liquids.water.flowing].tiles[1]
|
||||
if type(pipeworks.liquid_texture) == "table" then pipeworks.liquid_texture = pipeworks.liquid_texture.name end
|
||||
|
||||
pipeworks.button_off = {text="", texture="pipeworks_button_off.png", addopts="false;false;pipeworks_button_interm.png"}
|
||||
pipeworks.button_on = {text="", texture="pipeworks_button_on.png", addopts="false;false;pipeworks_button_interm.png"}
|
||||
pipeworks.button_base = "image_button[0,4.3;1,0.6"
|
||||
pipeworks.button_label = "label[0.9,4.31;"..S("Allow splitting incoming stacks from tubes").."]"
|
||||
|
||||
-- Helper functions
|
||||
|
||||
function pipeworks.fix_image_names(table, replacement)
|
||||
local outtable={}
|
||||
for i in ipairs(table) do
|
||||
outtable[i]=string.gsub(table[i], "_XXXXX", replacement)
|
||||
end
|
||||
|
||||
return outtable
|
||||
end
|
||||
|
||||
local function overlay_tube_texture(texture)
|
||||
-- The texture appears the first time to be colorized as the opaque background.
|
||||
return ("(%s)^[noalpha^[colorize:#dadada^(%s)"):format(texture, texture)
|
||||
end
|
||||
|
||||
function pipeworks.make_tube_tile(tile)
|
||||
if pipeworks.use_real_entities then
|
||||
return tile
|
||||
elseif type(tile) == "string" then
|
||||
return overlay_tube_texture(tile)
|
||||
else
|
||||
tile = table.copy(tile)
|
||||
if tile.color then
|
||||
-- Won't work 100% of the time, but good enough.
|
||||
tile.name = tile.name .. "^[multiply:" .. minetest.colorspec_to_colorstring(tile.color)
|
||||
tile.color = nil
|
||||
end
|
||||
tile.name = overlay_tube_texture(tile.name)
|
||||
tile.backface_culling = nil -- The texture is opaque
|
||||
return tile
|
||||
end
|
||||
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.may_configure(pos, player)
|
||||
local name = player:get_player_name()
|
||||
local meta = minetest.get_meta(pos)
|
||||
local owner = meta:get_string("owner")
|
||||
|
||||
if owner ~= "" and owner == name then -- wielders and filters
|
||||
return true
|
||||
end
|
||||
return not minetest.is_protected(pos, name)
|
||||
end
|
||||
|
||||
function pipeworks.replace_name(tbl,tr,name)
|
||||
local ntbl={}
|
||||
for key,i in pairs(tbl) do
|
||||
if type(i)=="string" then
|
||||
ntbl[key]=string.gsub(i,tr,name)
|
||||
elseif type(i)=="table" then
|
||||
ntbl[key]=pipeworks.replace_name(i,tr,name)
|
||||
else
|
||||
ntbl[key]=i
|
||||
end
|
||||
end
|
||||
return ntbl
|
||||
end
|
||||
|
||||
pipeworks.logger = function(msg)
|
||||
minetest.log("action", "[pipeworks] "..msg)
|
||||
end
|
||||
@ -58,29 +150,15 @@ dofile(pipeworks.modpath.."/autoplace_tubes.lua")
|
||||
dofile(pipeworks.modpath.."/luaentity.lua")
|
||||
dofile(pipeworks.modpath.."/item_transport.lua")
|
||||
dofile(pipeworks.modpath.."/flowing_logic.lua")
|
||||
dofile(pipeworks.modpath.."/tube_registration.lua")
|
||||
dofile(pipeworks.modpath.."/routing_tubes.lua")
|
||||
dofile(pipeworks.modpath.."/sorting_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")
|
||||
|
||||
local materials = loadfile(pipeworks.modpath.."/materials.lua")()
|
||||
|
||||
dofile(pipeworks.modpath.."/tubes/registration.lua")
|
||||
dofile(pipeworks.modpath.."/tubes/routing.lua")
|
||||
dofile(pipeworks.modpath.."/tubes/sorting.lua")
|
||||
dofile(pipeworks.modpath.."/tubes/signal.lua")
|
||||
loadfile(pipeworks.modpath.."/tubes/embedded_tube.lua")(materials)
|
||||
dofile(pipeworks.modpath.."/tubes/pane_embedded_tube.lua")
|
||||
|
||||
if pipeworks.enable_teleport_tube then
|
||||
dofile(pipeworks.modpath.."/tubes/teleport.lua")
|
||||
end
|
||||
if pipeworks.enable_lua_tube and minetest.get_modpath("mesecons") then
|
||||
dofile(pipeworks.modpath.."/tubes/lua.lua")
|
||||
end
|
||||
if pipeworks.enable_sand_tube or pipeworks.enable_mese_sand_tube then
|
||||
dofile(pipeworks.modpath.."/tubes/vacuum.lua")
|
||||
end
|
||||
|
||||
local logicdir = "/pressure_logic/"
|
||||
|
||||
-- note that even with these files the new flow logic is not yet default.
|
||||
@ -94,6 +172,9 @@ dofile(pipeworks.modpath..logicdir.."flowable_node_registry_install.lua")
|
||||
if pipeworks.enable_pipes then
|
||||
dofile(pipeworks.modpath.."/pipes.lua")
|
||||
end
|
||||
if pipeworks.enable_teleport_tube then
|
||||
dofile(pipeworks.modpath.."/teleport_tube.lua")
|
||||
end
|
||||
if pipeworks.enable_pipe_devices then
|
||||
dofile(pipeworks.modpath.."/devices.lua")
|
||||
end
|
||||
@ -110,8 +191,14 @@ end
|
||||
if pipeworks.enable_autocrafter then
|
||||
dofile(pipeworks.modpath.."/autocrafter.lua")
|
||||
end
|
||||
if pipeworks.enable_lua_tube and minetest.get_modpath("mesecons") then
|
||||
dofile(pipeworks.modpath.."/lua_tube.lua")
|
||||
end
|
||||
if pipeworks.enable_sand_tube or pipeworks.enable_mese_sand_tube then
|
||||
dofile(pipeworks.modpath.."/vacuum_tubes.lua")
|
||||
end
|
||||
|
||||
loadfile(pipeworks.modpath.."/crafts.lua")(materials)
|
||||
dofile(pipeworks.modpath.."/crafts.lua")
|
||||
|
||||
minetest.register_alias("pipeworks:pipe", "pipeworks:pipe_110000_empty")
|
||||
|
||||
|
@ -1,67 +0,0 @@
|
||||
local materials = {
|
||||
stone = "default:stone",
|
||||
desert_stone = "default:desert_stone",
|
||||
desert_sand = "default:desert_sand",
|
||||
chest = "default:chest",
|
||||
copper_ingot = "default:copper_ingot",
|
||||
steel_ingot = "default:steel_ingot",
|
||||
gold_ingot = "default:gold_ingot",
|
||||
mese = "default:mese",
|
||||
mese_crystal = "default:mese_crystal",
|
||||
mese_crystal_fragment = "default:mese_crystal_fragment",
|
||||
teleporter = "default:mese",
|
||||
glass = "default:glass"
|
||||
}
|
||||
|
||||
if minetest.get_modpath("mcl_core") then
|
||||
materials = {
|
||||
stone = "mcl_core:stone",
|
||||
desert_stone = "mcl_core:redsandstone",
|
||||
desert_sand = "mcl_core:sand",
|
||||
chest = "mcl_chests:chest",
|
||||
steel_ingot = "mcl_core:iron_ingot",
|
||||
gold_ingot = "mcl_core:gold_ingot",
|
||||
mese = "mesecons_torch:redstoneblock",
|
||||
mese_crystal = "mesecons:redstone",
|
||||
mese_crystal_fragment = "mesecons:redstone",
|
||||
teleporter = "mesecons_torch:redstoneblock",
|
||||
copper_ingot = "mcl_copper:copper_ingot",
|
||||
glass = "mcl_core:glass",
|
||||
}
|
||||
elseif minetest.get_modpath("fl_ores") and minetest.get_modpath("fl_stone") then
|
||||
materials = {
|
||||
stone = "fl_stone:stone",
|
||||
desert_stone = "fl_stone:desert_stone",
|
||||
desert_sand = "fl_stone:desert_sand",
|
||||
chest = "fl_storage:wood_chest",
|
||||
steel_ingot = "fl_ores:iron_ingot",
|
||||
gold_ingot = "fl_ores:gold_ingot",
|
||||
mese = "fl_ores:iron_ingot",
|
||||
mese_crystal = "fl_ores:iron_ingot",
|
||||
mese_crystal_fragment = "fl_ores:iron_ingot",
|
||||
teleporter = "fl_ores:iron_ingot",
|
||||
copper_ingot = "fl_ores:copper_ingot",
|
||||
glass = "fl_glass:framed_glass",
|
||||
}
|
||||
elseif minetest.get_modpath("hades_core") then
|
||||
materials = {
|
||||
stone = "hades_core:stone",
|
||||
desert_stone = "hades_core:stone_baked",
|
||||
desert_sand = "hades_core:volcanic_sand",
|
||||
chest = "hades_chests:chest";
|
||||
steel_ingot = "hades_core:steel_ingot",
|
||||
gold_ingot = "hades_core:gold_ingot",
|
||||
mese = "hades_core:mese",
|
||||
mese_crystal = "hades_core:mese_crystal",
|
||||
mese_crystal_fragment = "hades_core:mese_crystal_fragment",
|
||||
teleporter = "hades_materials:teleporter_device",
|
||||
copper_ingot = "hades_core:copper_ingot",
|
||||
tin_ingot = "hades_core:tin_ingot",
|
||||
glass = "hades_core:glass",
|
||||
}
|
||||
if minetest.get_modpath("hades_default") then
|
||||
materials.desert_sand = "hades_default:desert_sand"
|
||||
end
|
||||
end
|
||||
|
||||
return materials
|
2
mod.conf
2
mod.conf
@ -2,4 +2,4 @@ name = pipeworks
|
||||
description = This mod uses mesh nodes and nodeboxes to supply a complete set of 3D pipes and tubes, along with devices that work with them.
|
||||
depends = basic_materials
|
||||
optional_depends = mesecons, mesecons_mvps, digilines, signs_lib, unified_inventory, default, screwdriver, fl_mapgen, sound_api, i3, hades_core, hades_furnaces, hades_chests, mcl_mapgen_core, mcl_barrels, mcl_furnaces, mcl_experience
|
||||
min_minetest_version = 5.5.0
|
||||
min_minetest_version = 5.4.0
|
||||
|
@ -93,7 +93,6 @@ pipeworks.register_tube("pipeworks:broken_tube", {
|
||||
minetest.swap_node(pos, { name = was_node.name, param2 = was_node.param2 })
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end
|
||||
meta:set_string("the_tube_was", "")
|
||||
else
|
||||
pipeworks.logger(log_msg.." but original node "..was_node.name.." is not registered anymore.")
|
||||
minetest.chat_send_player(playername, S("This tube cannot be repaired."))
|
@ -1,68 +0,0 @@
|
||||
local materials = ...
|
||||
local S = minetest.get_translator("pipeworks")
|
||||
|
||||
local straight = function(pos, node, velocity, stack) return {velocity} end
|
||||
local steel_tex = "[combine:16x16^[noalpha^[colorize:#D3D3D3"
|
||||
if minetest.get_modpath("default") then steel_tex = "default_steel_block.png" end
|
||||
|
||||
-- register an embedded tube
|
||||
function pipeworks.register_embedded_tube(nodename, opts)
|
||||
minetest.register_node(nodename, {
|
||||
description = opts.description,
|
||||
tiles = {
|
||||
opts.base_texture,
|
||||
opts.base_texture,
|
||||
opts.base_texture,
|
||||
opts.base_texture,
|
||||
opts.base_texture .. "^pipeworks_tube_connection_metallic.png",
|
||||
opts.base_texture .. "^pipeworks_tube_connection_metallic.png",
|
||||
},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
groups = {
|
||||
cracky = 1,
|
||||
oddly_breakable_by_hand = 1,
|
||||
tubedevice = 1,
|
||||
dig_glass = 2,
|
||||
pickaxey=1,
|
||||
handy=1
|
||||
},
|
||||
_mcl_hardness = 0.8,
|
||||
legacy_facedir_simple = true,
|
||||
_sound_def = {
|
||||
key = "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,
|
||||
on_rotate = pipeworks.on_rotate,
|
||||
})
|
||||
|
||||
minetest.register_craft( {
|
||||
output = nodename .. " 1",
|
||||
recipe = {
|
||||
{ opts.base_ingredient, opts.base_ingredient, opts.base_ingredient },
|
||||
{ opts.base_ingredient, "pipeworks:tube_1", opts.base_ingredient },
|
||||
{ opts.base_ingredient, opts.base_ingredient, opts.base_ingredient }
|
||||
},
|
||||
})
|
||||
pipeworks.ui_cat_tube_list[#pipeworks.ui_cat_tube_list+1] = nodename
|
||||
end
|
||||
|
||||
-- steelblock embedded tube
|
||||
pipeworks.register_embedded_tube("pipeworks:steel_block_embedded_tube", {
|
||||
description = S("Airtight steelblock embedded tube"),
|
||||
base_texture = steel_tex,
|
||||
base_ingredient = materials.steel_ingot
|
||||
})
|
@ -32,12 +32,6 @@ local function set_timer(pos)
|
||||
timer:start(math.random(10, 20) * 0.1)
|
||||
end
|
||||
|
||||
local function repair_tube(pos, was_node)
|
||||
minetest.swap_node(pos, {name = was_node.name, param2 = was_node.param2})
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
set_timer(pos)
|
||||
end
|
||||
|
||||
if pipeworks.enable_sand_tube then
|
||||
pipeworks.register_tube("pipeworks:sand_tube", {
|
||||
description = S("Vacuuming Pneumatic Tube Segment"),
|
||||
@ -48,9 +42,6 @@ if pipeworks.enable_sand_tube then
|
||||
ends = {"pipeworks_sand_tube_end.png"},
|
||||
node_def = {
|
||||
groups = {vacuum_tube = 1},
|
||||
tube = {
|
||||
on_repair = repair_tube,
|
||||
},
|
||||
on_construct = set_timer,
|
||||
on_timer = function(pos, elapsed)
|
||||
vacuum(pos, 2)
|
||||
@ -77,9 +68,6 @@ if pipeworks.enable_mese_sand_tube then
|
||||
ends = {"pipeworks_mese_sand_tube_end.png"},
|
||||
node_def = {
|
||||
groups = {vacuum_tube = 1},
|
||||
tube = {
|
||||
on_repair = repair_tube,
|
||||
},
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_int("dist", 2)
|
Reference in New Issue
Block a user