Merge pull request #46 from BlockySurvival/master

merge fork from BlockySurvival back to base
This commit is contained in:
Joachim Stolberg 2020-06-06 17:37:34 +02:00 committed by GitHub
commit 74ec940932
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 195 additions and 113 deletions

@ -91,6 +91,41 @@ local function calculate_probability(item)
item.clust_scarcity / (item.clust_num_ores * ((ymax - ymin) / y_spread)) item.clust_scarcity / (item.clust_num_ores * ((ymax - ymin) / y_spread))
end end
local function pairs_by_values(t, f)
if not f then
f = function(a, b) return a < b end
end
local s = {}
for k, v in pairs(t) do
table.insert(s, {k, v})
end
table.sort(s, function(a, b)
return f(a[2], b[2])
end)
local i = 0
return function()
i = i + 1
local v = s[i]
if v then
return unpack(v)
else
return nil
end
end
end
local function parse_drop(drop)
local d, count = drop:match("^%s*(%S+)%s+(%d+)%s*$")
if d and count then
return d, count
end
d, count = drop:match("%s*craft%s+\"?([^%s\"]+)\"?%s+(%d+)%s*")
if d and count then
return d, count
end
return drop, 1
end
-- collect all registered ores and calculate the probability -- collect all registered ores and calculate the probability
local function add_ores() local function add_ores()
for _,item in pairs(minetest.registered_ores) do for _,item in pairs(minetest.registered_ores) do
@ -104,7 +139,10 @@ local function add_ores()
and item.clust_scarcity ~= nil and item.clust_scarcity > 0 and item.clust_scarcity ~= nil and item.clust_scarcity > 0
and item.clust_num_ores ~= nil and item.clust_num_ores > 0 and item.clust_num_ores ~= nil and item.clust_num_ores > 0
and item.y_max ~= nil and item.y_min ~= nil then and item.y_max ~= nil and item.y_min ~= nil then
local probability = calculate_probability(item) local count
drop, count = parse_drop(drop)
local probability = calculate_probability(item) / count
if probability > 0 then if probability > 0 then
local cur_probability = gravelsieve.ore_probability[drop] local cur_probability = gravelsieve.ore_probability[drop]
if cur_probability then if cur_probability then
@ -116,12 +154,13 @@ local function add_ores()
end end
end end
end end
minetest.log("action", "[gravelsieve] ore probabilties:")
local overall_probability = 0.0 local overall_probability = 0.0
for name,probability in pairs(gravelsieve.ore_probability) do for name,probability in pairs_by_values(gravelsieve.ore_probability) do
minetest.log("info", ("[gravelsieve] %-32s %.02f"):format(name, probability)) minetest.log("action", ("[gravelsieve] %-32s: 1 / %.02f"):format(name, probability))
overall_probability = overall_probability + 1.0/probability overall_probability = overall_probability + 1.0/probability
end end
minetest.log("info", ("[gravelsieve] Overall probability %f"):format(overall_probability)) minetest.log("action", ("[gravelsieve] Overall probability %f"):format(overall_probability))
end end
minetest.after(1, add_ores) minetest.after(1, add_ores)

1
modpack.conf Normal file

@ -0,0 +1 @@
name = techpack

@ -1,2 +1,3 @@
name=techpack_stairway name=techpack_stairway
description=Simple stairways and bridges for your machines.
depends=default

