outlet fix - when switching station disconnects or looses power

This commit is contained in:
rnd1 2015-10-19 18:19:20 +02:00
parent c71e303842
commit 50bde1cfe0
2 changed files with 9 additions and 7 deletions

View File

@ -27,9 +27,11 @@ end
local max_range = 10; -- machines range of operation local max_range = 10; -- machines range of operation
local machines_timer = 5 -- timestep local machines_timer = 5 -- timestep
local machines_TTL = 4; -- time to live for signals local machines_TTL = 4; -- time to live for signals
MOVER_FUEL_STORAGE_CAPACITY = 5; -- how many operations from one coal lump - base unit MOVER_FUEL_STORAGE_CAPACITY = 5; -- how many operations from one coal lump - base unit
basic_machines.fuels = {["default:coal_lump"]=1,["default:cactus"]=0.75,["default:tree"]=1,["default:jungletree"]=1,["default:pinetree"]=1,["default:coalblock"]=10,["default:lava_source"]=40};
minetest.register_node("basic_machines:mover", { minetest.register_node("basic_machines:mover", {
description = "Mover", description = "Mover",
@ -187,9 +189,9 @@ minetest.register_node("basic_machines:mover", {
local cmeta = minetest.get_meta(fpos); local cmeta = minetest.get_meta(fpos);
local inv = cmeta:get_inventory(); local inv = cmeta:get_inventory();
--fuels and their caloric value: 1 = 5 uses, TODO; add unknown fuels from minetest fuels --fuels and their caloric value: 1 = 5 uses, TODO; add unknown fuels from minetest fuels
local fuels = {["default:coal_lump"]=1,["default:cactus"]=0.75,["default:tree"]=1,["default:coalblock"]=10,["default:lava_source"]=40};
local stack; local stack;
for i,v in pairs(fuels) do for i,v in pairs(basic_machines.fuels) do
stack = ItemStack({name=i}) stack = ItemStack({name=i})
if inv:contains_item("main", stack) then found_fuel = v;inv:remove_item("main", stack) break end if inv:contains_item("main", stack) then found_fuel = v;inv:remove_item("main", stack) break end
end end

View File

@ -55,11 +55,11 @@ function basic_machines.check_power(pos) -- mover checks power source
local meta = minetest.get_meta({x=pos.x,y=pos.y-1,z=pos.z}); local meta = minetest.get_meta({x=pos.x,y=pos.y-1,z=pos.z});
local p = minetest.string_to_pos(meta:get_string("station")); if not p then return end local p = minetest.string_to_pos(meta:get_string("station")); if not p then return end
local smeta = minetest.get_meta(p); local smeta = minetest.get_meta(p); if not smeta then return end
local infot = smeta:get_string("infotext"); local infot = smeta:get_string("infotext");
--local infot = "Switching Station. Supply: 516 Demand: 0"; --local infot = "Switching Station. Supply: 516 Demand: 0";
local i = string.find(infot,"Supply"); local i = string.find(infot,"Supply") or 1;
local j = string.find(infot,"Demand"); local j = string.find(infot,"Demand") or 1;
local supply = tonumber(string.sub(infot,i+8,j-1)) or 0; local supply = tonumber(string.sub(infot,i+8,j-1)) or 0;
local demand = tonumber(string.sub(infot, j+8)) or 0; local demand = tonumber(string.sub(infot, j+8)) or 0;
supply= supply-demand-(smeta:get_int("bdemand") or 999999); supply= supply-demand-(smeta:get_int("bdemand") or 999999);