added new machine: power outlet
uses unused available supply from nearby switching station to power machines like mover. to use it just place it under machine to be powered.master
parent
c9a4f84a2f
commit
712b765975
3
init.lua
3
init.lua
|
@ -1,6 +1,9 @@
|
|||
basic_machines = {};
|
||||
dofile(minetest.get_modpath("basic_machines").."/mark.lua") -- used for markings, borrowed and adapted from worldedit mod
|
||||
dofile(minetest.get_modpath("basic_machines").."/technic_power.lua") -- technic power for mover
|
||||
dofile(minetest.get_modpath("basic_machines").."/mover.lua")
|
||||
dofile(minetest.get_modpath("basic_machines").."/recycler.lua")
|
||||
|
||||
dofile(minetest.get_modpath("basic_machines").."/autocrafter.lua") -- borrowed from pipeworks mod
|
||||
|
||||
-- IF USING UNTERNULL GAME COMMENT THE FOLLOWING
|
||||
|
|
44
mover.lua
44
mover.lua
|
@ -171,28 +171,44 @@ minetest.register_node("basic_machines:mover", {
|
|||
end
|
||||
end
|
||||
|
||||
if not fpos then return end -- no chest found
|
||||
local cmeta = minetest.get_meta(fpos);
|
||||
local inv = cmeta:get_inventory();
|
||||
--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;
|
||||
for i,v in pairs(fuels) do
|
||||
stack = ItemStack({name=i})
|
||||
if inv:contains_item("main", stack) then found_fuel = v break end
|
||||
if not fpos then -- no chest, check for alternative technic power sources
|
||||
|
||||
local supply = basic_machines.check_power(pos) or 0;
|
||||
--minetest.chat_send_all(" checking outlet. supply " .. supply)
|
||||
if supply>0 then
|
||||
fuel = fuel + MOVER_FUEL_STORAGE_CAPACITY; -- adds as much fuel as 1 coal lump
|
||||
meta:set_string("infotext", "Mover block refueled from an outlet. fuel ".. fuel);
|
||||
else
|
||||
meta:set_string("infotext", "Mover block. Put fuel chest near mover or place outlet below mover.");
|
||||
end
|
||||
|
||||
else -- look in chest for fuel
|
||||
|
||||
local cmeta = minetest.get_meta(fpos);
|
||||
local inv = cmeta:get_inventory();
|
||||
--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;
|
||||
for i,v in pairs(fuels) do
|
||||
stack = ItemStack({name=i})
|
||||
if inv:contains_item("main", stack) then found_fuel = v;inv:remove_item("main", stack) break end
|
||||
end
|
||||
-- check for this fuel
|
||||
|
||||
end
|
||||
-- check for this fuel
|
||||
|
||||
if found_fuel~=nil then
|
||||
--minetest.chat_send_all(" refueled ")
|
||||
inv:remove_item("main", stack)
|
||||
|
||||
meta:set_float("fuel", fuel+MOVER_FUEL_STORAGE_CAPACITY*found_fuel);
|
||||
fuel = fuel+MOVER_FUEL_STORAGE_CAPACITY*found_fuel;
|
||||
meta:set_string("infotext", "Mover block refueled. Fuel "..MOVER_FUEL_STORAGE_CAPACITY);
|
||||
else meta:set_string("infotext", "Mover block. Out of fuel. Put fuel chest near mover.");return
|
||||
|
||||
end
|
||||
--check fuel
|
||||
if fuel == 0 then return end
|
||||
|
||||
end
|
||||
|
||||
if fuel <= 0 then meta:set_string("infotext", "Mover block. Out of fuel. Put fuel chest near mover or place outlet below it."); return end
|
||||
|
||||
local owner = meta:get_string("owner");
|
||||
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
-- rnd 2015, power outlet
|
||||
-- used to power basic_machines using remaining available power from technic:switching_station. Just place it below mover but within 10 block distance of technich switching station. Each power outlet adds 500 to the power demand. If switching station has not enough unused power ( after technic machines demand), it wont supply power to mover.
|
||||
|
||||
local outlet_power_demand = 500;
|
||||
|
||||
|
||||
minetest.register_node("basic_machines:outlet", {
|
||||
description = "Power outlet",
|
||||
tiles = {"outlet.png"},
|
||||
groups = {oddly_breakable_by_hand=2,mesecon_effector_on = 1},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
after_place_node = function(pos, placer)
|
||||
local meta = minetest.get_meta(pos);
|
||||
meta:set_string("infotext", "Outlet: put it below mover and near (10 blocks) technic switching station. If switching station has at least 300 free supply it will be used to power mover")
|
||||
local r = 10;
|
||||
local positions = minetest.find_nodes_in_area(
|
||||
{x=pos.x-r, y=pos.y-r, z=pos.z-r},
|
||||
{x=pos.x+r, y=pos.y+r, z=pos.z+r},
|
||||
"technic:switching_station")
|
||||
if not positions then
|
||||
meta:set_string("infotext","outlet: error. please place it near technic switching station (within 10 blocks distance)"); return
|
||||
end
|
||||
|
||||
local p = positions[1]; if not p then return end
|
||||
local smeta = minetest.get_meta(p);
|
||||
local bdemand = smeta:get_int("bdemand") or 0;
|
||||
bdemand = bdemand + outlet_power_demand; smeta:set_int("bdemand", bdemand);
|
||||
--minetest.chat_send_all("demand "..bdemand);
|
||||
meta:set_string("infotext","outlet connected to switching station at "..p.x .. " " .. p.y .. " " .. p.z);
|
||||
|
||||
meta:set_string("station",minetest.pos_to_string(p)); -- remember where station is
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger) -- remove demand from switching station
|
||||
local r = 10;
|
||||
local positions = minetest.find_nodes_in_area(
|
||||
{x=pos.x-r, y=pos.y-r, z=pos.z-r},
|
||||
{x=pos.x+r, y=pos.y+r, z=pos.z+r},
|
||||
"technic:switching_station")
|
||||
if not positions then return end
|
||||
|
||||
local p = positions[1]; if not p then return end
|
||||
local smeta = minetest.get_meta(p);
|
||||
local bdemand = smeta:get_int("bdemand") or 0;
|
||||
bdemand = math.max(bdemand - outlet_power_demand,0); smeta:set_int("bdemand", bdemand);
|
||||
--minetest.chat_send_all("demand "..bdemand);
|
||||
end
|
||||
|
||||
})
|
||||
|
||||
function basic_machines.check_power(pos) -- mover checks power source
|
||||
if minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name ~= "basic_machines:outlet"
|
||||
then return 0
|
||||
end
|
||||
|
||||
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 smeta = minetest.get_meta(p);
|
||||
local infot = smeta:get_string("infotext");
|
||||
--local infot = "Switching Station. Supply: 516 Demand: 0";
|
||||
local i = string.find(infot,"Supply");
|
||||
local j = string.find(infot,"Demand");
|
||||
local supply = tonumber(string.sub(infot,i+8,j-1)) or 0;
|
||||
local demand = tonumber(string.sub(infot, j+8)) or 0;
|
||||
supply= supply-demand-(smeta:get_int("bdemand") or 999999);
|
||||
if supply>0 then
|
||||
return supply
|
||||
else return 0
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
output = "basic_machines:outlet",
|
||||
recipe = {
|
||||
{"default:mese_crystal","default:steel_ingot","default:mese_crystal"},
|
||||
{"default:mese_crystal","default:diamondblock","default:mese_crystal"},
|
||||
{"default:mese_crystal","default:mese_crystal","default:mese_crystal"},
|
||||
|
||||
}
|
||||
})
|
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
Loading…
Reference in New Issue