@ -7,7 +7,7 @@
LGPLv2.1+ LGPLv2.1+
See LICENSE.txt for more information See LICENSE.txt for more information
common.lua common.lua
]]-- ]]--
@ -36,24 +36,24 @@ local function formspec(self, pos, meta)
"list[context;shift;1,0;7,1;]".. "list[context;shift;1,0;7,1;]"..
"image_button[9,0;1,1;techpack_warehouse_arrow_inv.png;shift;;true;false;]".. "image_button[9,0;1,1;techpack_warehouse_arrow_inv.png;shift;;true;false;]"..
"image_button[8,0;1,1;".. self:get_state_button_image(meta) ..";state_button;]".. "image_button[8,0;1,1;".. self:get_state_button_image(meta) ..";state_button;]"..
"image_button[0,1.4;1,1;techpack_warehouse_filter_inv.png;filter;;true;false;]".. "image_button[0,1.4;1,1;techpack_warehouse_filter_inv.png;filter;;true;false;]"..
"list[context;filter;1,1.4;8,1;]".. "list[context;filter;1,1.4;8,1;]"..
"image_button[9,1.4;1,1;techpack_warehouse_filter_inv.png;filter;;true;false;]".. "image_button[9,1.4;1,1;techpack_warehouse_filter_inv.png;filter;;true;false;]"..
"image_button[0,2.5;1,1;techpack_warehouse_inventory_inv.png;storage;;true;false;]".. "image_button[0,2.5;1,1;techpack_warehouse_inventory_inv.png;storage;;true;false;]"..
"list[context;main;1,2.5;8,1;]".. "list[context;main;1,2.5;8,1;]"..
"image_button[9,2.5;1,1;techpack_warehouse_inventory_inv.png;storage;;true;false;]".. "image_button[9,2.5;1,1;techpack_warehouse_inventory_inv.png;storage;;true;false;]"..
"image_button[0,3.6;1,1;techpack_warehouse_input_inv.png;input;;true;false;]".. "image_button[0,3.6;1,1;techpack_warehouse_input_inv.png;input;;true;false;]"..
"list[context;input;1,3.6;8,1;]".. "list[context;input;1,3.6;8,1;]"..
"image_button[9,3.6;1,1;techpack_warehouse_input_inv.png;input;;true;false;]".. "image_button[9,3.6;1,1;techpack_warehouse_input_inv.png;input;;true;false;]"..
"tooltip[shift;Pass-through storage for unconfigured items (turn on/off)]".. "tooltip[shift;Pass-through storage for unconfigured items (turn on/off)]"..
"tooltip[filter;Filter: To configure the 8 storages]".. "tooltip[filter;Filter: To configure the 8 storages]"..
"tooltip[storage;Storage: All items will be stored here]".. "tooltip[storage;Storage: All items will be stored here]"..
"tooltip[input;Input: Put items will be moved to the storage, if configured]".. "tooltip[input;Input: Put items will be moved to the storage, if configured]"..
"list[current_player;main;1,5.3;8,4;]".. "list[current_player;main;1,5.3;8,4;]"..
"listring[context;shift]".. "listring[context;shift]"..
"listring[current_player;main]".. "listring[current_player;main]"..
@ -64,12 +64,12 @@ local function move_to_main(pos, index)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
local main_stack = inv:get_stack("main", index) local main_stack = inv:get_stack("main", index)
local inp_stack = inv:get_stack("input", index) local inp_stack = inv:get_stack("input", index)
if inp_stack:get_name() ~= "" then if inp_stack:get_name() ~= "" then
local stack = ItemStack(inp_stack:get_name()) local stack = ItemStack(inp_stack:get_name())
stack:set_count(inp_stack:get_count() + main_stack:get_count()) stack:set_count(inp_stack:get_count() + main_stack:get_count())
inp_stack:clear() inp_stack:clear()
inv:set_stack("main", index, stack) inv:set_stack("main", index, stack)
inv:set_stack("input", index, inp_stack) inv:set_stack("input", index, inp_stack)
end end
@ -178,12 +178,12 @@ function techpack_warehouse.numbers_to_shift(self, meta, item)
Cache[number][idx] = items:get_name() Cache[number][idx] = items:get_name()
end end
end end
-- determine number to shift -- determine number to shift
local num_items = item:get_count() local num_items = item:get_count()
local inv_size = meta:get_int("inv_size") local inv_size = meta:get_int("inv_size")
local inv = meta:get_inventory() local inv = meta:get_inventory()
for idx, name in ipairs(Cache[number]) do for idx, name in ipairs(Cache[number]) do
if item_name == name then if item_name == name then
local stack_size = inv:get_stack("main", idx):get_count() local stack_size = inv:get_stack("main", idx):get_count()
@ -206,6 +206,10 @@ end
function techpack_warehouse.allow_metadata_inventory_put(self, pos, listname, index, stack, player) function techpack_warehouse.allow_metadata_inventory_put(self, pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return 0 return 0
elseif stack:get_wear() ~= 0 then
return 0
elseif stack:get_stack_max() == 1 then
return 0
end end
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
local main_stack = inv:get_stack("main", index) local main_stack = inv:get_stack("main", index)
@ -275,7 +279,7 @@ function techpack_warehouse.after_place_node(self, pos, placer, itemstack)
inv:set_size('main', 8) inv:set_size('main', 8)
inv:set_size('input', 8) inv:set_size('input', 8)
end end
function techpack_warehouse.on_timer(self, pos, elapsed) function techpack_warehouse.on_timer(self, pos, elapsed)
if tubelib.data_not_corrupted(pos) then if tubelib.data_not_corrupted(pos) then
local meta = M(pos) local meta = M(pos)
@ -292,7 +296,7 @@ function techpack_warehouse.on_timer(self, pos, elapsed)
local stack = inv:get_stack("shift", idx) local stack = inv:get_stack("shift", idx)
if stack:get_count() > 0 then if stack:get_count() > 0 then
if tubelib.push_items(pos, push_dir, stack, player_name) then if tubelib.push_items(pos, push_dir, stack, player_name) then
-- The effort is needed here for the case the -- The effort is needed here for the case the
-- pusher pushes into its own chest. -- pusher pushes into its own chest.
local num = stack:get_count() local num = stack:get_count()
stack = inv:get_stack("shift", idx) stack = inv:get_stack("shift", idx)
@ -308,12 +312,12 @@ function techpack_warehouse.on_timer(self, pos, elapsed)
else else
self.State:idle(pos, meta) self.State:idle(pos, meta)
end end
return self.State:is_active(meta) return self.State:is_active(meta)
end end
return false return false
end end
function techpack_warehouse.can_dig(self, pos) function techpack_warehouse.can_dig(self, pos)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
return inv:is_empty("main") and inv:is_empty("shift") return inv:is_empty("main") and inv:is_empty("shift")

@ -1,2 +1,3 @@
name=techpack_warehouse name=techpack_warehouse
description=Warehouse boxes
depends=tubelib,tubelib_addons1

@ -96,7 +96,7 @@ end)
minetest.after(60*59, update_mod_storage) minetest.after(60*59, update_mod_storage)
-- Key2Number will be generated at runtine -- Key2Number will be generated at runtine
local Key2Number = {} local Key2Number = {}
local Name2Name = {} -- translation table local Name2Name = {} -- translation table
@ -206,11 +206,12 @@ local function get_dest_node(pos, side)
local _,node = Tube:get_node(pos) local _,node = Tube:get_node(pos)
local dir = side_to_dir(side, node.param2) local dir = side_to_dir(side, node.param2)
local spos, sdir = Tube:get_connected_node_pos(pos, dir) local spos, sdir = Tube:get_connected_node_pos(pos, dir)
if not (spos and sdir) then return end
_,node = Tube:get_node(spos) _,node = Tube:get_node(spos)
local out_side = dir_to_side(tubelib2.Turn180Deg[sdir], node.param2) local out_side = dir_to_side(tubelib2.Turn180Deg[sdir], node.param2)
return spos, out_side, Name2Name[node.name] or node.name return spos, out_side, Name2Name[node.name] or node.name
end end
local function item_handling_node(name) local function item_handling_node(name)
local node_def = name and tubelib_NodeDef[name] local node_def = name and tubelib_NodeDef[name]
if node_def then if node_def then
@ -221,7 +222,7 @@ end
------------------------------------------------------------------- -------------------------------------------------------------------
-- API helper functions -- API helper functions
------------------------------------------------------------------- -------------------------------------------------------------------
-- Check the given list of numbers. -- Check the given list of numbers.
-- Returns true if number(s) is/are valid and point to real nodes. -- Returns true if number(s) is/are valid and point to real nodes.
function tubelib.check_numbers(numbers) function tubelib.check_numbers(numbers)
@ -234,7 +235,7 @@ function tubelib.check_numbers(numbers)
return true return true
end end
return false return false
end end
-- Function returns { pos, name } for the node on the given position number. -- Function returns { pos, name } for the node on the given position number.
function tubelib.get_node_info(dest_num) function tubelib.get_node_info(dest_num)
@ -242,7 +243,7 @@ function tubelib.get_node_info(dest_num)
return Number2Pos[dest_num] return Number2Pos[dest_num]
end end
return nil return nil
end end
-- Function returns the node number from the given position or -- Function returns the node number from the given position or
-- nil, if no node number for this position is assigned. -- nil, if no node number for this position is assigned.
@ -256,14 +257,14 @@ function tubelib.get_node_number(pos)
end end
end end
return nil return nil
end end
-- Function is used for available nodes with lost numbers, only. -- Function is used for available nodes with lost numbers, only.
function tubelib.get_new_number(pos, name) function tubelib.get_new_number(pos, name)
-- store position -- store position
local number = get_number(pos) local number = get_number(pos)
Number2Pos[number] = { Number2Pos[number] = {
pos = pos, pos = pos,
name = name, name = name,
} }
return number return number
@ -293,7 +294,7 @@ end
------------------------------------------------------------------- -------------------------------------------------------------------
-- Node construction/destruction functions -- Node construction/destruction functions
------------------------------------------------------------------- -------------------------------------------------------------------
-- Add node to the tubelib lists. -- Add node to the tubelib lists.
-- Function determines and returns the node position number, -- Function determines and returns the node position number,
-- needed for message communication. -- needed for message communication.
@ -301,10 +302,10 @@ function tubelib.add_node(pos, name)
if item_handling_node(name) then if item_handling_node(name) then
Tube:after_place_node(pos) Tube:after_place_node(pos)
end end
-- store position -- store position
local number = get_number(pos) local number = get_number(pos)
Number2Pos[number] = { Number2Pos[number] = {
pos = pos, pos = pos,
name = name, name = name,
} }
return number return number
@ -317,7 +318,7 @@ function tubelib.remove_node(pos)
if Number2Pos[number] then if Number2Pos[number] then
name = Number2Pos[number].name name = Number2Pos[number].name
Number2Pos[number] = { Number2Pos[number] = {
pos = pos, pos = pos,
name = nil, name = nil,
time = minetest.get_day_count() -- used for reservation timeout time = minetest.get_day_count() -- used for reservation timeout
} }
@ -352,11 +353,11 @@ function tubelib.register_node(name, add_names, node_definition)
for _,n in ipairs(add_names) do for _,n in ipairs(add_names) do
Name2Name[n] = name Name2Name[n] = name
end end
if node_definition.on_pull_item or node_definition.on_push_item or if node_definition.on_pull_item or node_definition.on_push_item or
node_definition.is_pusher then node_definition.is_pusher then
Tube:add_secondary_node_names({name}) Tube:add_secondary_node_names({name})
Tube:add_secondary_node_names(add_names) Tube:add_secondary_node_names(add_names)
tubelib.KnownNodes[name] = true tubelib.KnownNodes[name] = true
for _,n in ipairs(add_names) do for _,n in ipairs(add_names) do
tubelib.KnownNodes[n] = true tubelib.KnownNodes[n] = true
@ -387,7 +388,7 @@ function tubelib.send_message(numbers, placer_name, clicker_name, topic, payload
end end
end end
end end
end end
function tubelib.send_request(number, topic, payload) function tubelib.send_request(number, topic, payload)
if Number2Pos[number] and Number2Pos[number].name then if Number2Pos[number] and Number2Pos[number].name then
@ -397,7 +398,7 @@ function tubelib.send_request(number, topic, payload)
end end
end end
return false return false
end end
-- for defect nodes -- for defect nodes
function tubelib.repair_node(pos) function tubelib.repair_node(pos)
@ -426,10 +427,10 @@ function tubelib.push_items(pos, side, items, player_name)
local npos, nside, name = get_dest_node(pos, side) local npos, nside, name = get_dest_node(pos, side)
if npos == nil then return end if npos == nil then return end
if tubelib_NodeDef[name] and tubelib_NodeDef[name].on_push_item then if tubelib_NodeDef[name] and tubelib_NodeDef[name].on_push_item then
return tubelib_NodeDef[name].on_push_item(npos, nside, items, player_name) return tubelib_NodeDef[name].on_push_item(npos, nside, items, player_name)
elseif name == "air" then elseif name == "air" then
minetest.add_item(npos, items) minetest.add_item(npos, items)
return true return true
end end
return false return false
end end
@ -442,7 +443,7 @@ function tubelib.unpull_items(pos, side, items, player_name)
end end
return false return false
end end
function tubelib.pull_stack(pos, side, player_name) function tubelib.pull_stack(pos, side, player_name)
local npos, nside, name = get_dest_node(pos, side) local npos, nside, name = get_dest_node(pos, side)
if npos == nil then return end if npos == nil then return end
@ -493,7 +494,7 @@ function tubelib.get_this_item(meta, listname, list_number, num_items)
if inv:is_empty(listname) then if inv:is_empty(listname) then
return nil return nil
end end
if num_items == nil then num_items = 1 end if num_items == nil then num_items = 1 end
local items = inv:get_stack(listname, list_number) local items = inv:get_stack(listname, list_number)
if items:get_count() > 0 then if items:get_count() > 0 then
@ -548,7 +549,7 @@ function tubelib.get_stack(meta, listname)
taken:set_count(taken:get_count() + 1) taken:set_count(taken:get_count() + 1)
return taken return taken
end end
return item return item
end end
-- Return "full", "loaded", or "empty" depending -- Return "full", "loaded", or "empty" depending
@ -567,7 +568,7 @@ function tubelib.fuelstate(meta, listname, item)
return "loaded" return "loaded"
end end
end end
-- Return "full", "loaded", or "empty" depending -- Return "full", "loaded", or "empty" depending
-- on the inventory load. -- on the inventory load.
-- Full is returned, when no empty stack is available. -- Full is returned, when no empty stack is available.
@ -682,8 +683,8 @@ local function data_maintenance()
end end
minetest.log("info", "[Tubelib] Data base shrank from "..cnt1.." to "..cnt2.." nodes") minetest.log("info", "[Tubelib] Data base shrank from "..cnt1.." to "..cnt2.." nodes")
minetest.log("info", "[Tubelib] Data maintenance finished") minetest.log("info", "[Tubelib] Data maintenance finished")
end end
generate_Key2Number() generate_Key2Number()
-- maintain data after 2 seconds -- maintain data after 2 seconds

@ -13,6 +13,15 @@ minetest.register_node("tubelib:defect_dummy", {
is_ground_content = false, is_ground_content = false,
}) })
local reported_machines = {}
local function report(pos)
reported_machines[minetest.pos_to_string(pos)] = true
end
local function already_reported(pos)
local key = minetest.pos_to_string(pos)
return reported_machines[key]
end
function tubelib.data_not_corrupted(pos) function tubelib.data_not_corrupted(pos)
if minetest.pos_to_string(pos) ~= minetest.get_meta(pos):get_string("my_pos") then if minetest.pos_to_string(pos) ~= minetest.get_meta(pos):get_string("my_pos") then
@ -29,23 +38,27 @@ function tubelib.data_not_corrupted(pos)
number = meta:get_string("own_number") number = meta:get_string("own_number")
end end
if number == "" then if number == "" then
tubelib.remove_node(pos) if not already_reported(pos) then
minetest.set_node(pos, {name = "tubelib:defect_dummy"}) minetest.log('error', ('[tubelib] machine @ %s has no number'):format(minetest.pos_to_string(pos)))
meta:from_table(nil) report(pos)
return false end
end end
-- node moved? -- node moved?
local info = tubelib.get_node_info(number) local info = tubelib.get_node_info(number)
if not info or not vector.equals(info.pos, pos) then if not info or not vector.equals(info.pos, pos) then
if not already_reported(pos) then
if not info then
minetest.log('error', ('[tubelib] machine @ %s has no info'):format(minetest.pos_to_string(pos)))
else
minetest.log('error', ('[tubelib] machine @ %s thinks it is at %s'):format(minetest.pos_to_string(pos), minetest.pos_to_string(info.pos)))
end
report(pos)
end
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
number = tubelib.get_new_number(pos, node.name) number = tubelib.get_new_number(pos, node.name)
meta:set_string("tubelib_number", number) meta:set_string("tubelib_number", number)
-- tubelib.remove_node(pos)
-- minetest.set_node(pos, {name = "tubelib:defect_dummy"})
-- meta:from_table(nil)
-- return false
end end
minetest.get_meta(pos):get_string("my_pos", minetest.pos_to_string(pos)) minetest.get_meta(pos):get_string("my_pos", minetest.pos_to_string(pos))
end end
return true return true
end end

