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
|
||||
|
||||
signs_bot.MAX_CAPA = 600
|
||||
local PWR_NEEDED = 8
|
||||
|
||||
local CYCLE_TIME = 1
|
||||
local CYCLE_TIME2 = 2 -- for charging phase
|
||||
|
||||
local function in_range(val, min, max)
|
||||
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
|
||||
mem.running = false
|
||||
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.power_available = false
|
||||
else
|
||||
minetest.get_node_timer(base_pos):stop()
|
||||
mem.charging = false
|
||||
end
|
||||
if mem.power_available then
|
||||
if mem.charging then
|
||||
signs_bot.infotext(base_pos, S("charging"))
|
||||
else
|
||||
signs_bot.infotext(base_pos, S("stopped"))
|
||||
@ -387,19 +387,6 @@ if minetest.global_exists("techage") then
|
||||
drop = ""
|
||||
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", {
|
||||
description = S("Signs Bot Box"),
|
||||
stack_max = 1,
|
||||
@ -478,31 +465,6 @@ minetest.register_node("signs_bot:box", {
|
||||
on_timer = node_timer,
|
||||
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,
|
||||
paramtype2 = "facedir",
|
||||
is_ground_content = false,
|
||||
|
@ -156,6 +156,7 @@ end
|
||||
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 = mem.robot_pos})
|
||||
err = err or "unknown"
|
||||
if cmd then
|
||||
signs_bot.infotext(base_pos, err .. ":\n'" .. 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}
|
||||
node = minetest.get_node(pos)
|
||||
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)
|
||||
end
|
||||
|
||||
@ -47,7 +47,7 @@ local function takeitem(mem)
|
||||
pos = {x = pos.x, y = pos.y - 1, z = pos.z}
|
||||
node = minetest.get_node(pos)
|
||||
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)
|
||||
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
|
||||
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
|
||||
error("[signs_bot] Signs Bot requires techage version 0.25 or newer!")
|
||||
if minetest.global_exists("techage") and techage.version < 1.0 then
|
||||
error("[signs_bot] Signs Bot requires techage version 1.0 or newer!")
|
||||
end
|
||||
|
||||
if tubelib2.version < 1.9 then
|
||||
|
@ -188,7 +188,7 @@ register_command("end", 0,
|
||||
register_command("call", 1,
|
||||
function(base_pos, mem, addr)
|
||||
if #mem.Stack > 99 then
|
||||
return api.ERROR
|
||||
return api.ERROR, "call stack overrun"
|
||||
end
|
||||
mem.Stack[#mem.Stack + 1] = mem.pc + 2
|
||||
mem.pc = addr - 2
|
||||
@ -202,7 +202,7 @@ register_command("call", 1,
|
||||
register_command("return", 0,
|
||||
function(base_pos, mem)
|
||||
if #mem.Stack < 1 then
|
||||
return api.ERROR
|
||||
return api.ERROR, "no return address"
|
||||
end
|
||||
mem.pc = (mem.Stack[#mem.Stack] or 1) - 1
|
||||
mem.Stack[#mem.Stack] = nil
|
||||
|
54
techage.lua
54
techage.lua
@ -8,19 +8,33 @@
|
||||
GPLv3
|
||||
See LICENSE.txt for more information
|
||||
|
||||
Signs Bot: Bot Flap
|
||||
Signs Bot: interface for techage
|
||||
|
||||
]]--
|
||||
|
||||
-- Load support for I18n.
|
||||
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
|
||||
|
||||
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 power = techage.power
|
||||
local power = networks.power
|
||||
|
||||
signs_bot.register_inventory({"techage:chest_ta2", "techage:chest_ta3", "techage:chest_ta4",
|
||||
"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
|
||||
function signs_bot.while_charging(pos, mem)
|
||||
mem.capa = mem.capa or 0
|
||||
if mem.power_available then
|
||||
if mem.capa < signs_bot.MAX_CAPA then
|
||||
local taken = power.consumer_alive(pos, Cable, CYCLE_TIME)
|
||||
mem.capa = mem.capa + taken
|
||||
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
|
||||
|
||||
if mem.capa < signs_bot.MAX_CAPA then
|
||||
local consumed = power.consume_power(pos, Cable, nil, PWR_NEEDED)
|
||||
mem.capa = mem.capa + consumed
|
||||
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
|
||||
return true
|
||||
end
|
||||
|
||||
Cable:add_secondary_node_names({"signs_bot:box"})
|
||||
power.register_nodes({"signs_bot:box"}, Cable, "con")
|
||||
|
||||
techage.register_node({"signs_bot:box"}, {
|
||||
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)
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
techage.register_node_for_v1_transition({"signs_bot:box"}, function(pos, node)
|
||||
power.update_network(pos, nil, Cable)
|
||||
end)
|
||||
else
|
||||
function signs_bot.formspec_battery_capa(max_capa, current_capa)
|
||||
return ""
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user