settingtypes added, basalt added, Quarry reworked

This commit is contained in:
Joachim Stolberg 2018-12-23 19:36:11 +01:00
parent bddb2c0c63
commit 92e8cda2ed
18 changed files with 332 additions and 234 deletions

@ -12,14 +12,22 @@
- add a tubelib Repair Kit for defect blocks - add a tubelib Repair Kit for defect blocks
- Forceload block as part of tubelib - Forceload block as part of tubelib
- support for intllib - support for intllib
- optionally disable the cobble/ore generation
## Current state ## Current state
- Switch to tubelib2 is done (not fully tested). - Switch to tubelib2 is done (not fully tested).
- Pusher, Distributor, and Grinder already support the new state 'defect'. The AGING_VALUE is currently much to low. This is for testing only. - Pusher, Distributor, and Grinder already support the new state 'defect'. The AGING_VALUE is currently much to low. This is for testing only.
- The Repair Kit is available and can be used to repair defect machines. - The Repair Kit is available and can be used to repair defect machines.
- The mod 'basic_materials' is now needed for the Repair Kit. - The mod 'basic_materials' is now needed for some new recipes.
- Due to server crashes I can happen that all loaded nodes loose their timers. Therefore, all "timed" nodes got an "on_node_load" function, which is used to restart the timer. - Due to server crashes I can happen that all loaded nodes loose their timers. Therefore, all "timed" nodes got an "on_node_load" function, which is used to restart the timer.
- Forceload block (16x16x16) added - Forceload block (16x16x16) added
- switch 'tubelib_addons1_cobble_generator_enabled' activated, so that the automated cobble/ore generation can be disabled.
The cobble generation produces Basalt Stone which can be crafted to Basalt Stone Blocks and Basalt Stone Bricks
- Quarry now uses LVM techniques to go down up to 100 meter
## To Do
- adapt API.md
-

68
tubelib/basalt.lua Normal file

@ -0,0 +1,68 @@
--[[
Tube Library
============
Copyright (C) 2019 Joachim Stolberg
LGPLv2.1+
See LICENSE.txt for more information
basalt.lua:
]]--
if tubelib.basalt_stone_enabled then
-- Replace default:stone with tubelib:basalt which is useless for ore generation.
default.cool_lava = function(pos, node)
if node.name == "default:lava_source" then
minetest.set_node(pos, {name = "default:obsidian"})
else -- Lava flowing
minetest.set_node(pos, {name = "tubelib:basalt_stone"})
end
minetest.sound_play("default_cool_lava",
{pos = pos, max_hear_distance = 16, gain = 0.25})
end
minetest.register_node("tubelib:basalt_stone", {
description = "Basalt Stone",
tiles = {"default_stone.png^[brighten"},
groups = {cracky = 3, stone = 1},
drop = "default:silver_sand",
sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("tubelib:basalt_stone_brick", {
description = "Basalt Stone Brick",
paramtype2 = "facedir",
place_param2 = 0,
tiles = {"default_stone_brick.png^[brighten"},
is_ground_content = false,
groups = {cracky = 2, stone = 1},
sounds = default.node_sound_stone_defaults(),
})
minetest.register_node("tubelib:basalt_stone_block", {
description = "Basalt Stone Block",
tiles = {"default_stone_block.png^[brighten"},
is_ground_content = false,
groups = {cracky = 2, stone = 1},
sounds = default.node_sound_stone_defaults(),
})
minetest.register_craft({
output = "tubelib:basalt_stone_brick 4",
recipe = {
{"tubelib:basalt_stone", "tubelib:basalt_stone"},
{"tubelib:basalt_stone", "tubelib:basalt_stone"},
}
})
minetest.register_craft({
output = "tubelib:basalt_stone_block 9",
recipe = {
{"tubelib:basalt_stone", "tubelib:basalt_stone", "tubelib:basalt_stone"},
{"tubelib:basalt_stone", "tubelib:basalt_stone", "tubelib:basalt_stone"},
{"tubelib:basalt_stone", "tubelib:basalt_stone", "tubelib:basalt_stone"},
}
})
end

@ -3,7 +3,7 @@
Tube Library Tube Library
============ ============
Copyright (C) 2017 Joachim Stolberg Copyright (C) 2017-2019 Joachim Stolberg
LGPLv2.1+ LGPLv2.1+
See LICENSE.txt for more information See LICENSE.txt for more information

@ -3,7 +3,7 @@
Tube Library Tube Library
============ ============
Copyright (C) 2017 Joachim Stolberg Copyright (C) 2017-2019 Joachim Stolberg
LGPLv2.1+ LGPLv2.1+
See LICENSE.txt for more information See LICENSE.txt for more information

@ -3,7 +3,7 @@
Tube Library Tube Library
============ ============
Copyright (C) 2017 Joachim Stolberg Copyright (C) 2017-2019 Joachim Stolberg
LGPLv2.1+ LGPLv2.1+
See LICENSE.txt for more information See LICENSE.txt for more information
@ -34,7 +34,7 @@ local function update_mod_storage()
storage:set_string("Number2Pos", minetest.serialize(Number2Pos)) storage:set_string("Number2Pos", minetest.serialize(Number2Pos))
storage:set_string("Key2Number", nil) -- not used any more storage:set_string("Key2Number", nil) -- not used any more
-- store data each hour -- store data each hour
minetest.after(60*60, update_mod_storage) minetest.after(60*59, update_mod_storage)
minetest.log("action", "[Tubelib] Data stored") minetest.log("action", "[Tubelib] Data stored")
end end
@ -43,7 +43,7 @@ minetest.register_on_shutdown(function()
end) end)
-- store data after one hour -- store data after one hour
minetest.after(60*60, 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 = {}

@ -3,7 +3,7 @@
Tube Library Tube Library
============ ============
Copyright (C) 2017 Joachim Stolberg Copyright (C) 2017-2019 Joachim Stolberg
LGPLv2.1+ LGPLv2.1+
See LICENSE.txt for more information See LICENSE.txt for more information
@ -16,7 +16,7 @@
- topic = "on", payload = nil - topic = "on", payload = nil
- topic = "off" , payload = nil - topic = "off" , payload = nil
- topic = "state", payload = nil, - topic = "state", payload = nil,
response is "running", "stopped", "standby", or "not supported" response is "running", "stopped", "standby", "defect", or "not supported"
]]-- ]]--
-- for lazy programmers -- for lazy programmers
@ -372,6 +372,7 @@ minetest.register_node("tubelib:distributor", {
on_timer = keep_running, on_timer = keep_running,
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
drop = "",
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
paramtype2 = "facedir", paramtype2 = "facedir",
@ -460,7 +461,7 @@ minetest.register_node("tubelib:distributor_defect", {
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {crumbly=0, not_in_creative_inventory=1}, groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory=1},
is_ground_content = false, is_ground_content = false,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
}) })

