Remove deprecated code, add bot status to formspec, improve many commands

This commit is contained in:
Joachim Stolberg 2021-03-13 15:22:43 +01:00
parent bca7ec9537
commit 249340d5fd
19 changed files with 72 additions and 17 deletions

View File

@ -112,12 +112,25 @@ local function preassigned_slots(pos)
return table.concat(tbl, "")
end
local function status(mem)
if mem.error then
return mem.error
end
if mem.running then
return I("running")
end
if mem.charging then
return I("charging")
end
return I("stopped")
end
local function formspec(pos, mem)
mem.running = mem.running or false
local cmnd = mem.running and "stop;"..I("Off") or "start;"..I("On")
local bot = not mem.running and "image[0.6,0;1,1;signs_bot_bot_inv.png]" or ""
local current_capa = mem.capa or (signs_bot.MAX_CAPA * 0.9)
return "size[9,7.6]"..
return "size[9,8.2]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
@ -134,13 +147,14 @@ local function formspec(pos, mem)
"label[5.3,3;5]label[6.3,3;6]label[7.3,3;7]label[8.3,3;8]"..
"button[0.2,1;1.5,1;config;"..I("Config").."]"..
"button[0.2,2;1.5,1;"..cmnd.."]"..
"list[current_player;main;0.5,3.8;8,4;]"..
"label[1,3.6;"..status(mem).."]"..
"list[current_player;main;0.5,4.4;8,4;]"..
"listring[context;main]"..
"listring[current_player;main]"
end
local function formspec_cfg(pos, mem)
return "size[9,7.6]"..
return "size[9,8.2]"..
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
@ -149,7 +163,7 @@ local function formspec_cfg(pos, mem)
"list[context;filter;5,1;4,2;]"..
"label[5.3,3;5]label[6.3,3;6]label[7.3,3;7]label[8.3,3;8]"..
"button[0.2,1;1.5,1;back;"..I("Back").."]"..
"list[current_player;main;0.5,3.8;8,4;]"..
"list[current_player;main;0.5,4.4;8,4;]"..
"listring[context;filter]"..
"listring[current_player;main]"
end

View File

