Add leaves to cutting command, fix rotate bug, fix farming:peas bug

master
Joachim Stolberg 2021-05-09 15:10:45 +02:00
parent a2da9f8393
commit 291b4d3fb5
9 changed files with 65 additions and 39 deletions

View File

@ -386,6 +386,7 @@ end
local function on_power(pos)
local mem = tubelib2.get_mem(pos)
mem.power_available = true
mem.charging = true
signs_bot.infotext(pos, S("charging"))
end

View File

@ -42,9 +42,12 @@ minetest.after(1, function()
end
end)
local function is_tree(name)
if minetest.get_item_group(name, "tree") == 1 then
return name
local function is_tree(node)
if minetest.get_item_group(node.name, "tree") == 1 then
return signs_bot.handle_drop_like_a_player(node)
end
if minetest.get_item_group(node.name, "leaves") == 1 then
return signs_bot.handle_drop_like_a_player(node)
end
end
@ -54,7 +57,7 @@ local function harvesting(base_pos, mem)
if pos and lib.not_protected(base_pos, pos) then
local node = minetest.get_node_or_nil(pos)
local drop = Flowers[node.name] or is_tree(node.name)
local drop = Flowers[node.name] or is_tree(node)
if drop then
minetest.remove_node(pos)
local leftover = bot_inv_put_item(base_pos, 0, ItemStack(drop))
@ -69,7 +72,7 @@ signs_bot.register_botcommand("cutting", {
mod = "farming",
params = "",
num_param = 0,
description = S("Cutting flowers and tree blocks\nin front of the robot\non a 3x3 field."),
description = S("Cutting flowers, leaves and tree blocks\nin front of the robot\non a 3x3 field."),
cmnd = function(base_pos, mem)
if not mem.steps then
mem.pos_tbl = signs_bot.lib.gen_position_table(mem.robot_pos, mem.robot_param2, 3, 3, 0)

View File

@ -366,6 +366,7 @@ end
signs_bot.register_botcommand("rotate_item", {
mod = "place",
params = "<lvl> <steps>",
num_param = 2,
description = S("Rotate the block in front of the robot\n"..
"<lvl> is one of: -1 0 +1\n"..
"<steps> is one of: 1 2 3"),

View File

@ -132,11 +132,11 @@ local function gen_string_cmnd(code, pc, num_param, script)
if num_param == 0 then
return tokens[pc]
elseif num_param == 1 then
return tokens[pc] .. " " .. tokens[pc+1]
return tokens[pc] .. " " .. (tokens[pc+1] or "")
elseif num_param == 2 then
return tokens[pc] .. " " .. tokens[pc+1] .. " " .. tokens[pc+2]
return tokens[pc] .. " " .. (tokens[pc+1] or "") .. " " .. (tokens[pc+2] or "")
else
return tokens[pc] .. " " .. tokens[pc+1] .. " " .. tokens[pc+2] .. " " .. tokens[pc+3]
return tokens[pc] .. " " .. (tokens[pc+1] or "") .. " " .. (tokens[pc+2] or "") .. " " .. (tokens[pc+3] or "")
end
end

21
lib.lua
View File

@ -74,7 +74,24 @@ function signs_bot.lib.check_pos(posA, nodeA, nodeB, param2)
return false
end
local function handle_drop(node)
local function handle_drop(drop)
-- To keep it simple, return only the item with the lowest rarity
if drop.items then
local rarity = 9999
local name
for idx,item in ipairs(drop.items) do
if item.rarity and item.rarity < rarity then
rarity = item.rarity
name = item.items[1] -- take always the first item
else
return item.items[1] -- take always the first item
end
end
return name
end
end
function signs_bot.handle_drop_like_a_player(node)
local drops = minetest.get_node_drops(node)
if #drops >= 1 then
return drops[1]
@ -104,7 +121,7 @@ function signs_bot.lib.is_simple_node(node)
if ndef.after_dig_node then return false end
end
if type(ndef.drop) == "table" then
return handle_drop(node)
return handle_drop(ndef.drop)
end
return ndef.drop or node.name
end

View File

@ -87,19 +87,19 @@ Sign 'farming'=Zeichen 'Farming'
Used to harvest and seed a 3x3 field.=Benötigt um ein 3x3 Feld zu ernten und wieder zu sähen.
The seed to be placed has to be in the first inventory slot of the bot.=Das Saatgut, dass gesät werden soll, muss sich an der 1. Position im Inventar befinden.
### cmd_flowers.lua ###
Cutting flowers and tree blocks@nin front of the robot@non a 3x3 field.=Schneide Blumen und Baumblöcke@nin einem 3x3 großem Feld@nvor dem Roboter.
Sign "flowers"=Zeichen "Blumen"
Sign 'flowers'=Zeichen 'Blumen'
Used to cut flowers on a 3x3 field.=Benötigt um ein 3x3 Blumenfeld zu ernten.
### cmd_flowers.lua ###
### cmd_farming.lua ###
### cmd_flowers.lua ###
Place the sign in front of the field.=Platziere das Zeichen vor das Feld.
When finished, the bot turns.=Der Roboter dreht um, wenn er fertig ist.
### cmd_flowers.lua ###
Cutting flowers, leaves and tree blocks@nin front of the robot@non a 3x3 field.=Schneide Blumen, Blätter und Baumblöcke@nin einem 3x3 großem Feld@nvor dem Roboter.
Sign "flowers"=Zeichen "Blumen"
Sign 'flowers'=Zeichen 'Blumen'
Used to cut flowers on a 3x3 field.=Benötigt um ein 3x3 Blumenfeld zu ernten.
### cmd_item.lua ###
Take <num> items from a chest like node@nand put it into the item inventory.@n<slot> is the inventory slot (1..8) or 0 for any one=Nehme <num> Gegenstände aus der@nKiste oder dem Kisten-ähnlichen Block@nund tue diese in das eigene Inventar@nan der Position <slot>. Slot = (1..8)@noder 0 für irgend eine Position
@ -179,11 +179,6 @@ The 'command' sign can be programmed by the player.=Das 'Kommando' Zeichen kann
Place the sign in front of you and use the node menu to program your sequence of bot commands.=Platziere das Zeichen vor dir und nutze das Zeichen-Menü, um die Kommando-Sequenz zu programmieren.
The menu has an edit field for your commands and a help page with all available commands.=Das Menü hat ein Eingabefeld für deine Kommandos und eine Hilfeseite zu allen Kommandos.
### cmd_sign.lua ###
### doc.lua ###
The help page has a copy button to simplify the programming.=Die Hilfeseite hat einen Kopier-Button um die Programmierung zu erleichtern.
### commands.lua ###
commands:=Kommandos:
@ -300,6 +295,11 @@ Sensors and Actuators=Sensoren und Aktoren
Connecting sensors and actuator=Verbinde Sensor mit Aktor
Bot inventory behavior=Verhalten beim Roboter Inventar
### doc.lua ###
### cmd_sign.lua ###
The help page has a copy button to simplify the programming.=Die Hilfeseite hat einen Kopier-Button um die Programmierung zu erleichtern.
### duplicator.lua ###
Template:=Vorlage:
@ -408,3 +408,6 @@ Connected with=Verbunden mit
### tool.lua ###
Sensor Connection Tool=Sensor Verbindungswerkzeug
##### not used anymore #####

View File

@ -87,19 +87,19 @@ Sign 'farming'=
Used to harvest and seed a 3x3 field.=
The seed to be placed has to be in the first inventory slot of the bot.=
### cmd_flowers.lua ###
Cutting flowers and tree blocks@nin front of the robot@non a 3x3 field.=
Sign "flowers"=
Sign 'flowers'=
Used to cut flowers on a 3x3 field.=
### cmd_flowers.lua ###
### cmd_farming.lua ###
### cmd_flowers.lua ###
Place the sign in front of the field.=
When finished, the bot turns.=
### cmd_flowers.lua ###
Cutting flowers, leaves and tree blocks@nin front of the robot@non a 3x3 field.=
Sign "flowers"=
Sign 'flowers'=
Used to cut flowers on a 3x3 field.=
### cmd_item.lua ###
Take <num> items from a chest like node@nand put it into the item inventory.@n<slot> is the inventory slot (1..8) or 0 for any one=
@ -179,11 +179,6 @@ The 'command' sign can be programmed by the player.=
Place the sign in front of you and use the node menu to program your sequence of bot commands.=
The menu has an edit field for your commands and a help page with all available commands.=
### cmd_sign.lua ###
### doc.lua ###
The help page has a copy button to simplify the programming.=
### commands.lua ###
commands:=
@ -300,6 +295,11 @@ Sensors and Actuators=
Connecting sensors and actuator=
Bot inventory behavior=
### doc.lua ###
### cmd_sign.lua ###
The help page has a copy button to simplify the programming.=
### duplicator.lua ###
Template:=

View File

@ -69,7 +69,7 @@ if farming.mod == "redo" then
fp("farming:cocoa_beans", "farming:cocoa_1", "farming:cocoa_4")
fp("farming:garlic_clove", "farming:garlic_1", "farming:garlic_5")
fp("farming:onion", "farming:onion_1", "farming:onion_5")
fp("farming:peas", "farming:pea_1", "farming:pea_5")
fp("farming:pea_pod", "farming:pea_1", "farming:pea_5")
fp("farming:peppercorn", "farming:pepper_1", "farming:pepper_5")
fp("farming:pineapple_top", "farming:pineapple_1", "farming:pineapple_8")
end

View File

@ -23,7 +23,7 @@ if minetest.get_modpath("techage") then
local power = techage.power
signs_bot.register_inventory({"techage:chest_ta2", "techage:chest_ta3", "techage:chest_ta4",
"techage:ta3_silo", "techage:ta4_silo"}, {
"techage:ta3_silo", "techage:ta4_silo", "techage:ta4_sensor_chest"}, {
allow_inventory_put = function(pos, stack, player_name)
return not minetest.is_protected(pos, player_name)
end,
@ -120,7 +120,8 @@ send_cmnd 3465 pull*default:dirt*2]]),
address = tostring(tonumber(address))
local meta = minetest.get_meta(base_pos)
local number = meta:get_int("number") or 0
techage.send_multi(number, address, command)
local topic, payload = unpack(string.split(command, " ", false, 1))
techage.send_multi(number, address, topic, payload)
return signs_bot.DONE
end,
})