@ -3,7 +3,7 @@
Tube Library Tube Library
============ ============
Copyright (C) 2017 Joachim Stolberg Copyright (C) 2017-2019 Joachim Stolberg
LGPLv2.1+ LGPLv2.1+
See LICENSE.txt for more information See LICENSE.txt for more information
@ -127,22 +127,23 @@ minetest.register_node("tubelib:forceload", {
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
groups = {choppy=2, cracky=2, crumbly=2}, groups = {choppy=2, cracky=2, crumbly=2,
not_in_creative_inventory = tubelib.max_num_forceload_blocks == 0 and 1 or 0},
is_ground_content = false, is_ground_content = false,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
}) })
if tubelib.max_num_forceload_blocks > 0 then
minetest.register_craft({ minetest.register_craft({
output = "tubelib:forceload", output = "tubelib:forceload",
recipe = { recipe = {
{"group:wood", "", "group:wood"}, {"group:wood", "", "group:wood"},
{"", "basic_materials:energy_crystal_simple", ""}, {"", "basic_materials:energy_crystal_simple", ""},
{"group:wood", "", "group:wood"}, {"group:wood", "tubelib:wlanchip", "group:wood"},
}, },
}) })
end
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
for _,pos in ipairs(get_pos_list(player)) do for _,pos in ipairs(get_pos_list(player)) do

@ -3,7 +3,7 @@
Tube Library Tube Library
============ ============
Copyright (C) 2017,2018 Joachim Stolberg Copyright (C) 2017-2019 Joachim Stolberg
LGPLv2.1+ LGPLv2.1+
See LICENSE.txt for more information See LICENSE.txt for more information
@ -24,8 +24,8 @@
- new tubing algorithm - new tubing algorithm
- tubelib.pull_stack()/tubelib.get_stack() added - tubelib.pull_stack()/tubelib.get_stack() added
- item counter for pusher/distributor added - item counter for pusher/distributor added
2018-12-21 v2.00 Switch to tubelib2, "defect" nodes and "repair kit" added, 2018-12-21 v2.00 Switch to tubelib2, "defect" nodes and "Repair Kit" added,
Forceload block added, Forceload block added, Basalt as Cobble Stone alternative added
]]-- ]]--
@ -35,7 +35,10 @@ tubelib = {
} }
tubelib.version = 2.00 tubelib.version = 2.00
tubelib.max_num_forceload_blocks = 10
tubelib.max_num_forceload_blocks = tonumber(minetest.setting_get("tubelib_max_num_forceload_blocks")) or 10
tubelib.basalt_stone_enabled = minetest.setting_get("tubelib_basalt_stone_enabled") == "true"
tubelib.machine_aging_value = tonumber(minetest.setting_get("tubelib_machine_aging_value")) or 100
--------------------------- conversion to v0.04 --------------------------- conversion to v0.04
@ -105,4 +108,5 @@ dofile(minetest.get_modpath("tubelib") .. "/legacy_nodes.lua")
dofile(minetest.get_modpath("tubelib") .. "/repairkit.lua") dofile(minetest.get_modpath("tubelib") .. "/repairkit.lua")
dofile(minetest.get_modpath("tubelib") .. "/mark.lua") dofile(minetest.get_modpath("tubelib") .. "/mark.lua")
dofile(minetest.get_modpath("tubelib") .. "/forceload.lua") dofile(minetest.get_modpath("tubelib") .. "/forceload.lua")
dofile(minetest.get_modpath("tubelib") .. "/basalt.lua")