@ -57,6 +57,7 @@ minetest.register_node("signs_bot:bot_sensor", {
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
use_texture_alpha = "clip",
is_ground_content = false,
groups = {sign_bot_sensor = 1, cracky = 1},
sounds = default.node_sound_metal_defaults(),
@ -100,6 +101,7 @@ minetest.register_node("signs_bot:bot_sensor_on", {
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
use_texture_alpha = "clip",
is_ground_content = false,
diggable = false,
groups = {sign_bot_sensor = 1, not_in_creative_inventory = 1},

View File

@ -93,6 +93,7 @@ minetest.register_node("signs_bot:cart_sensor", {
update_infotext = update_infotext,
on_rotate = screwdriver.disallow,
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
paramtype2 = "facedir",
is_ground_content = false,
@ -123,6 +124,7 @@ minetest.register_node("signs_bot:cart_sensor_on", {
update_infotext = update_infotext,
on_rotate = screwdriver.disallow,
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
paramtype2 = "facedir",
is_ground_content = false,

View File

@ -100,6 +100,11 @@ local function allow_metadata_inventory()
return 0
end
local function can_dig(pos)
local inv = minetest.get_inventory({type="node", pos=pos})
return inv:is_empty("sign")
end
for idx = 1,4 do
local not_in_inv = idx == 1 and 0 or 1
minetest.register_node("signs_bot:changer"..idx, {
@ -139,9 +144,11 @@ for idx = 1,4 do
allow_metadata_inventory_put = allow_metadata_inventory,
allow_metadata_inventory_take = allow_metadata_inventory,
on_punch = swap_node,
can_dig = can_dig,
on_rotate = screwdriver.disallow,
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
paramtype2 = "facedir",
is_ground_content = false,

View File

@ -97,7 +97,10 @@ local function harvesting(base_pos, mem)
-- Do not cache the result of get_node_drops; it is a probabilistic function!
local drops = minetest.get_node_drops(node.name)
for _,itemstring in ipairs(drops) do
bot_inv_put_item(base_pos, 0, ItemStack(itemstring))
local leftover = bot_inv_put_item(base_pos, 0, ItemStack(itemstring))
if leftover and leftover:get_count() > 0 then
signs_bot.lib.drop_items(mem.robot_pos, leftover)
end
end
end
end

View File

@ -63,7 +63,10 @@ local function harvesting(base_pos, mem)
local drop = Flowers[node.name] or is_tree(node.name)
if drop then
minetest.remove_node(pos)
bot_inv_put_item(base_pos, 0, ItemStack(drop))
local leftover = bot_inv_put_item(base_pos, 0, ItemStack(drop))
if leftover and leftover:get_count() > 0 then
signs_bot.lib.drop_items(mem.robot_pos, leftover)
end
end
end
end

View File

@ -428,6 +428,7 @@ minetest.register_node("signs_bot:torch", {
"group:bakedclay", "group:soil"},
paramtype = "light",
paramtype2 = "facedir",
use_texture_alpha = "clip",
sunlight_propagates = true,
walkable = false,
liquids_pointable = false,

View File

@ -175,6 +175,7 @@ minetest.register_node("signs_bot:sign_cmnd", {
after_dig_node = lib.after_dig_sign_node,
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
is_ground_content = false,
drop = "",
@ -323,7 +324,10 @@ local function trash_sign(base_pos, robot_pos, param2, slot)
local node = tubelib2.get_node_lvm(pos1)
local sign = ItemStack("signs_bot:sign_cmnd")
minetest.remove_node(pos1)
signs_bot.bot_inv_put_item(base_pos, slot, sign)
local leftover = signs_bot.bot_inv_put_item(base_pos, slot, sign)
if leftover and leftover:get_count() > 0 then
signs_bot.lib.drop_items(robot_pos, leftover)
end
return signs_bot.DONE
end
return signs_bot.ERROR, I("Error: Position is protected")

View File

@ -157,9 +157,8 @@ end
local function bot_error(base_pos, mem, err)
minetest.sound_play('signs_bot_error', {pos = base_pos})
minetest.sound_play('signs_bot_error', {pos = mem.robot_pos})
print(err)
signs_bot.infotext(base_pos, err)
mem.error = true
mem.error = err
return false
end

View File

@ -2,7 +2,7 @@
local MP = minetest.get_modpath("signs_bot")
local I,_ = dofile(MP.."/intllib.lua")
local NUM_LEAVES = 4
local NUM_LEAVES = 2
-- we reuse the minecart hopper API here
local function additem(mem, stack)
@ -46,7 +46,7 @@ if minetest.global_exists("signs_bot") then
mod = "compost",
params = "<slot>",
num_param = 1,
description = I("Put 4 leaves into the compost barrel\n"..
description = I("Put 2 leaves into the compost barrel\n"..
"<slot> is the bot inventory slot (1..8)\n"..
"with the leaves."),
check = function(slot)

View File

@ -87,6 +87,7 @@ minetest.register_node("signs_bot:crop_sensor", {
update_infotext = update_infotext,
on_rotate = screwdriver.disallow,
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
paramtype2 = "facedir",
is_ground_content = false,
@ -117,6 +118,7 @@ minetest.register_node("signs_bot:crop_sensor_on", {
update_infotext = update_infotext,
on_rotate = screwdriver.disallow,
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
paramtype2 = "facedir",
is_ground_content = false,

View File

@ -172,6 +172,7 @@ minetest.register_node("signs_bot:delayer", {
update_infotext = update_infotext,
on_rotate = screwdriver.disallow,
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
paramtype2 = "facedir",
is_ground_content = false,
@ -203,6 +204,7 @@ minetest.register_node("signs_bot:delayer_loaded", {
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
use_texture_alpha = "clip",
is_ground_content = false,
diggable = false,
groups = {sign_bot_sensor = 1, not_in_creative_inventory = 1},
@ -230,6 +232,7 @@ minetest.register_node("signs_bot:delayer_on", {
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
use_texture_alpha = "clip",
is_ground_content = false,
diggable = false,
groups = {sign_bot_sensor = 1, not_in_creative_inventory = 1},

View File

@ -60,6 +60,7 @@ minetest.register_node("signs_bot:sensor_extender", {
update_infotext = update_infotext,
on_rotate = screwdriver.disallow,
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
paramtype2 = "facedir",
is_ground_content = false,
@ -108,6 +109,7 @@ minetest.register_node("signs_bot:sensor_extender_on", {
update_infotext = update_infotext,
on_rotate = screwdriver.disallow,
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
paramtype2 = "facedir",
is_ground_content = false,

View File

@ -170,6 +170,7 @@ minetest.register_node("signs_bot:and1", {
update_infotext = update_infotext,
on_rotate = screwdriver.disallow,
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
paramtype2 = "facedir",
is_ground_content = false,
@ -197,6 +198,7 @@ minetest.register_node("signs_bot:and2", {
update_infotext = update_infotext,
on_rotate = screwdriver.disallow,
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
paramtype2 = "facedir",
is_ground_content = false,
@ -223,6 +225,7 @@ minetest.register_node("signs_bot:and3", {
update_infotext = update_infotext,
on_rotate = screwdriver.disallow,
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
paramtype2 = "facedir",
is_ground_content = false,

View File

@ -149,6 +149,7 @@ minetest.register_node("signs_bot:node_sensor", {
on_receive_fields = on_receive_fields,
on_rotate = screwdriver.disallow,
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
paramtype2 = "facedir",
is_ground_content = false,
@ -180,6 +181,7 @@ minetest.register_node("signs_bot:node_sensor_on", {
on_receive_fields = on_receive_fields,
on_rotate = screwdriver.disallow,
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
paramtype2 = "facedir",
is_ground_content = false,

View File

@ -76,6 +76,7 @@ minetest.register_node("signs_bot:robot", {
},
paramtype2 = "facedir",
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
is_ground_content = false,
drop = "",
@ -96,6 +97,7 @@ minetest.register_node("signs_bot:robot_leg", {
},
paramtype2 = "facedir",
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
is_ground_content = false,
drop = "",
@ -115,6 +117,7 @@ minetest.register_node("signs_bot:robot_foot", {
},
paramtype2 = "facedir",
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
is_ground_content = false,
drop = "",

View File

@ -59,6 +59,7 @@ local function register_sign(def)
end,
on_rotate = screwdriver.disallow,
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
is_ground_content = false,
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2, sign_bot_sign = 1},

View File

@ -160,6 +160,7 @@ minetest.register_node("signs_bot:timer", {
update_infotext = update_infotext,
on_rotate = screwdriver.disallow,
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
paramtype2 = "facedir",
is_ground_content = false,
@ -186,6 +187,7 @@ minetest.register_node("signs_bot:timer_on", {
update_infotext = update_infotext,
on_rotate = screwdriver.disallow,
paramtype = "light",
use_texture_alpha = "clip",
sunlight_propagates = true,
paramtype2 = "facedir",
is_ground_content = false,

View File

@ -30,21 +30,23 @@ local function get_current_data(pointed_thing)
end
local function get_stored_data(placer)
local spos = placer:get_attribute("signs_bot_spos")
local name = placer:get_attribute("signs_bot_name")
local meta = placer:get_meta()
local spos = meta:get_string("signs_bot_spos")
local name = meta:get_string("signs_bot_name")
if spos ~= "" then
return minetest.string_to_pos(spos), name
end
end
local function store_data(placer, pos, name)
local meta = placer:get_meta()
if pos then
local spos = minetest.pos_to_string(pos)
placer:set_attribute("signs_bot_spos", spos)
placer:set_attribute("signs_bot_name", name)
meta:set_string("signs_bot_spos", spos)
meta:set_string("signs_bot_name", name)
else
placer:set_attribute("signs_bot_spos", nil)
placer:set_attribute("signs_bot_name", nil)
meta:set_string("signs_bot_spos", nil)
meta:set_string("signs_bot_name", nil)
end
end