Adapt mod for techage v1
This commit is contained in:
parent
7c22ab3636
commit
bd9c76cdf6
44
basis.lua
44
basis.lua
@ -21,9 +21,9 @@ local S = signs_bot.S
|
|||||||
local lib = signs_bot.lib
|
local lib = signs_bot.lib
|
||||||
|
|
||||||
signs_bot.MAX_CAPA = 600
|
signs_bot.MAX_CAPA = 600
|
||||||
local PWR_NEEDED = 8
|
|
||||||
|
|
||||||
local CYCLE_TIME = 1
|
local CYCLE_TIME = 1
|
||||||
|
local CYCLE_TIME2 = 2 -- for charging phase
|
||||||
|
|
||||||
local function in_range(val, min, max)
|
local function in_range(val, min, max)
|
||||||
if val < min then return min end
|
if val < min then return min end
|
||||||
@ -233,14 +233,14 @@ function signs_bot.stop_robot(base_pos, mem)
|
|||||||
if mem.signal_request ~= true then
|
if mem.signal_request ~= true then
|
||||||
mem.running = false
|
mem.running = false
|
||||||
if minetest.global_exists("techage") then
|
if minetest.global_exists("techage") then
|
||||||
minetest.get_node_timer(base_pos):start(4)
|
minetest.get_node_timer(base_pos):start(CYCLE_TIME2)
|
||||||
mem.charging = true
|
mem.charging = true
|
||||||
mem.power_available = false
|
mem.power_available = false
|
||||||
else
|
else
|
||||||
minetest.get_node_timer(base_pos):stop()
|
minetest.get_node_timer(base_pos):stop()
|
||||||
mem.charging = false
|
mem.charging = false
|
||||||
end
|
end
|
||||||
if mem.power_available then
|
if mem.charging then
|
||||||
signs_bot.infotext(base_pos, S("charging"))
|
signs_bot.infotext(base_pos, S("charging"))
|
||||||
else
|
else
|
||||||
signs_bot.infotext(base_pos, S("stopped"))
|
signs_bot.infotext(base_pos, S("stopped"))
|
||||||
@ -387,19 +387,6 @@ if minetest.global_exists("techage") then
|
|||||||
drop = ""
|
drop = ""
|
||||||
end
|
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
|
|
||||||
|
|
||||||
local function on_nopower(pos)
|
|
||||||
local mem = tubelib2.get_mem(pos)
|
|
||||||
mem.power_available = false
|
|
||||||
signs_bot.infotext(pos, S("no power"))
|
|
||||||
end
|
|
||||||
|
|
||||||
minetest.register_node("signs_bot:box", {
|
minetest.register_node("signs_bot:box", {
|
||||||
description = S("Signs Bot Box"),
|
description = S("Signs Bot Box"),
|
||||||
stack_max = 1,
|
stack_max = 1,
|
||||||
@ -478,31 +465,6 @@ minetest.register_node("signs_bot:box", {
|
|||||||
on_timer = node_timer,
|
on_timer = node_timer,
|
||||||
on_rotate = screwdriver.disallow,
|
on_rotate = screwdriver.disallow,
|
||||||
|
|
||||||
-- techage power definition
|
|
||||||
tubelib2_on_update2 = function(pos, outdir, tlib2, node)
|
|
||||||
if minetest.global_exists("techage") then
|
|
||||||
techage.power.update_network(pos, outdir, tlib2)
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
networks = {
|
|
||||||
ele1 = {
|
|
||||||
sides = {L=1, U=1, D=1, F=1, B=1},
|
|
||||||
ntype = "con1",
|
|
||||||
on_power = function(pos)
|
|
||||||
local mem = tubelib2.get_mem(pos)
|
|
||||||
mem.power_available = true
|
|
||||||
signs_bot.infotext(pos, S("charging"))
|
|
||||||
end,
|
|
||||||
on_nopower = function(pos)
|
|
||||||
local mem = tubelib2.get_mem(pos)
|
|
||||||
mem.power_available = false
|
|
||||||
signs_bot.infotext(pos, S("no power"))
|
|
||||||
end,
|
|
||||||
nominal = PWR_NEEDED,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
-- techage power definition
|
|
||||||
|
|
||||||
drop = drop,
|
drop = drop,
|
||||||
paramtype2 = "facedir",
|
paramtype2 = "facedir",
|
||||||
is_ground_content = false,
|
is_ground_content = false,
|
||||||
|
@ -156,6 +156,7 @@ end
|
|||||||
local function bot_error(base_pos, mem, err, cmd)
|
local function bot_error(base_pos, mem, err, cmd)
|
||||||
minetest.sound_play('signs_bot_error', {pos = base_pos})
|
minetest.sound_play('signs_bot_error', {pos = base_pos})
|
||||||
minetest.sound_play('signs_bot_error', {pos = mem.robot_pos})
|
minetest.sound_play('signs_bot_error', {pos = mem.robot_pos})
|
||||||
|
err = err or "unknown"
|
||||||
if cmd then
|
if cmd then
|
||||||
signs_bot.infotext(base_pos, err .. ":\n'" .. cmd .. "'")
|
signs_bot.infotext(base_pos, err .. ":\n'" .. cmd .. "'")
|
||||||
mem.error = err .. ": '" .. cmd .. "'"
|
mem.error = err .. ": '" .. cmd .. "'"
|
||||||
|
@ -29,7 +29,7 @@ local function additem(mem, stack)
|
|||||||
pos = {x = pos.x, y = pos.y - 1, z = pos.z}
|
pos = {x = pos.x, y = pos.y - 1, z = pos.z}
|
||||||
node = minetest.get_node(pos)
|
node = minetest.get_node(pos)
|
||||||
ndef = minetest.registered_nodes[node.name]
|
ndef = minetest.registered_nodes[node.name]
|
||||||
if ndef.minecart_hopper_additem then
|
if ndef and ndef.minecart_hopper_additem then
|
||||||
return ndef.minecart_hopper_additem(pos, stack)
|
return ndef.minecart_hopper_additem(pos, stack)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ local function takeitem(mem)
|
|||||||
pos = {x = pos.x, y = pos.y - 1, z = pos.z}
|
pos = {x = pos.x, y = pos.y - 1, z = pos.z}
|
||||||
node = minetest.get_node(pos)
|
node = minetest.get_node(pos)
|
||||||
ndef = minetest.registered_nodes[node.name]
|
ndef = minetest.registered_nodes[node.name]
|
||||||
if ndef.minecart_hopper_takeitem then
|
if ndef and ndef.minecart_hopper_takeitem then
|
||||||
return ndef.minecart_hopper_takeitem(pos, 1)
|
return ndef.minecart_hopper_takeitem(pos, 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
4
init.lua
4
init.lua
@ -20,8 +20,8 @@ signs_bot.version = 1.08
|
|||||||
-- Test for MT 5.4 new string mode
|
-- Test for MT 5.4 new string mode
|
||||||
signs_bot.CLIP = minetest.features.use_texture_alpha_string_modes and "clip" or true
|
signs_bot.CLIP = minetest.features.use_texture_alpha_string_modes and "clip" or true
|
||||||
|
|
||||||
if minetest.global_exists("techage") and techage.version < 0.25 then
|
if minetest.global_exists("techage") and techage.version < 1.0 then
|
||||||
error("[signs_bot] Signs Bot requires techage version 0.25 or newer!")
|
error("[signs_bot] Signs Bot requires techage version 1.0 or newer!")
|
||||||
end
|
end
|
||||||
|
|
||||||
if tubelib2.version < 1.9 then
|
if tubelib2.version < 1.9 then
|
||||||
|
@ -188,7 +188,7 @@ register_command("end", 0,
|
|||||||
register_command("call", 1,
|
register_command("call", 1,
|
||||||
function(base_pos, mem, addr)
|
function(base_pos, mem, addr)
|
||||||
if #mem.Stack > 99 then
|
if #mem.Stack > 99 then
|
||||||
return api.ERROR
|
return api.ERROR, "call stack overrun"
|
||||||
end
|
end
|
||||||
mem.Stack[#mem.Stack + 1] = mem.pc + 2
|
mem.Stack[#mem.Stack + 1] = mem.pc + 2
|
||||||
mem.pc = addr - 2
|
mem.pc = addr - 2
|
||||||
@ -202,7 +202,7 @@ register_command("call", 1,
|
|||||||
register_command("return", 0,
|
register_command("return", 0,
|
||||||
function(base_pos, mem)
|
function(base_pos, mem)
|
||||||
if #mem.Stack < 1 then
|
if #mem.Stack < 1 then
|
||||||
return api.ERROR
|
return api.ERROR, "no return address"
|
||||||
end
|
end
|
||||||
mem.pc = (mem.Stack[#mem.Stack] or 1) - 1
|
mem.pc = (mem.Stack[#mem.Stack] or 1) - 1
|
||||||
mem.Stack[#mem.Stack] = nil
|
mem.Stack[#mem.Stack] = nil
|
||||||
|
54
techage.lua
54
techage.lua
@ -8,19 +8,33 @@
|
|||||||
GPLv3
|
GPLv3
|
||||||
See LICENSE.txt for more information
|
See LICENSE.txt for more information
|
||||||
|
|
||||||
Signs Bot: Bot Flap
|
Signs Bot: interface for techage
|
||||||
|
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
-- Load support for I18n.
|
-- Load support for I18n.
|
||||||
local S = signs_bot.S
|
local S = signs_bot.S
|
||||||
|
|
||||||
local CYCLE_TIME = 4
|
local MAX_CAPA = signs_bot.MAX_CAPA
|
||||||
|
local PWR_NEEDED = 8
|
||||||
|
|
||||||
if minetest.get_modpath("techage") then
|
if minetest.get_modpath("techage") then
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
local function on_nopower(pos)
|
||||||
|
local mem = tubelib2.get_mem(pos)
|
||||||
|
mem.power_available = false
|
||||||
|
signs_bot.infotext(pos, S("no power"))
|
||||||
|
end
|
||||||
|
|
||||||
local Cable = techage.ElectricCable
|
local Cable = techage.ElectricCable
|
||||||
local power = techage.power
|
local power = networks.power
|
||||||
|
|
||||||
signs_bot.register_inventory({"techage:chest_ta2", "techage:chest_ta3", "techage:chest_ta4",
|
signs_bot.register_inventory({"techage:chest_ta2", "techage:chest_ta3", "techage:chest_ta4",
|
||||||
"techage:ta3_silo", "techage:ta4_silo", "techage:ta4_sensor_chest"}, {
|
"techage:ta3_silo", "techage:ta4_silo", "techage:ta4_sensor_chest"}, {
|
||||||
@ -164,26 +178,22 @@ send_cmnd 3465 pull*default:dirt*2]]),
|
|||||||
-- Bot in the box
|
-- Bot in the box
|
||||||
function signs_bot.while_charging(pos, mem)
|
function signs_bot.while_charging(pos, mem)
|
||||||
mem.capa = mem.capa or 0
|
mem.capa = mem.capa or 0
|
||||||
if mem.power_available then
|
|
||||||
if mem.capa < signs_bot.MAX_CAPA then
|
if mem.capa < signs_bot.MAX_CAPA then
|
||||||
local taken = power.consumer_alive(pos, Cable, CYCLE_TIME)
|
local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED)
|
||||||
mem.capa = mem.capa + taken
|
mem.capa = mem.capa + consumed
|
||||||
else
|
|
||||||
power.consumer_stop(pos, Cable)
|
|
||||||
minetest.get_node_timer(pos):stop()
|
|
||||||
mem.charging = false
|
|
||||||
if not mem.running then
|
|
||||||
signs_bot.infotext(pos, S("fully charged"))
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
power.consumer_start(pos, Cable, CYCLE_TIME)
|
minetest.get_node_timer(pos):stop()
|
||||||
|
mem.charging = false
|
||||||
|
if not mem.running then
|
||||||
|
signs_bot.infotext(pos, S("fully charged"))
|
||||||
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
Cable:add_secondary_node_names({"signs_bot:box"})
|
power.register_nodes({"signs_bot:box"}, Cable, "con")
|
||||||
|
|
||||||
techage.register_node({"signs_bot:box"}, {
|
techage.register_node({"signs_bot:box"}, {
|
||||||
on_inv_request = function(pos, in_dir, access_type)
|
on_inv_request = function(pos, in_dir, access_type)
|
||||||
@ -266,9 +276,13 @@ send_cmnd 3465 pull*default:dirt*2]]),
|
|||||||
return techage.put_items(inv, "main", stack)
|
return techage.put_items(inv, "main", stack)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
techage.register_node_for_v1_transition({"signs_bot:box"}, function(pos, node)
|
||||||
|
power.update_network(pos, nil, Cable)
|
||||||
|
end)
|
||||||
else
|
else
|
||||||
function signs_bot.formspec_battery_capa(max_capa, current_capa)
|
function signs_bot.formspec_battery_capa(max_capa, current_capa)
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user