@ -72,7 +72,7 @@ local State = tubelib.NodeStates:new({
-- Return a key/value table with all items and the corresponding stack numbers -- Return a key/value table with all items and the corresponding stack numbers
local function invlist_content_as_kvlist(list) local function invlist_content_as_kvlist(list)
local res = {} local res = {}
for idx,items in ipairs(list) do for idx,items in ipairs(list or {}) do
local name = items:get_name() local name = items:get_name()
if name ~= "" then if name ~= "" then
res[name] = idx res[name] = idx

@ -1 +1,3 @@
name=tubelib name=tubelib
description=Tubes Mod with message communication interface as basis for further technique Mods.
depends=default,tubelib2,basic_materials

@ -1,8 +1,10 @@
tubelib tubelib
default default
bucket bucket
stairs?
moreores?
farming?
ethereal? ethereal?
farming?
moreores?
moretrees?
skytest?
stairs?
unified_inventory? unified_inventory?

@ -9,7 +9,7 @@
See LICENSE.txt for more information See LICENSE.txt for more information
detector.lua: detector.lua:
]]-- ]]--
@ -75,11 +75,11 @@ minetest.register_node("tubelib_addons1:detector", {
"button_exit[2,2;3,1;exit;Save]") "button_exit[2,2;3,1;exit;Save]")
end end
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
tubelib.remove_node(pos) tubelib.remove_node(pos)
end, end,
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
@ -108,7 +108,7 @@ minetest.register_node("tubelib_addons1:detector_active", {
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
tubelib.remove_node(pos) tubelib.remove_node(pos)
end, end,
paramtype = "light", paramtype = "light",
light_source = 2, light_source = 2,
sunlight_propagates = true, sunlight_propagates = true,
@ -140,5 +140,5 @@ tubelib.register_node("tubelib_addons1:detector", {"tubelib_addons1:detector_act
return false return false
end, end,
is_pusher = true, -- is a pulling/pushing node is_pusher = true, -- is a pulling/pushing node
}) })

