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

@ -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)

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

@ -206,6 +206,7 @@ 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

@ -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,21 +38,25 @@ 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

@ -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?

@ -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})
@ -186,12 +187,14 @@ minetest.register_node("tubelib_addons1:fermenter", {
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
minetest.remove_node(pos)
return
end
local number = tubelib.add_node(pos, "tubelib_addons1:fermenter") local number = tubelib.add_node(pos, "tubelib_addons1:fermenter")
State:node_init(pos, number) State:node_init(pos, number)
else
minetest.remove_node(pos)
minetest.chat_send_player(placer:get_player_name(), "Fermenter will not fit there")
return true
end
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
@ -252,13 +255,15 @@ minetest.register_node("tubelib_addons1:fermenter_defect", {
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
minetest.remove_node(pos)
return
end
local number = tubelib.add_node(pos, "tubelib_addons1:fermenter") local number = tubelib.add_node(pos, "tubelib_addons1:fermenter")
State:node_init(pos, number) State:node_init(pos, number)
State:defect(pos, M(pos)) State:defect(pos, M(pos))
else
minetest.remove_node(pos)
minetest.chat_send_player(placer:get_player_name(), "Fermenter will not fit there")
return true
end
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

@ -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

@ -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})
@ -182,12 +183,14 @@ minetest.register_node("tubelib_addons1:reformer", {
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
minetest.remove_node(pos)
return
end
local number = tubelib.add_node(pos, "tubelib_addons1:reformer") local number = tubelib.add_node(pos, "tubelib_addons1:reformer")
State:node_init(pos, number) State:node_init(pos, number)
else
minetest.remove_node(pos)
minetest.chat_send_player(placer:get_player_name(), "Reformer will not fit there")
return true
end
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
@ -248,13 +251,15 @@ minetest.register_node("tubelib_addons1:reformer_defect", {
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
minetest.remove_node(pos)
return
end
local number = tubelib.add_node(pos, "tubelib_addons1:reformer") local number = tubelib.add_node(pos, "tubelib_addons1:reformer")
State:node_init(pos, number) State:node_init(pos, number)
State:defect(pos, M(pos)) State:defect(pos, M(pos))
else
minetest.remove_node(pos)
minetest.chat_send_player(placer:get_player_name(), "Reformer will not fit there")
return true
end
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

@ -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