@ -54,7 +54,8 @@ minetest.register_lbm({
local peer_pos = P(peer) local peer_pos = P(peer)
local _,node = Tube:get_node(peer_pos) local _,node = Tube:get_node(peer_pos)
local tube_dir = ((3 + (node.param2 % 4)) % 4) + 1 local tube_dir = ((3 + (node.param2 % 4)) % 4) + 1
print("migration", peer, tube_dir) print("migrate "..node.name.." at "..S(pos))
meta:set_string("peer", nil)
if tube_dir then if tube_dir then
meta:set_int("tube_dir", tube_dir) meta:set_int("tube_dir", tube_dir)
end end
@ -64,6 +65,7 @@ minetest.register_lbm({
else else
local items = TubesTranslation[node.name][node.param2] local items = TubesTranslation[node.name][node.param2]
if items then if items then
print("migrate "..node.name.." at "..S(pos))
local param2, ntype = items[1], items[2] local param2, ntype = items[1], items[2]
minetest.set_node(pos, {name = "tubelib:tube"..ntype, param2 = param2}) minetest.set_node(pos, {name = "tubelib:tube"..ntype, param2 = param2})
end end

@ -57,7 +57,6 @@ local P = minetest.string_to_pos
local M = minetest.get_meta local M = minetest.get_meta
local AGING_VALUE = 10 -- start aging value
local AGING_FACTOR = 3 -- defect random factor local AGING_FACTOR = 3 -- defect random factor
-- --
@ -90,8 +89,8 @@ function NodeStates:new(attr)
infotext_name = attr.infotext_name, infotext_name = attr.infotext_name,
} }
if attr.aging_factor then if attr.aging_factor then
o.aging_level1 = attr.aging_factor * AGING_VALUE o.aging_level1 = attr.aging_factor * tubelib.machine_aging_value
o.aging_level2 = attr.aging_factor * AGING_VALUE * AGING_FACTOR o.aging_level2 = attr.aging_factor * tubelib.machine_aging_value * AGING_FACTOR
end end
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
@ -415,6 +414,7 @@ function NodeStates:on_node_repair(pos)
return false return false
end end
-- Return working or defect machine, depending on machine lifetime
function NodeStates:after_dig_node(pos, oldnode, oldmetadata, digger) function NodeStates:after_dig_node(pos, oldnode, oldmetadata, digger)
local inv = minetest.get_inventory({type="player", name=digger:get_player_name()}) local inv = minetest.get_inventory({type="player", name=digger:get_player_name()})
local cnt = oldmetadata.fields.tubelib_aging and tonumber(oldmetadata.fields.tubelib_aging) or 0 local cnt = oldmetadata.fields.tubelib_aging and tonumber(oldmetadata.fields.tubelib_aging) or 0

10
tubelib/settingtypes.txt Normal file

@ -0,0 +1,10 @@
# Maximim number of Forceload Blocks per player
tubelib_max_num_forceload_blocks (max number of Forceload Blocks) int 10
# Enable Basalt Stone (and disable ore generation via cobble generator)
tubelib_basalt_stone_enabled (Basalt Stone enabled) bool true
# This aging value is used to calculate the lifetime of machines before
# they go defect. The value 100 results in a lifetime
# for standard machines of about 1000 - 4000 item processing cycles.
tubelib_machine_aging_value (machine aging value) int 100

@ -279,11 +279,9 @@ tubelib.register_node("tubelib_addons1:grinder",
end end
end, end,
on_node_load = function(pos) on_node_load = function(pos)
print("on_node_load")
return State:on_node_load(pos) return State:on_node_load(pos)
end, end,
on_node_repair = function(pos) on_node_repair = function(pos)
print("on_node_repair")
return State:on_node_repair(pos) return State:on_node_repair(pos)
end, end,
}) })
@ -314,6 +312,7 @@ tubelib.add_grinder_recipe({input="default:mossycobble", output="default:gravel"
tubelib.add_grinder_recipe({input="default:gravel", output="default:sand"}) tubelib.add_grinder_recipe({input="default:gravel", output="default:sand"})
tubelib.add_grinder_recipe({input="gravelsieve:sieved_gravel", output="default:sand"}) tubelib.add_grinder_recipe({input="gravelsieve:sieved_gravel", output="default:sand"})
tubelib.add_grinder_recipe({input="default:coral_skeleton", output="default:silver_sand"}) tubelib.add_grinder_recipe({input="default:coral_skeleton", output="default:silver_sand"})
tubelib.add_grinder_recipe({input="tubelib:basalt_stone", output="default:silver_sand"})
if minetest.global_exists("skytest") then if minetest.global_exists("skytest") then
tubelib.add_grinder_recipe({input="default:desert_sand", output="skytest:dust"}) tubelib.add_grinder_recipe({input="default:desert_sand", output="skytest:dust"})

@ -10,30 +10,6 @@
]]-- ]]--
local cobble_generator_enabled =
tonumber(minetest.setting_get("tubelib_addons1_cobble_generator_enabled")) or true
if not cobble_generator_enabled then
-- Replace default:stone with tubelib_addons1:basalt which is useless.
default.cool_lava = function(pos, node)
if node.name == "default:lava_source" then
minetest.set_node(pos, {name = "default:obsidian"})
else -- Lava flowing
minetest.set_node(pos, {name = "tubelib_addons1:basalt"})
end
minetest.sound_play("default_cool_lava",
{pos = pos, max_hear_distance = 16, gain = 0.25})
end
minetest.register_node("tubelib_addons1:basalt", {
description = "Basalt",
tiles = {"default_obsidian.png^[brighten"},
groups = {cracky = 3, stone = 1},
drop = 'default:cobble',
sounds = default.node_sound_stone_defaults(),
})
end
dofile(minetest.get_modpath("tubelib_addons1") .. "/nodes.lua") dofile(minetest.get_modpath("tubelib_addons1") .. "/nodes.lua")
dofile(minetest.get_modpath("tubelib_addons1") .. "/quarry.lua") dofile(minetest.get_modpath("tubelib_addons1") .. "/quarry.lua")