@ -7,9 +7,9 @@
LGPLv2.1+ LGPLv2.1+
See LICENSE.txt for more information See LICENSE.txt for more information
fermenter.lua fermenter.lua
The Fermenter converts 3 leave items of any kind into one Bio Gas item, The Fermenter converts 3 leave items of any kind into one Bio Gas item,
needed by the Reformer to produce Bio Fuel. needed by the Reformer to produce Bio Fuel.
@ -97,7 +97,8 @@ local function place_top(pos, facedir, placer)
return false return false
end end
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
if node.name ~= "air" then local def = minetest.registered_nodes[node.name]
if not def or not def.buildable_to then
return false return false
end end
minetest.add_node(pos, {name="tubelib_addons1:fermenter_top", param2=facedir}) minetest.add_node(pos, {name="tubelib_addons1:fermenter_top", param2=facedir})
@ -107,13 +108,13 @@ end
local function convert_leaves_to_biogas(pos, meta) local function convert_leaves_to_biogas(pos, meta)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local biogas = ItemStack("tubelib_addons1:biogas") local biogas = ItemStack("tubelib_addons1:biogas")
-- Not enough output space? -- Not enough output space?
if not inv:room_for_item("dst", biogas) then if not inv:room_for_item("dst", biogas) then
State:blocked(pos, meta) State:blocked(pos, meta)
return return
end end
-- take NUM_LEAVES items -- take NUM_LEAVES items
local items = {} local items = {}
for i = 1, NUM_LEAVES do for i = 1, NUM_LEAVES do
@ -128,14 +129,14 @@ local function convert_leaves_to_biogas(pos, meta)
end end
end end
end end
-- put result into dst inventory -- put result into dst inventory
if #items == NUM_LEAVES then if #items == NUM_LEAVES then
inv:add_item("dst", biogas) inv:add_item("dst", biogas)
State:keep_running(pos, meta, COUNTDOWN_TICKS) State:keep_running(pos, meta, COUNTDOWN_TICKS)
return return
end end
-- put leaves back to src inventory -- put leaves back to src inventory
for i = 1, #items do for i = 1, #items do
inv:add_item("src", items[i]) inv:add_item("src", items[i])
@ -176,22 +177,24 @@ minetest.register_node("tubelib_addons1:fermenter", {
type = "fixed", type = "fixed",
fixed = { -8/16, -8/16, -8/16, 8/16, 24/16, 8/16 }, fixed = { -8/16, -8/16, -8/16, 8/16, 24/16, 8/16 },
}, },
on_construct = function(pos) on_construct = function(pos)
local meta = M(pos) local meta = M(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size('src', 9) inv:set_size('src', 9)
inv:set_size('dst', 9) inv:set_size('dst', 9)
end, end,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local facedir = minetest.dir_to_facedir(placer:get_look_dir(), false) local facedir = minetest.dir_to_facedir(placer:get_look_dir(), false)
if place_top({x=pos.x, y=pos.y+1, z=pos.z}, facedir, placer) == false then if place_top({x=pos.x, y=pos.y+1, z=pos.z}, facedir, placer) then
local number = tubelib.add_node(pos, "tubelib_addons1:fermenter")
State:node_init(pos, number)
else
minetest.remove_node(pos) minetest.remove_node(pos)
return minetest.chat_send_player(placer:get_player_name(), "Fermenter will not fit there")
return true
end end
local number = tubelib.add_node(pos, "tubelib_addons1:fermenter")
State:node_init(pos, number)
end, end,
-- the fermenter needs 'on_dig' to be able to remove the upper node -- the fermenter needs 'on_dig' to be able to remove the upper node
@ -208,7 +211,7 @@ minetest.register_node("tubelib_addons1:fermenter", {
tubelib.remove_node(pos) tubelib.remove_node(pos)
State:after_dig_node(pos, oldnode, oldmetadata, digger) State:after_dig_node(pos, oldnode, oldmetadata, digger)
end, end,
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
on_timer = keep_running, on_timer = keep_running,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
@ -242,23 +245,25 @@ minetest.register_node("tubelib_addons1:fermenter_defect", {
type = "fixed", type = "fixed",
fixed = { -8/16, -8/16, -8/16, 8/16, 24/16, 8/16 }, fixed = { -8/16, -8/16, -8/16, 8/16, 24/16, 8/16 },
}, },
on_construct = function(pos) on_construct = function(pos)
local meta = M(pos) local meta = M(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size('src', 9) inv:set_size('src', 9)
inv:set_size('dst', 9) inv:set_size('dst', 9)
end, end,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local facedir = minetest.dir_to_facedir(placer:get_look_dir(), false) local facedir = minetest.dir_to_facedir(placer:get_look_dir(), false)
if place_top({x=pos.x, y=pos.y+1, z=pos.z}, facedir, placer) == false then if place_top({x=pos.x, y=pos.y+1, z=pos.z}, facedir, placer) then
local number = tubelib.add_node(pos, "tubelib_addons1:fermenter")
State:node_init(pos, number)
State:defect(pos, M(pos))
else
minetest.remove_node(pos) minetest.remove_node(pos)
return minetest.chat_send_player(placer:get_player_name(), "Fermenter will not fit there")
return true
end end
local number = tubelib.add_node(pos, "tubelib_addons1:fermenter")
State:node_init(pos, number)
State:defect(pos, M(pos))
end, end,
-- the fermenter needs 'on_dig' to be able to remove the upper node -- the fermenter needs 'on_dig' to be able to remove the upper node
@ -274,7 +279,7 @@ minetest.register_node("tubelib_addons1:fermenter_defect", {
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
tubelib.remove_node(pos) tubelib.remove_node(pos)
end, end,
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move, allow_metadata_inventory_move = allow_metadata_inventory_move,
@ -327,14 +332,14 @@ if minetest.global_exists("unified_inventory") then
height = 2, height = 2,
}) })
unified_inventory.register_craft({ unified_inventory.register_craft({
items = {"group:leaves", "group:leaves"}, items = {"group:leaves", "group:leaves"},
output = "tubelib_addons1:biogas", output = "tubelib_addons1:biogas",
type = "fermenting" type = "fermenting"
}) })
unified_inventory.register_craft({ unified_inventory.register_craft({
items = {"tubelib_addons1:biogas", "tubelib_addons1:biogas", items = {"tubelib_addons1:biogas", "tubelib_addons1:biogas",
"tubelib_addons1:biogas", "tubelib_addons1:biogas"}, "tubelib_addons1:biogas", "tubelib_addons1:biogas"},
output = "tubelib_addons1:biofuel", output = "tubelib_addons1:biofuel",
type = "reforming" type = "reforming"
}) })
end end
@ -373,4 +378,4 @@ tubelib.register_node("tubelib_addons1:fermenter", {"tubelib_addons1:fermenter_d
on_node_repair = function(pos) on_node_repair = function(pos)
return State:on_node_repair(pos) return State:on_node_repair(pos)
end, end,
}) })

