mirror of
https://github.com/joe7575/techpack.git
synced 2024-11-22 07:13:48 +01:00
bug fixes and improvements
This commit is contained in:
parent
58718c2f0f
commit
021f5c450c
@ -3,7 +3,7 @@
|
||||
Gravel Sieve Mod
|
||||
================
|
||||
|
||||
v1.07 by JoSt
|
||||
v1.09 by JoSt
|
||||
Derived from the work of celeron55, Perttu Ahola (furnace)
|
||||
Pipeworks support added by FiftySix
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
2018-01-01 V1.06 * Hopper support added
|
||||
2018-01-02 V1.07 * changed to registered ores
|
||||
2018-02-09 V1.08 * Pipeworks support added, bugfix for issue #7
|
||||
2018-12-28 V1.09 * Ore probability calculation changed (thanks to obl3pplifp)
|
||||
]]--
|
||||
|
||||
gravelsieve = {
|
||||
@ -70,28 +71,28 @@ local function add_ores()
|
||||
and drop ~= item.ore
|
||||
and drop ~= ""
|
||||
and item.ore_type == "scatter"
|
||||
and item.wherein == "default:stone"
|
||||
and item.clust_scarcity ~= nil and item.clust_scarcity > 0
|
||||
and item.clust_size ~= nil and item.clust_size > 0 then
|
||||
local probability = item.clust_scarcity / item.clust_size /
|
||||
PROBABILITY_FACTOR * gravelsieve.ore_rarity
|
||||
probability = math.floor(probability)
|
||||
if probability > 20 then
|
||||
and item.clust_num_ores ~= nil and item.clust_num_ores > 0
|
||||
and item.y_max ~= nil and item.y_min ~= nil then
|
||||
local probability = (gravelsieve.ore_rarity / PROBABILITY_FACTOR) * item.clust_scarcity /
|
||||
(item.clust_num_ores * ((item.y_max - item.y_min) / 65535))
|
||||
if gravelsieve.ore_probability[drop] == nil then
|
||||
gravelsieve.ore_probability[drop] = probability
|
||||
else
|
||||
gravelsieve.ore_probability[drop] =
|
||||
math.min(gravelsieve.ore_probability[drop], probability)
|
||||
end
|
||||
-- harmonic sum
|
||||
gravelsieve.ore_probability[drop] = 1.0 / ((1.0 / gravelsieve.ore_probability[drop]) +
|
||||
(1.0 / probability))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local overall_probability = 0.0
|
||||
for name,probability in pairs(gravelsieve.ore_probability) do
|
||||
print(string.format("[gravelsieve] %-32s %u", name, probability))
|
||||
minetest.log("info", string.format("[gravelsieve] %-32s %u", name, probability))
|
||||
overall_probability = overall_probability + 1.0/probability
|
||||
end
|
||||
print(string.format("[gravelsieve] Overall probability %g", overall_probability))
|
||||
minetest.log("info", string.format("[gravelsieve] Overall probability %g", overall_probability))
|
||||
end
|
||||
|
||||
minetest.after(1, add_ores)
|
||||
|
@ -26,6 +26,7 @@ local storage = minetest.get_mod_storage()
|
||||
local NextNumber = minetest.deserialize(storage:get_string("NextNumber")) or 1
|
||||
local Version = minetest.deserialize(storage:get_string("Version")) or 1
|
||||
local Number2Pos = minetest.deserialize(storage:get_string("Number2Pos")) or {}
|
||||
local FreeNumbers = {}
|
||||
|
||||
local function update_mod_storage()
|
||||
minetest.log("action", "[Tubelib] Store data...")
|
||||
@ -70,11 +71,18 @@ end
|
||||
-- Determine position related node number for addressing purposes
|
||||
local function get_number(pos)
|
||||
local key = get_key_str(pos)
|
||||
local num
|
||||
if not Key2Number[key] then
|
||||
num = table.remove(FreeNumbers)
|
||||
if not num then
|
||||
Key2Number[key] = NextNumber
|
||||
NextNumber = NextNumber + 1
|
||||
num = string.format("%.04u", Key2Number[key])
|
||||
end
|
||||
return string.format("%.04u", Key2Number[key])
|
||||
else
|
||||
num = string.format("%.04u", Key2Number[key])
|
||||
end
|
||||
return num
|
||||
end
|
||||
|
||||
local function generate_Key2Number()
|
||||
@ -525,6 +533,14 @@ local function data_maintenance()
|
||||
end
|
||||
end
|
||||
end
|
||||
-- collect unused node numbers
|
||||
for idx = 1,NextNumber-1 do
|
||||
--FreeNumbers
|
||||
local num = string.format("%.04u", idx)
|
||||
if not Number2Pos[num] then
|
||||
FreeNumbers[#FreeNumbers+1] = num
|
||||
end
|
||||
end
|
||||
print("[Tubelib] Data maintenance finished")
|
||||
end
|
||||
|
||||
|
@ -52,9 +52,10 @@ local function calc_area(pos)
|
||||
end
|
||||
|
||||
local function add_pos(pos, player)
|
||||
local pos1 = calc_area(pos)
|
||||
local lPos = minetest.deserialize(player:get_attribute("tubelib_forceload_blocks")) or {}
|
||||
if not in_list(lPos, pos) and #lPos < tubelib.max_num_forceload_blocks then
|
||||
lPos[#lPos+1] = pos
|
||||
if not in_list(lPos, pos1) and #lPos < tubelib.max_num_forceload_blocks then
|
||||
lPos[#lPos+1] = pos1
|
||||
player:set_attribute("tubelib_forceload_blocks", minetest.serialize(lPos))
|
||||
return true
|
||||
end
|
||||
@ -62,9 +63,9 @@ local function add_pos(pos, player)
|
||||
end
|
||||
|
||||
local function del_pos(pos, player)
|
||||
local pos1 = calc_area(pos)
|
||||
local lPos = minetest.deserialize(player:get_attribute("tubelib_forceload_blocks")) or {}
|
||||
lPos = remove_list_elem(lPos, pos)
|
||||
lPos = remove_list_elem(lPos, pos)
|
||||
lPos = remove_list_elem(lPos, pos1)
|
||||
player:set_attribute("tubelib_forceload_blocks", minetest.serialize(lPos))
|
||||
end
|
||||
|
||||
@ -79,6 +80,27 @@ local function get_data(pos, player)
|
||||
return pos1, pos2, num, max
|
||||
end
|
||||
|
||||
local function formspec(player)
|
||||
local lPos = get_pos_list(player)
|
||||
local tRes = {}
|
||||
tRes[1] = "size[7,9]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"label[0,0;List of your Forceload Blocks:]"
|
||||
|
||||
for idx,pos in ipairs(lPos) do
|
||||
local pos1, pos2 = calc_area(pos)
|
||||
local ypos = 0.2 + idx * 0.4
|
||||
tRes[#tRes+1] = "label[0,"..ypos..";"..idx.."]"
|
||||
tRes[#tRes+1] = "label[0.8,"..ypos..";"..S(pos1).."]"
|
||||
tRes[#tRes+1] = "label[3.2,"..ypos..";to]"
|
||||
tRes[#tRes+1] = "label[4,"..ypos..";"..S(pos2).."]"
|
||||
end
|
||||
return table.concat(tRes)
|
||||
end
|
||||
|
||||
|
||||
minetest.register_node("tubelib:forceload", {
|
||||
description = "Tubelib Forceload Block",
|
||||
tiles = {
|
||||
@ -107,7 +129,7 @@ minetest.register_node("tubelib:forceload", {
|
||||
tubelib.mark_region(placer:get_player_name(), pos1, pos2)
|
||||
M(pos):set_string("owner", placer:get_player_name())
|
||||
else
|
||||
chat(placer, "Max. number of Forceload Blocks reached!")
|
||||
chat(placer, "Area already loaded or max. number of Forceload Blocks reached!")
|
||||
minetest.remove_node(pos)
|
||||
return itemstack
|
||||
end
|
||||
@ -119,6 +141,14 @@ minetest.register_node("tubelib:forceload", {
|
||||
tubelib.unmark_region(oldmetadata.fields.owner)
|
||||
end,
|
||||
|
||||
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
||||
if M(pos):get_string("owner") == clicker:get_player_name() or
|
||||
minetest.check_player_privs(clicker:get_player_name(), "server") then
|
||||
local s = formspec(clicker)
|
||||
minetest.show_formspec(clicker:get_player_name(), "tubelib:forceload", s)
|
||||
end
|
||||
end,
|
||||
|
||||
on_punch = function(pos, node, puncher, pointed_thing)
|
||||
local pos1, pos2 = calc_area(pos)
|
||||
tubelib.switch_region(puncher:get_player_name(), pos1, pos2)
|
||||
|
@ -92,6 +92,8 @@ function NodeStates:new(attr)
|
||||
node_name_defect = attr.node_name_defect,
|
||||
infotext_name = attr.infotext_name,
|
||||
start_condition_fullfilled = attr.start_condition_fullfilled or start_condition_fullfilled,
|
||||
on_start = attr.on_start,
|
||||
on_stop = attr.on_stop,
|
||||
}
|
||||
if attr.aging_factor then
|
||||
o.aging_level1 = attr.aging_factor * tubelib.machine_aging_value
|
||||
@ -125,7 +127,11 @@ function NodeStates:node_init(pos, number)
|
||||
end
|
||||
|
||||
function NodeStates:stop(pos, meta)
|
||||
if meta:get_int("tubelib_state") ~= DEFECT then
|
||||
local state = meta:get_int("tubelib_state")
|
||||
if state ~= DEFECT then
|
||||
if self.on_stop then
|
||||
self.on_stop(pos, meta, state)
|
||||
end
|
||||
meta:set_int("tubelib_state", STOPPED)
|
||||
if self.node_name_passive then
|
||||
local node = minetest.get_node(pos)
|
||||
@ -151,6 +157,9 @@ function NodeStates:start(pos, meta, called_from_on_timer)
|
||||
if not self.start_condition_fullfilled(pos, meta) then
|
||||
return false
|
||||
end
|
||||
if self.on_start then
|
||||
self.on_start(pos, meta, state)
|
||||
end
|
||||
meta:set_int("tubelib_state", RUNNING)
|
||||
if called_from_on_timer then
|
||||
-- timer has to be stopped once to be able to be restarted
|
||||
|
@ -32,6 +32,13 @@ local STANDBY_TICKS = 4 -- used for blocked state
|
||||
local COUNTDOWN_TICKS = 2
|
||||
local OFFSET = 5 -- for uneven terrains
|
||||
|
||||
-- start on top of the base block
|
||||
local function working_start_pos(pos)
|
||||
local working_pos = table.copy(pos)
|
||||
working_pos.y = working_pos.y + MAX_HEIGHT
|
||||
return working_pos
|
||||
end
|
||||
|
||||
local State = tubelib.NodeStates:new({
|
||||
node_name_passive = "tubelib_addons1:harvester_base",
|
||||
node_name_defect = "tubelib_addons1:harvester_defect",
|
||||
@ -40,6 +47,12 @@ local State = tubelib.NodeStates:new({
|
||||
standby_ticks = STANDBY_TICKS,
|
||||
has_item_meter = true,
|
||||
aging_factor = 15,
|
||||
on_start = function(pos, meta, oldstate)
|
||||
local this = minetest.deserialize(meta:get_string("this"))
|
||||
this.idx = 0
|
||||
this.working_pos = working_start_pos(pos)
|
||||
meta:set_string("this", minetest.serialize(this))
|
||||
end,
|
||||
})
|
||||
|
||||
local Radius2Idx = {[4]=1 ,[6]=2, [8]=3, [10]=4, [12]=5, [14]=6, [16]=7}
|
||||
@ -118,19 +131,11 @@ local function allow_metadata_inventory_take(pos, listname, index, stack, player
|
||||
return stack:get_count()
|
||||
end
|
||||
|
||||
-- start on top of the base block
|
||||
local function working_start_pos(pos)
|
||||
local working_pos = table.copy(pos)
|
||||
working_pos.y = working_pos.y + MAX_HEIGHT
|
||||
return working_pos
|
||||
end
|
||||
|
||||
local function get_next_pos(old_pos, idx)
|
||||
local facedir = WorkingSteps[idx]
|
||||
return vector.add(old_pos, core.facedir_to_dir(facedir))
|
||||
end
|
||||
|
||||
|
||||
-- Remove saplings lying arround
|
||||
local function remove_all_sapling_items(pos)
|
||||
for _, object in pairs(minetest.get_objects_inside_radius(pos, 4)) do
|
||||
@ -241,11 +246,11 @@ end
|
||||
local function keep_running(pos, elapsed)
|
||||
local meta = M(pos)
|
||||
local this = minetest.deserialize(meta:get_string("this"))
|
||||
this.num_items = 0
|
||||
|
||||
if not_blocked(pos, this, meta) then
|
||||
if check_fuel(pos, this, meta) then
|
||||
if calc_new_pos(pos, this, meta) then
|
||||
this.num_items = 0
|
||||
if harvest_field(this, meta) then
|
||||
meta:set_string("this", minetest.serialize(this))
|
||||
meta:set_string("infotext",
|
||||
@ -287,16 +292,7 @@ local function on_receive_fields(pos, formname, fields, player)
|
||||
this.endless = fields.endless == "true" and 1 or 0
|
||||
end
|
||||
|
||||
if fields.state_button ~= nil then
|
||||
local state = State:get_state(meta)
|
||||
if state == tubelib.STOPPED or state == tubelib.STANDBY or state == tubelib.BLOCKED then
|
||||
this.idx = 0
|
||||
this.working_pos = working_start_pos(pos)
|
||||
State:start(pos, meta)
|
||||
elseif state == tubelib.RUNNING or state == tubelib.FAULT then
|
||||
State:stop(pos, meta)
|
||||
end
|
||||
end
|
||||
State:state_button_event(pos, fields)
|
||||
|
||||
meta:set_string("this", minetest.serialize(this))
|
||||
end
|
||||
|
@ -43,6 +43,12 @@ local State = tubelib.NodeStates:new({
|
||||
standby_ticks = STANDBY_TICKS,
|
||||
has_item_meter = true,
|
||||
aging_factor = 12,
|
||||
on_stop = function(pos, meta, oldstate)
|
||||
if oldstate == tubelib.RUNNING then
|
||||
meta:set_int("idx", 1) -- restart from the beginning
|
||||
meta:set_string("quarry_pos", nil)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
local function formspec(pos, meta)
|
||||
@ -110,8 +116,7 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player)
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
return 0
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local inv = M(pos):get_inventory()
|
||||
if listname == "main" then
|
||||
return stack:get_count()
|
||||
elseif listname == "fuel" and stack:get_name() == "tubelib_addons1:biofuel" then
|
||||
@ -195,7 +200,7 @@ local function quarry_next_node(pos, meta)
|
||||
|
||||
local node = get_node_lvm(quarry_pos)
|
||||
if node then
|
||||
local number = meta:get_string("number")
|
||||
local number = meta:get_string("tubelib_number")
|
||||
local order = tubelib_addons1.GroundNodes[node.name]
|
||||
if order ~= nil then
|
||||
local inv = meta:get_inventory()
|
||||
@ -253,16 +258,7 @@ local function on_receive_fields(pos, formname, fields, player)
|
||||
end
|
||||
meta:set_int("endless", endless)
|
||||
|
||||
if fields.state_button ~= nil then
|
||||
local state = State:get_state(meta)
|
||||
if state == tubelib.STOPPED or state == tubelib.STANDBY or state == tubelib.BLOCKED then
|
||||
meta:set_int("idx", 1) -- restart from the beginning
|
||||
meta:set_string("quarry_pos", nil)
|
||||
State:start(pos, meta)
|
||||
elseif state == tubelib.RUNNING or state == tubelib.FAULT then
|
||||
State:stop(pos, meta)
|
||||
end
|
||||
end
|
||||
State:state_button_event(pos, fields)
|
||||
end
|
||||
|
||||
minetest.register_node("tubelib_addons1:quarry", {
|
||||
@ -285,7 +281,6 @@ minetest.register_node("tubelib_addons1:quarry", {
|
||||
local number = tubelib.add_node(pos, "tubelib_addons1:quarry")
|
||||
local facedir = minetest.dir_to_facedir(placer:get_look_dir(), false)
|
||||
meta:set_int("facedir", facedir)
|
||||
meta:set_string("number", number)
|
||||
meta:set_string("owner", placer:get_player_name())
|
||||
meta:set_int("endless", 0)
|
||||
meta:set_int("curr_level", -1)
|
||||
|
Loading…
Reference in New Issue
Block a user