@ -174,6 +174,12 @@ gn("default:coral_skeleton", "default:coral_skeleton")
gn("default:coral_orange", "default:coral_skeleton") gn("default:coral_orange", "default:coral_skeleton")
gn("default:coral_brown", "default:coral_skeleton") gn("default:coral_brown", "default:coral_skeleton")
-------------------------------------------------------------------------------
-- tubelib Ground
-------------------------------------------------------------------------------
gn("tubelib:basalt_stone", "tubelib:basalt_stone")
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- Moreores Ground -- Moreores Ground
------------------------------------------------------------------------------- -------------------------------------------------------------------------------

@ -39,9 +39,9 @@ local COUNTDOWN_TICKS = 5
local CYCLE_TIME = 1 local CYCLE_TIME = 1
local State = tubelib.NodeStates:new({ local State = tubelib.NodeStates:new({
node_name_passive = "tubelib_addons1:pusher", node_name_passive = "tubelib_addons1:pusher_fast",
node_name_active = "tubelib_addons1:pusher_active", node_name_active = "tubelib_addons1:pusher_fast_active",
node_name_defect = "tubelib_addons1:pusher_defect", node_name_defect = "tubelib_addons1:pusher_fast_defect",
infotext_name = "Fast Pusher", infotext_name = "Fast Pusher",
cycle_time = CYCLE_TIME, cycle_time = CYCLE_TIME,
standby_ticks = STANDBY_TICKS, standby_ticks = STANDBY_TICKS,

@ -26,7 +26,7 @@ local TICKS_TO_SLEEP = 5
local STOP_STATE = 0 local STOP_STATE = 0
local FAULT_STATE = -3 local FAULT_STATE = -3
local Depth2Idx = {[1]=1 ,[2]=2, [3]=3, [5]=4, [10]=5, [15]=6, [20]=7, [25]=8} local Depth2Idx = {[1]=1 ,[2]=2, [3]=3, [5]=4, [10]=5, [15]=6, [20]=7, [25]=8, [50]=9, [100]=10}
local Level2Idx = {[2]=1, [1]=2, [0]=3, [-1]=4, [-2]=5, [-3]=6, local Level2Idx = {[2]=1, [1]=2, [0]=3, [-1]=4, [-2]=5, [-3]=6,
[-5]=7, [-10]=8, [-15]=9, [-20]=10} [-5]=7, [-10]=8, [-15]=9, [-20]=10}
@ -49,7 +49,7 @@ local function quarry_formspec(meta, state)
default.gui_slots.. default.gui_slots..
"dropdown[0,0;1.5;level;2,1,0,-1,-2,-3,-5,-10,-15,-20;"..Level2Idx[start_level].."]".. "dropdown[0,0;1.5;level;2,1,0,-1,-2,-3,-5,-10,-15,-20;"..Level2Idx[start_level].."]"..
"label[1.6,0.2;Start level]".. "label[1.6,0.2;Start level]"..
"dropdown[0,1;1.5;depth;1,2,3,5,10,15,20,25;"..Depth2Idx[depth].."]".. "dropdown[0,1;1.5;depth;1,2,3,5,10,15,20,25,50,100;"..Depth2Idx[depth].."]"..
"label[1.6,1.2;Digging depth]".. "label[1.6,1.2;Digging depth]"..
"checkbox[0,2;endless;Run endless;"..endless.."]".. "checkbox[0,2;endless;Run endless;"..endless.."]"..
"list[context;main;5,0;4,4;]".. "list[context;main;5,0;4,4;]"..
@ -71,6 +71,24 @@ local function get_pos(pos, facedir, side)
return vector.add(dst_pos, dir) return vector.add(dst_pos, dir)
end end
local function get_node_lvm(pos)
local node = minetest.get_node_or_nil(pos)
if node then
return node
end
local vm = minetest.get_voxel_manip()
local MinEdge, MaxEdge = vm:read_from_map(pos, pos)
local data = vm:get_data()
local param2_data = vm:get_param2_data()
local area = VoxelArea:new({MinEdge = MinEdge, MaxEdge = MaxEdge})
local idx = area:index(pos.x, pos.y, pos.z)
node = {
name = minetest.get_name_from_content_id(data[idx]),
param2 = param2_data[idx]
}
return node
end
local function allow_metadata_inventory_put(pos, listname, index, stack, player) local function allow_metadata_inventory_put(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
@ -184,7 +202,7 @@ local function quarry_next_node(pos, meta)
return nil -- fault return nil -- fault
end end
local node = minetest.get_node_or_nil(quarry_pos) local node = get_node_lvm(quarry_pos)
if node == nil then if node == nil then
return true return true
end end

@ -1,3 +0,0 @@
# Cobble generator enabled (true/false)
tubelib_addons1_cobble_generator_enabled (Enable cobblestone generation) bool true

@ -13,17 +13,55 @@
A high performance distributor A high performance distributor
]]-- ]]--
-- for lazy programmers
local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos
local M = minetest.get_meta
local NUM_FILTER_ELEM = 6 local NUM_FILTER_ELEM = 6
local NUM_FILTER_SLOTS = 4 local NUM_FILTER_SLOTS = 4
local TICKS_TO_SLEEP = 5
local CYCLE_TIME = 2
local STOP_STATE = 0
local STANDBY_STATE = -1
local Side2Color = {B="red", L="green", F="blue", R="yellow"} local COUNTDOWN_TICKS = 6
local SlotColors = {"red", "green", "blue", "yellow"} local STANDBY_TICKS = 4
local Num2Ascii = {"B", "L", "F", "R"} local CYCLE_TIME = 2
local FilterCache = {} -- local cache for filter settings
local State = tubelib.NodeStates:new({
node_name_passive = "tubelib_addons3:distributor",
node_name_active = "tubelib_addons3:distributor_active",
node_name_defect = "tubelib_addons3:distributor_defect",
infotext_name = "HighPerf Distributor",
cycle_time = CYCLE_TIME,
standby_ticks = STANDBY_TICKS,
aging_factor = 10,
})
local function formspec(pos, meta)
local filter = minetest.deserialize(meta:get_string("filter"))
return "size[10.5,8.5]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
"list[context;src;0,0;2,4;]"..
"image[2,1.5;1,1;tubelib_gui_arrow.png]"..
"image_button[2,3;1,1;"..State:get_state_button_image(meta)..";state_button;]"..
"checkbox[3,0;filter1;On;"..dump(filter[1]).."]"..
"checkbox[3,1;filter2;On;"..dump(filter[2]).."]"..
"checkbox[3,2;filter3;On;"..dump(filter[3]).."]"..
"checkbox[3,3;filter4;On;"..dump(filter[4]).."]"..
"image[4,0;0.3,1;tubelib_red.png]"..
"image[4,1;0.3,1;tubelib_green.png]"..
"image[4,2;0.3,1;tubelib_blue.png]"..
"image[4,3;0.3,1;tubelib_yellow.png]"..
"list[context;red;4.5,0;6,1;]"..
"list[context;green;4.5,1;6,1;]"..
"list[context;blue;4.5,2;6,1;]"..
"list[context;yellow;4.5,3;6,1;]"..
"list[current_player;main;1.25,4.5;8,4;]"..
"listring[context;src]"..
"listring[current_player;main]"
end
State:register_formspec_func(formspec)
-- Return the total number of list entries -- Return the total number of list entries
local function invlist_num_entries(list) local function invlist_num_entries(list)
@ -73,34 +111,49 @@ local function random_list_elem(list)
end end
end end
local function distributor_formspec(state, filter) local function allow_metadata_inventory_put(pos, listname, index, stack, player)
return "size[10.5,8.5]".. local meta = M(pos)
default.gui_bg.. local inv = meta:get_inventory()
default.gui_bg_img.. local list = inv:get_list(listname)
default.gui_slots..
"list[context;src;0,0;2,4;]".. if minetest.is_protected(pos, player:get_player_name()) then
"image[2,1.5;1,1;tubelib_gui_arrow.png]".. return 0
"image_button[2,3;1,1;".. tubelib.state_button(state) ..";button;]".. end
"checkbox[3,0;filter1;On;"..dump(filter[1]).."]".. if listname == "src" then
"checkbox[3,1;filter2;On;"..dump(filter[2]).."]".. if State:get_state(M(pos)) == tubelib.STANDBY then
"checkbox[3,2;filter3;On;"..dump(filter[3]).."]".. State:start(pos, meta)
"checkbox[3,3;filter4;On;"..dump(filter[4]).."]".. end
"image[4,0;0.3,1;tubelib_red.png]".. return stack:get_count()
"image[4,1;0.3,1;tubelib_green.png]".. elseif invlist_num_entries(list) < NUM_FILTER_ELEM then
"image[4,2;0.3,1;tubelib_blue.png]".. filter_settings(pos)
"image[4,3;0.3,1;tubelib_yellow.png]".. return 1
"list[context;red;4.5,0;6,1;]".. end
"list[context;green;4.5,1;6,1;]".. return 0
"list[context;blue;4.5,2;6,1;]"..
"list[context;yellow;4.5,3;6,1;]"..
"list[current_player;main;1.25,4.5;8,4;]"..
"listring[context;src]"..
"listring[current_player;main]"
end end
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
filter_settings(pos)
return stack:get_count()
end
local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local stack = inv:get_stack(from_list, from_index)
return allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
end
local Side2Color = {B="red", L="green", F="blue", R="yellow"}
local SlotColors = {"red", "green", "blue", "yellow"}
local Num2Ascii = {"B", "L", "F", "R"}
local FilterCache = {} -- local cache for filter settings
local function filter_settings(pos) local function filter_settings(pos)
local hash = minetest.hash_node_position(pos) local hash = minetest.hash_node_position(pos)
local meta = minetest.get_meta(pos) local meta = M(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local filter = minetest.deserialize(meta:get_string("filter")) or {false,false,false,false} local filter = minetest.deserialize(meta:get_string("filter")) or {false,false,false,false}
local kvFilterItemNames = {} -- {<item:name> = side,...} local kvFilterItemNames = {} -- {<item:name> = side,...}
@ -125,86 +178,8 @@ local function filter_settings(pos)
} }
end end
local function allow_metadata_inventory_put(pos, listname, index, stack, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local list = inv:get_list(listname)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
if listname == "src" then
return stack:get_count()
elseif invlist_num_entries(list) < NUM_FILTER_ELEM then
filter_settings(pos)
return 1
end
return 0
end
local function allow_metadata_inventory_take(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
filter_settings(pos)
return stack:get_count()
end
local function allow_metadata_inventory_move(pos, from_list, from_index, to_list, to_index, count, player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local stack = inv:get_stack(from_list, from_index)
return allow_metadata_inventory_put(pos, to_list, to_index, stack, player)
end
local function start_the_machine(pos)
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
local number = meta:get_string("number")
meta:set_int("running", TICKS_TO_SLEEP)
node.name = "tubelib_addons3:distributor_active"
minetest.swap_node(pos, node)
meta:set_string("infotext", "HighPerf Distributor "..number..": running")
local filter = minetest.deserialize(meta:get_string("filter"))
meta:set_string("formspec", distributor_formspec(tubelib.RUNNING, filter))
minetest.get_node_timer(pos):start(CYCLE_TIME)
return false
end
local function stop_the_machine(pos)
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
local number = meta:get_string("number")
meta:set_int("running", STOP_STATE)
node.name = "tubelib_addons3:distributor"
minetest.swap_node(pos, node)
meta:set_string("infotext", "HighPerf Distributor "..number..": stopped")
local filter = minetest.deserialize(meta:get_string("filter"))
meta:set_string("formspec", distributor_formspec(tubelib.STOPPED, filter))
minetest.get_node_timer(pos):stop()
return false
end
local function goto_sleep(pos)
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
local number = meta:get_string("number")
meta:set_int("running", STANDBY_STATE)
node.name = "tubelib_addons3:distributor"
minetest.swap_node(pos, node)
meta:set_string("infotext", "HighPerf Distributor "..number..": standby")
local filter = minetest.deserialize(meta:get_string("filter"))
meta:set_string("formspec", distributor_formspec(tubelib.STANDBY, filter))
minetest.get_node_timer(pos):start(CYCLE_TIME * TICKS_TO_SLEEP)
return false
end
-- move items to the output slots -- move items to the output slots
local function keep_running(pos, elapsed) local function distributing(pos, meta)
local meta = minetest.get_meta(pos)
local running = meta:get_int("running") - 1
local player_name = meta:get_string("player_name") local player_name = meta:get_string("player_name")
local counter = minetest.deserialize(meta:get_string("item_counter")) or local counter = minetest.deserialize(meta:get_string("item_counter")) or
{red=0, green=0, blue=0, yellow=0} {red=0, green=0, blue=0, yellow=0}
@ -221,7 +196,7 @@ local function keep_running(pos, elapsed)
-- no filter configured? -- no filter configured?
if next(kvFilterItemNames) == nil then if next(kvFilterItemNames) == nil then
return goto_sleep(pos) return false
end end
local busy = false local busy = false
@ -272,29 +247,26 @@ local function keep_running(pos, elapsed)
end end
inv:set_list("src", list) inv:set_list("src", list)
if busy == true then
if running <= 0 then
return start_the_machine(pos)
else
running = TICKS_TO_SLEEP
end
else
if running <= 0 then
return goto_sleep(pos)
end
end
meta:set_string("item_counter", minetest.serialize(counter)) meta:set_string("item_counter", minetest.serialize(counter))
meta:set_int("running", running) return busy
return true end
-- move items to the output slots
local function keep_running(pos, elapsed)
local meta = M(pos)
if distributing(pos, meta) then
State:keep_running(pos, meta, COUNTDOWN_TICKS)
else
State:idle(pos, meta)
end
return State:is_active(meta)
end end
local function on_receive_fields(pos, formname, fields, player) local function on_receive_fields(pos, formname, fields, player)
if minetest.is_protected(pos, player:get_player_name()) then if minetest.is_protected(pos, player:get_player_name()) then
return return
end end
local meta = minetest.get_meta(pos) local meta = M(pos)
local running = meta:get_int("running")
local filter = minetest.deserialize(meta:get_string("filter")) local filter = minetest.deserialize(meta:get_string("filter"))
if fields.filter1 ~= nil then if fields.filter1 ~= nil then
filter[1] = fields.filter1 == "true" filter[1] = fields.filter1 == "true"
@ -309,21 +281,13 @@ local function on_receive_fields(pos, formname, fields, player)
filter_settings(pos) filter_settings(pos)
if fields.button ~= nil then State:state_button_event(pos, fields)
if running > STOP_STATE then
stop_the_machine(pos)
else
start_the_machine(pos)
end
else
meta:set_string("formspec", distributor_formspec(tubelib.state(running), filter))
end
end end
-- tubelib command to turn on/off filter channels -- tubelib command to turn on/off filter channels
local function change_filter_settings(pos, slot, val) local function change_filter_settings(pos, slot, val)
local slots = {["red"] = 1, ["green"] = 2, ["blue"] = 3, ["yellow"] = 4} local slots = {["red"] = 1, ["green"] = 2, ["blue"] = 3, ["yellow"] = 4}
local meta = minetest.get_meta(pos) local meta = M(pos)
local filter = minetest.deserialize(meta:get_string("filter")) local filter = minetest.deserialize(meta:get_string("filter"))
local num = slots[slot] or 1 local num = slots[slot] or 1
if num >= 1 and num <= 4 then if num >= 1 and num <= 4 then
@ -333,8 +297,7 @@ local function change_filter_settings(pos, slot, val)
filter_settings(pos) filter_settings(pos)
local running = meta:get_int("running") meta:set_string("formspec", formspec(pos, meta))
meta:set_string("formspec", distributor_formspec(tubelib.state(running), filter))
return true return true
end end
@ -351,15 +314,13 @@ minetest.register_node("tubelib_addons3:distributor", {
}, },
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local meta = M(pos)
local number = tubelib.add_node(pos, "tubelib_addons3:distributor") local number = tubelib.add_node(pos, "tubelib_addons3:distributor")
local meta = minetest.get_meta(pos) local filter = {false,false,false,false}
meta:set_string("filter", minetest.serialize(filter))
State:node_init(pos, number)
meta:set_string("player_name", placer:get_player_name()) meta:set_string("player_name", placer:get_player_name())
local filter = {false,false,false,false}
meta:set_string("formspec", distributor_formspec(tubelib.STOPPED, filter))
meta:set_string("filter", minetest.serialize(filter))
meta:set_string("number", number)
meta:set_string("infotext", "HighPerf Distributor "..number..": stopped")
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size('src', 8) inv:set_size('src', 8)
inv:set_size('yellow', 6) inv:set_size('yellow', 6)
@ -375,7 +336,7 @@ minetest.register_node("tubelib_addons3:distributor", {
if minetest.is_protected(pos, puncher:get_player_name()) then if minetest.is_protected(pos, puncher:get_player_name()) then
return return
end end
local meta = minetest.get_meta(pos) local meta = M(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
if inv:is_empty("src") then if inv:is_empty("src") then
minetest.node_dig(pos, node, puncher, pointed_thing) minetest.node_dig(pos, node, puncher, pointed_thing)
@ -383,6 +344,10 @@ minetest.register_node("tubelib_addons3:distributor", {
end end
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
State:after_dig_node(pos, oldnode, oldmetadata, digger)
end,
allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_take = allow_metadata_inventory_take, allow_metadata_inventory_take = allow_metadata_inventory_take,
allow_metadata_inventory_move = allow_metadata_inventory_move, allow_metadata_inventory_move = allow_metadata_inventory_move,
@ -390,6 +355,7 @@ minetest.register_node("tubelib_addons3:distributor", {
on_timer = keep_running, on_timer = keep_running,
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
drop = "",
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
paramtype2 = "facedir", paramtype2 = "facedir",
@ -437,6 +403,53 @@ minetest.register_node("tubelib_addons3:distributor_active", {
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
}) })
minetest.register_node("tubelib_addons3:distributor_defect", {
description = "HighPerf Distributor",
tiles = {
-- up, down, right, left, back, front
'tubelib_distributor.png^tubelib_addons3_node_frame.png',
'tubelib_distributor.png^tubelib_addons3_node_frame.png',
'tubelib_distributor_yellow.png^tubelib_addons3_node_frame.png^tubelib_defect.png',
'tubelib_distributor_green.png^tubelib_addons3_node_frame.png^tubelib_defect.png',
"tubelib_distributor_red.png^tubelib_addons3_node_frame.png^tubelib_defect.png",
"tubelib_distributor_blue.png^tubelib_addons3_node_frame.png^tubelib_defect.png",
},
after_place_node = function(pos, placer)
local meta = M(pos)
local number = tubelib.add_node(pos, "tubelib_addons3:distributor")
State:node_init(pos, number)
meta:set_string("player_name", placer:get_player_name())
local filter = {false,false,false,false}
meta:set_string("filter", minetest.serialize(filter))
local inv = meta:get_inventory()
inv:set_size('src', 8)
inv:set_size('yellow', 6)
inv:set_size('green', 6)
inv:set_size('red', 6)
inv:set_size('blue', 6)
meta:set_string("item_counter", minetest.serialize({red=0, green=0, blue=0, yellow=0}))
State:defect(pos, meta)
end,
on_receive_fields = on_receive_fields,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_take = allow_metadata_inventory_take,
allow_metadata_inventory_move = allow_metadata_inventory_move,
on_rotate = screwdriver.disallow,
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
groups = {choppy=2, cracky=2, crumbly=2, not_in_creative_inventory=1},
is_ground_content = false,
sounds = default.node_sound_wood_defaults(),
})
minetest.register_craft({ minetest.register_craft({
output = "tubelib_addons3:distributor", output = "tubelib_addons3:distributor",
recipe = { recipe = {
@ -447,29 +460,19 @@ minetest.register_craft({
}) })
tubelib.register_node("tubelib_addons3:distributor", {"tubelib_addons3:distributor_active"}, { tubelib.register_node("tubelib_addons3:distributor",
{"tubelib_addons3:distributor_active", "tubelib_addons3:distributor_defect"}, {
on_pull_item = function(pos, side) on_pull_item = function(pos, side)
local meta = minetest.get_meta(pos) return tubelib.get_item(M(pos), "src")
return tubelib.get_item(meta, "src")
end, end,
on_push_item = function(pos, side, item) on_push_item = function(pos, side, item)
local meta = minetest.get_meta(pos) return tubelib.put_item(M(pos), "src", item)
return tubelib.put_item(meta, "src", item)
end, end,
on_unpull_item = function(pos, side, item) on_unpull_item = function(pos, side, item)
local meta = minetest.get_meta(pos) return tubelib.put_item(M(pos), "src", item)
return tubelib.put_item(meta, "src", item)
end, end,
on_recv_message = function(pos, topic, payload) on_recv_message = function(pos, topic, payload)
if topic == "on" then if topic == "filter" then
return start_the_machine(pos)
elseif topic == "off" then
return stop_the_machine(pos)
elseif topic == "state" then
local meta = minetest.get_meta(pos)
local running = meta:get_int("running")
return tubelib.statestring(running)
elseif topic == "filter" then
return change_filter_settings(pos, payload.slot, payload.val) return change_filter_settings(pos, payload.slot, payload.val)
elseif topic == "counter" then elseif topic == "counter" then
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -478,15 +481,20 @@ tubelib.register_node("tubelib_addons3:distributor", {"tubelib_addons3:distribut
elseif topic == "clear_counter" then elseif topic == "clear_counter" then
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_string("item_counter", minetest.serialize({red=0, green=0, blue=0, yellow=0})) meta:set_string("item_counter", minetest.serialize({red=0, green=0, blue=0, yellow=0}))
else
local resp = State:on_receive_message(pos, topic, payload)
if resp then
return resp
else else
return "unsupported" return "unsupported"
end end
end,
on_node_load = function(pos)
local meta = minetest.get_meta(pos)
if meta:get_int("running") ~= STOP_STATE then
meta:set_int("running", STANDBY_STATE)
minetest.get_node_timer(pos):start(CYCLE_TIME * TICKS_TO_SLEEP)
end end
end, end,
on_node_load = function(pos)
State:on_node_load(pos)
end,
on_node_repair = function(pos)
return State:on_node_repair(pos)
end,
}) })