@ -1 +1,4 @@
name=tubelib_addons1 name=tubelib_addons1
description=Tubelib Extension with Mining, Farming, and Crafting nodes
depends=tubelib,default,bucket
optional_depends=ethereal,farming,moreores,moretrees,skytest,stairs,unified_inventory

@ -9,10 +9,10 @@
See LICENSE.txt for more information See LICENSE.txt for more information
reformer.lua reformer.lua
The Reformer converts 4 Bio Gas items into one Bio Fuel item, The Reformer converts 4 Bio Gas items into one Bio Fuel item,
needed by Harvester and Quarry. needed by Harvester and Quarry.
]]-- ]]--
-- for lazy programmers -- for lazy programmers
@ -91,7 +91,8 @@ local function place_top(pos, facedir, placer)
return false return false
end end
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
if node.name ~= "air" then local def = minetest.registered_nodes[node.name]
if not def or not def.buildable_to then
return false return false
end end
minetest.add_node(pos, {name="tubelib_addons1:reformer_top", param2=facedir}) minetest.add_node(pos, {name="tubelib_addons1:reformer_top", param2=facedir})
@ -172,24 +173,26 @@ minetest.register_node("tubelib_addons1:reformer", {
type = "fixed", type = "fixed",
fixed = { -8/16, -8/16, -8/16, 8/16, 24/16, 8/16 }, fixed = { -8/16, -8/16, -8/16, 8/16, 24/16, 8/16 },
}, },
on_construct = function(pos) on_construct = function(pos)
local meta = M(pos) local meta = M(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size('src', 9) inv:set_size('src', 9)
inv:set_size('dst', 9) inv:set_size('dst', 9)
end, end,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local facedir = minetest.dir_to_facedir(placer:get_look_dir(), false) local facedir = minetest.dir_to_facedir(placer:get_look_dir(), false)
if place_top({x=pos.x, y=pos.y+1, z=pos.z}, facedir, placer) == false then if place_top({x=pos.x, y=pos.y+1, z=pos.z}, facedir, placer) then
local number = tubelib.add_node(pos, "tubelib_addons1:reformer")
State:node_init(pos, number)
else
minetest.remove_node(pos) minetest.remove_node(pos)
return minetest.chat_send_player(placer:get_player_name(), "Reformer will not fit there")
return true
end end
local number = tubelib.add_node(pos, "tubelib_addons1:reformer")
State:node_init(pos, number)
end, end,
-- the reformer needs 'on_dig' to be able to remove the upper node -- the reformer needs 'on_dig' to be able to remove the upper node
on_dig = function(pos, node, puncher, pointed_thing) on_dig = function(pos, node, puncher, pointed_thing)
local meta = M(pos) local meta = M(pos)
@ -199,12 +202,12 @@ minetest.register_node("tubelib_addons1:reformer", {
minetest.remove_node({x=pos.x, y=pos.y+1, z=pos.z}) minetest.remove_node({x=pos.x, y=pos.y+1, z=pos.z})
end end
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
tubelib.remove_node(pos) tubelib.remove_node(pos)
State:after_dig_node(pos, oldnode, oldmetadata, digger) State:after_dig_node(pos, oldnode, oldmetadata, digger)
end, end,
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
on_timer = keep_running, on_timer = keep_running,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
@ -238,23 +241,25 @@ minetest.register_node("tubelib_addons1:reformer_defect", {
type = "fixed", type = "fixed",
fixed = { -8/16, -8/16, -8/16, 8/16, 24/16, 8/16 }, fixed = { -8/16, -8/16, -8/16, 8/16, 24/16, 8/16 },
}, },
on_construct = function(pos) on_construct = function(pos)
local meta = M(pos) local meta = M(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size('src', 9) inv:set_size('src', 9)
inv:set_size('dst', 9) inv:set_size('dst', 9)
end, end,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local facedir = minetest.dir_to_facedir(placer:get_look_dir(), false) local facedir = minetest.dir_to_facedir(placer:get_look_dir(), false)
if place_top({x=pos.x, y=pos.y+1, z=pos.z}, facedir, placer) == false then if place_top({x=pos.x, y=pos.y+1, z=pos.z}, facedir, placer) then
local number = tubelib.add_node(pos, "tubelib_addons1:reformer")
State:node_init(pos, number)
State:defect(pos, M(pos))
else
minetest.remove_node(pos) minetest.remove_node(pos)
return minetest.chat_send_player(placer:get_player_name(), "Reformer will not fit there")
return true
end end
local number = tubelib.add_node(pos, "tubelib_addons1:reformer")
State:node_init(pos, number)
State:defect(pos, M(pos))
end, end,
-- the reformer needs 'on_dig' to be able to remove the upper node -- the reformer needs 'on_dig' to be able to remove the upper node
@ -266,11 +271,11 @@ minetest.register_node("tubelib_addons1:reformer_defect", {
minetest.remove_node({x=pos.x, y=pos.y+1, z=pos.z}) minetest.remove_node({x=pos.x, y=pos.y+1, z=pos.z})
end end
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
tubelib.remove_node(pos) tubelib.remove_node(pos)
end, end,
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move, allow_metadata_inventory_move = allow_metadata_inventory_move,
@ -351,4 +356,4 @@ tubelib.register_node("tubelib_addons1:reformer", {"tubelib_addons1:reformer_def
on_node_repair = function(pos) on_node_repair = function(pos)
return State:on_node_repair(pos) return State:on_node_repair(pos)
end, end,
}) })

@ -1 +1,4 @@
name=tubelib_addons2 name=tubelib_addons2
description=Tubelib Extension for switching/controlling tasks
depends=default,tubelib,basic_materials
optional_depends=mesecons,unifieddyes

@ -1 +1,3 @@
name=tubelib_addons3 name=tubelib_addons3
description=Tubelib Extension with High Performance nodes
depends=tubelib,tubelib_addons1,default