heater, fixes
parent
3d946b9e7f
commit
9cac441bec
|
@ -0,0 +1,161 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bitumen.burners = {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function grab_fuel(inv)
|
||||||
|
|
||||||
|
local list = inv:get_list("fuel")
|
||||||
|
for i,st in ipairs(list) do
|
||||||
|
print(st:get_name())
|
||||||
|
local fuel, remains
|
||||||
|
fuel, remains = minetest.get_craft_result({
|
||||||
|
method = "fuel",
|
||||||
|
width = 1,
|
||||||
|
items = {
|
||||||
|
ItemStack(st:get_name())
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if fuel.time > 0 then
|
||||||
|
-- Take fuel from fuel list
|
||||||
|
st:take_item()
|
||||||
|
inv:set_stack("fuel", i, st)
|
||||||
|
|
||||||
|
return fuel.time
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return 0 -- no fuel found
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
bitumen.register_burner = function(nodes, callbacks)
|
||||||
|
local default_callbacks = {
|
||||||
|
grab_fuel = grab_fuel, -- needs to return the fuel time
|
||||||
|
start_cook = function() end, -- needs to return the cook time
|
||||||
|
finish_cook = function() end,
|
||||||
|
abort_cook = function() end,
|
||||||
|
get_formspec_on = bitumen.get_melter_active_formspec,
|
||||||
|
turn_on = function() end,
|
||||||
|
turn_off = function() end,
|
||||||
|
}
|
||||||
|
|
||||||
|
for k,v in pairs(callbacks) do
|
||||||
|
default_callbacks[k] = v
|
||||||
|
end
|
||||||
|
|
||||||
|
for _,n in ipairs(nodes) do
|
||||||
|
print("setting burner: "..n)
|
||||||
|
bitumen.burners[n] = default_callbacks
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bitumen.burner_on_timer = function(pos, elapsed)
|
||||||
|
|
||||||
|
local posnode = minetest.get_node(pos)
|
||||||
|
local fns = bitumen.burners[posnode.name]
|
||||||
|
if fns == nil then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local fuel_time = meta:get_float("fuel_time") or 0
|
||||||
|
local fuel_burned = meta:get_float("fuel_burned") or 0
|
||||||
|
local cook_time = meta:get_float("cook_time") or 0
|
||||||
|
local cook_burned = meta:get_float("cook_burned") or 0
|
||||||
|
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
|
||||||
|
local burned = elapsed
|
||||||
|
local turn_off = false
|
||||||
|
|
||||||
|
|
||||||
|
-- print("\n\naf timer")
|
||||||
|
--/ print("fuel_burned: " .. fuel_burned)
|
||||||
|
-- print("fuel_time: " .. fuel_time)
|
||||||
|
|
||||||
|
|
||||||
|
if fuel_time > 0 and fuel_burned + elapsed < fuel_time then
|
||||||
|
-- still good on fuel
|
||||||
|
fuel_burned = fuel_burned + elapsed
|
||||||
|
meta:set_float("fuel_burned", fuel_burned + elapsed)
|
||||||
|
else
|
||||||
|
local t = fns.grab_fuel(inv)
|
||||||
|
if t <= 0 then -- out of fuel
|
||||||
|
--print("out of fuel")
|
||||||
|
meta:set_float("fuel_time", 0)
|
||||||
|
meta:set_float("fuel_burned", 0)
|
||||||
|
|
||||||
|
burned = fuel_time - fuel_burned
|
||||||
|
|
||||||
|
turn_off = true
|
||||||
|
else
|
||||||
|
-- check if the machine is turning on
|
||||||
|
if fuel_time == 0 then
|
||||||
|
fns.turn_on(pos, meta, inv)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- roll into the next period
|
||||||
|
fuel_burned = elapsed - (fuel_time - fuel_burned)
|
||||||
|
fuel_time = t
|
||||||
|
|
||||||
|
meta:set_float("fuel_time", fuel_time)
|
||||||
|
meta:set_float("fuel_burned", fuel_burned)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--print("cooktime " .. cook_time)
|
||||||
|
--print("cookburned " .. cook_burned)
|
||||||
|
if cook_time == 0 then -- nothing cooking atm
|
||||||
|
--print("fueltime " .. fuel_time)
|
||||||
|
--print("turnoff " .. dump(turn_off))
|
||||||
|
if fuel_time ~= 0 and turn_off == false then -- should we start to cook?
|
||||||
|
cook_time = fns.start_cook(pos, meta, inv)
|
||||||
|
meta:set_float("cook_time", cook_time)
|
||||||
|
meta:set_float("cook_burned", 0)
|
||||||
|
else
|
||||||
|
-- no fuel
|
||||||
|
end
|
||||||
|
else -- continue cooking
|
||||||
|
cook_burned = cook_burned + burned
|
||||||
|
if cook_burned >= cook_time then -- cooking finished
|
||||||
|
fns.finish_cook(pos, met, inv)
|
||||||
|
|
||||||
|
local new_cook_time = fns.start_cook(pos, meta, inv)
|
||||||
|
meta:set_float("cook_time", new_cook_time)
|
||||||
|
cook_burned = cook_burned - cook_time
|
||||||
|
end
|
||||||
|
meta:set_float("cook_burned", cook_burned)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if turn_off then
|
||||||
|
fns.turn_off(pos)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
fuel_pct = math.floor((fuel_burned * 100) / fuel_time)
|
||||||
|
meta:set_string("formspec", fns.get_formspec_on(fuel_pct, 0))
|
||||||
|
meta:set_string("infotext", "Fuel: " .. fuel_pct)
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,136 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function swap_node(pos, name)
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
if node.name == name then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
node.name = name
|
||||||
|
minetest.swap_node(pos, node)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
minetest.register_craftitem("bitumen:heat", {
|
||||||
|
description = "Heat",
|
||||||
|
stack_max = 100,
|
||||||
|
inventory_image = "bitumen_heat.png",
|
||||||
|
groups = {flammable = 3},
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
type = "fuel",
|
||||||
|
recipe = "bitumen:heat",
|
||||||
|
burntime = 10,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
minetest.register_node("bitumen:heater", {
|
||||||
|
description = "Heater",
|
||||||
|
tiles = {
|
||||||
|
"default_bronze_block.png", "default_bronze_block.png",
|
||||||
|
"default_bronze_block.png", "default_bronze_block.png",
|
||||||
|
"default_bronze_block.png", "default_furnace_front.png",
|
||||||
|
},
|
||||||
|
paramtype2 = "facedir",
|
||||||
|
groups = {cracky=2, petroleum_fixture=1},
|
||||||
|
is_ground_content = false,
|
||||||
|
sounds = default.node_sound_stone_defaults(),
|
||||||
|
|
||||||
|
on_punch = function(pos)
|
||||||
|
swap_node(pos, "bitumen:heater_on")
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
minetest.register_node("bitumen:heater_on", {
|
||||||
|
description = "Heater (Active)",
|
||||||
|
tiles = {
|
||||||
|
"default_tin_block.png", "default_bronze_block.png",
|
||||||
|
"default_bronze_block.png", "default_tin_block.png",
|
||||||
|
"default_tin_block.png",
|
||||||
|
{
|
||||||
|
image = "default_furnace_front_active.png",
|
||||||
|
backface_culling = false,
|
||||||
|
animation = {
|
||||||
|
type = "vertical_frames",
|
||||||
|
aspect_w = 16,
|
||||||
|
aspect_h = 16,
|
||||||
|
length = 1.5
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
paramtype2 = "facedir",
|
||||||
|
groups = {cracky=2, petroleum_fixture=1, not_in_creative_inventory=1},
|
||||||
|
is_ground_content = false,
|
||||||
|
sounds = default.node_sound_stone_defaults(),
|
||||||
|
|
||||||
|
on_punch = function(pos)
|
||||||
|
swap_node(pos, "bitumen:heater")
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
minetest.register_abm({
|
||||||
|
nodenames = {"bitumen:heater_on"},
|
||||||
|
interval = 1,
|
||||||
|
chance = 1,
|
||||||
|
action = function(pos)
|
||||||
|
|
||||||
|
local apos = {x=pos.x, y=pos.y + 1, z=pos.z}
|
||||||
|
local anode = minetest.get_node(apos)
|
||||||
|
if anode.name == "air" then
|
||||||
|
-- print("air above")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local ameta = minetest.get_meta(apos)
|
||||||
|
local ainv = ameta:get_inventory()
|
||||||
|
if ainv:get_size("fuel") <= 0 then
|
||||||
|
-- print("no fuel inv")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if ainv:contains_item("fuel", "bitumen:heat 2") then
|
||||||
|
-- print("fuel full")
|
||||||
|
return -- still full
|
||||||
|
end
|
||||||
|
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
local back_dir = minetest.facedir_to_dir(node.param2)
|
||||||
|
local backpos = vector.add(pos, back_dir)
|
||||||
|
local backnet = bitumen.pipes.get_net(backpos)
|
||||||
|
if backnet == nil then
|
||||||
|
-- print("no network")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local max_amount = 1
|
||||||
|
|
||||||
|
local taken, fluid = bitumen.pipes.take_fluid(backpos, max_amount)
|
||||||
|
-- print("taken " .. fluid .. " " .. taken)
|
||||||
|
local heat = bitumen.fluid_to_heat(fluid, taken)
|
||||||
|
ainv:add_item("fuel", "bitumen:heat ".. math.floor(heat+.5))
|
||||||
|
-- print("")
|
||||||
|
|
||||||
|
-- print("added heat ".. heat)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
minetest.register_craft({
|
||||||
|
output = "bitumen:heater",
|
||||||
|
recipe = {
|
||||||
|
{"default:tin_ingot", "default:furnace", "default:tin_ingot"},
|
||||||
|
{"default:tin_ingot", "default:tin_ingot", "default:tin_ingot"},
|
||||||
|
{"default:tin_ingot", "default:tin_ingot", "default:tin_ingot"},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
|
43
init.lua
43
init.lua
|
@ -1,9 +1,49 @@
|
||||||
local modpath = minetest.get_modpath("bitumen")
|
local modpath = minetest.get_modpath("bitumen")
|
||||||
|
|
||||||
bitumen ={}
|
bitumen = {}
|
||||||
|
|
||||||
|
-- coal = 38
|
||||||
|
-- crude 44
|
||||||
|
bitumen.energy_density = {
|
||||||
|
tar = 20,
|
||||||
|
heavy_oil = 25,
|
||||||
|
light_oil = 30,
|
||||||
|
diesel = 36,
|
||||||
|
kerosene = 38,
|
||||||
|
gasoline = 34,
|
||||||
|
mineral_spirits = 42,
|
||||||
|
lpg = 45,
|
||||||
|
|
||||||
|
["bitumen:tar"] = 20,
|
||||||
|
["bitumen:heavy_oil"] = 25,
|
||||||
|
["bitumen:light_oil"] = 30,
|
||||||
|
["bitumen:diesel"] = 36,
|
||||||
|
["bitumen:kerosene"] = 38,
|
||||||
|
["bitumen:gasoline"] = 34,
|
||||||
|
["bitumen:mineral_spirits"] = 42,
|
||||||
|
["bitumen:lpg"] = 45,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
-- a coal lump burns for 40 seconds
|
||||||
|
-- a bitumen:heat burns for 10 seconds
|
||||||
|
-- multiply the energy density by this factor to find the number of bitumen:heats
|
||||||
|
bitumen.coal_equivalency = .1
|
||||||
|
|
||||||
|
bitumen.fluid_to_heat = function(fluid, amount)
|
||||||
|
local d = bitumen.energy_density[fluid]
|
||||||
|
if d == nil then
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
return bitumen.coal_equivalency * d * amount
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- first, to initialize the pipe API
|
-- first, to initialize the pipe API
|
||||||
dofile(modpath.."/pipes.lua")
|
dofile(modpath.."/pipes.lua")
|
||||||
|
dofile(modpath.."/burner.lua")
|
||||||
|
|
||||||
dofile(modpath.."/fluids.lua")
|
dofile(modpath.."/fluids.lua")
|
||||||
|
|
||||||
|
@ -12,6 +52,7 @@ dofile(modpath.."/fluids.lua")
|
||||||
|
|
||||||
--dofile(modpath.."/pumping.lua")
|
--dofile(modpath.."/pumping.lua")
|
||||||
|
|
||||||
|
dofile(modpath.."/heater.lua")
|
||||||
dofile(modpath.."/pump.lua")
|
dofile(modpath.."/pump.lua")
|
||||||
dofile(modpath.."/oilshale.lua")
|
dofile(modpath.."/oilshale.lua")
|
||||||
dofile(modpath.."/wells.lua")
|
dofile(modpath.."/wells.lua")
|
||||||
|
|
123
oilshale.lua
123
oilshale.lua
|
@ -155,129 +155,6 @@ end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bitumen.burners = {}
|
|
||||||
|
|
||||||
bitumen.register_burner = function(nodes, callbacks)
|
|
||||||
local default_callbacks = {
|
|
||||||
grab_fuel = grab_fuel, -- needs to return the fuel time
|
|
||||||
start_cook = function() end, -- needs to return the cook time
|
|
||||||
finish_cook = function() end,
|
|
||||||
abort_cook = function() end,
|
|
||||||
get_formspec_on = get_melter_active_formspec,
|
|
||||||
turn_on = function() end,
|
|
||||||
turn_off = function() end,
|
|
||||||
}
|
|
||||||
|
|
||||||
for k,v in pairs(callbacks) do
|
|
||||||
default_callbacks[k] = v
|
|
||||||
end
|
|
||||||
|
|
||||||
for _,n in ipairs(nodes) do
|
|
||||||
print("setting burner: "..n)
|
|
||||||
bitumen.burners[n] = default_callbacks
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bitumen.burner_on_timer = function(pos, elapsed)
|
|
||||||
|
|
||||||
local posnode = minetest.get_node(pos)
|
|
||||||
local fns = bitumen.burners[posnode.name]
|
|
||||||
if fns == nil then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
local fuel_time = meta:get_float("fuel_time") or 0
|
|
||||||
local fuel_burned = meta:get_float("fuel_burned") or 0
|
|
||||||
local cook_time = meta:get_float("cook_time") or 0
|
|
||||||
local cook_burned = meta:get_float("cook_burned") or 0
|
|
||||||
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
|
|
||||||
local burned = elapsed
|
|
||||||
local turn_off = false
|
|
||||||
|
|
||||||
|
|
||||||
-- print("\n\naf timer")
|
|
||||||
--/ print("fuel_burned: " .. fuel_burned)
|
|
||||||
-- print("fuel_time: " .. fuel_time)
|
|
||||||
|
|
||||||
|
|
||||||
if fuel_time > 0 and fuel_burned + elapsed < fuel_time then
|
|
||||||
-- still good on fuel
|
|
||||||
fuel_burned = fuel_burned + elapsed
|
|
||||||
meta:set_float("fuel_burned", fuel_burned + elapsed)
|
|
||||||
else
|
|
||||||
local t = fns.grab_fuel(inv)
|
|
||||||
if t <= 0 then -- out of fuel
|
|
||||||
--print("out of fuel")
|
|
||||||
meta:set_float("fuel_time", 0)
|
|
||||||
meta:set_float("fuel_burned", 0)
|
|
||||||
|
|
||||||
burned = fuel_time - fuel_burned
|
|
||||||
|
|
||||||
turn_off = true
|
|
||||||
else
|
|
||||||
-- check if the machine is turning on
|
|
||||||
if fuel_time == 0 then
|
|
||||||
fns.turn_on(pos, meta, inv)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- roll into the next period
|
|
||||||
fuel_burned = elapsed - (fuel_time - fuel_burned)
|
|
||||||
fuel_time = t
|
|
||||||
|
|
||||||
meta:set_float("fuel_time", fuel_time)
|
|
||||||
meta:set_float("fuel_burned", fuel_burned)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--print("cooktime " .. cook_time)
|
|
||||||
--print("cookburned " .. cook_burned)
|
|
||||||
if cook_time == 0 then -- nothing cooking atm
|
|
||||||
--print("fueltime " .. fuel_time)
|
|
||||||
--print("turnoff " .. dump(turn_off))
|
|
||||||
if fuel_time ~= 0 and turn_off == false then -- should we start to cook?
|
|
||||||
cook_time = fns.start_cook(pos, meta, inv)
|
|
||||||
meta:set_float("cook_time", cook_time)
|
|
||||||
meta:set_float("cook_burned", 0)
|
|
||||||
else
|
|
||||||
-- no fuel
|
|
||||||
end
|
|
||||||
else -- continue cooking
|
|
||||||
cook_burned = cook_burned + burned
|
|
||||||
if cook_burned >= cook_time then -- cooking finished
|
|
||||||
fns.finish_cook(pos, met, inv)
|
|
||||||
|
|
||||||
local new_cook_time = fns.start_cook(pos, meta, inv)
|
|
||||||
meta:set_float("cook_time", new_cook_time)
|
|
||||||
cook_burned = cook_burned - cook_time
|
|
||||||
end
|
|
||||||
meta:set_float("cook_burned", cook_burned)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if turn_off then
|
|
||||||
fns.turn_off(pos)
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
fuel_pct = math.floor((fuel_burned * 100) / fuel_time)
|
|
||||||
meta:set_string("formspec", fns.get_formspec_on(fuel_pct, 0))
|
|
||||||
meta:set_string("infotext", "Fuel: " .. fuel_pct)
|
|
||||||
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
99
pump.lua
99
pump.lua
|
@ -51,6 +51,8 @@ minetest.register_node("bitumen:pump", {
|
||||||
|
|
||||||
--bitumen.pipes.on_construct(pos)
|
--bitumen.pipes.on_construct(pos)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
--[[ not working, apparently due to an "undocumented feature" in the engine ;)
|
||||||
on_receive_fields = function(pos, form, fields, player)
|
on_receive_fields = function(pos, form, fields, player)
|
||||||
local meta = minetest:get_meta(pos)
|
local meta = minetest:get_meta(pos)
|
||||||
local mf = meta:get_string("formspec")
|
local mf = meta:get_string("formspec")
|
||||||
|
@ -70,6 +72,7 @@ minetest.register_node("bitumen:pump", {
|
||||||
minetest.show_formspec(player:get_player_name(), "", pump_formspec_on)
|
minetest.show_formspec(player:get_player_name(), "", pump_formspec_on)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
]]
|
||||||
|
|
||||||
on_punch = function(pos)
|
on_punch = function(pos)
|
||||||
swap_node(pos, "bitumen:pump_on")
|
swap_node(pos, "bitumen:pump_on")
|
||||||
|
@ -78,45 +81,6 @@ minetest.register_node("bitumen:pump", {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
minetest.register_abm({
|
|
||||||
nodenames = {"bitumen:pump"},
|
|
||||||
interval = 1,
|
|
||||||
chance = 1,
|
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
||||||
local node = minetest.get_node(pos)
|
|
||||||
|
|
||||||
local back_dir = minetest.facedir_to_dir(node.param2)
|
|
||||||
local backpos = vector.add(pos, back_dir)
|
|
||||||
local backnet = bitumen.pipes.get_net(backpos)
|
|
||||||
if backnet == nil then
|
|
||||||
print("pump no backnet at "..minetest.pos_to_string(backpos))
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local front_dir = vector.multiply(back_dir, -1)
|
|
||||||
local frontpos = vector.add(pos, front_dir)
|
|
||||||
local frontnet = bitumen.pipes.get_net(frontpos)
|
|
||||||
if frontnet == nil then
|
|
||||||
print("pump no frontnet at "..minetest.pos_to_string(frontpos))
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if backnet.fluid ~= frontnet.fluid and backnet.fluid ~= "air" then
|
|
||||||
print("pump: bad_fluid")
|
|
||||||
return -- incompatible fluids
|
|
||||||
end
|
|
||||||
|
|
||||||
local lift = 25
|
|
||||||
|
|
||||||
local taken, fluid = bitumen.pipes.take_fluid(frontpos, 20)
|
|
||||||
local pushed = bitumen.pipes.push_fluid(backpos, fluid, taken, lift)
|
|
||||||
print("pumped " ..pushed)
|
|
||||||
|
|
||||||
if pushed < taken then
|
|
||||||
print("pump leaked ".. (taken - pushed))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
|
||||||
minetest.register_node("bitumen:pump_on", {
|
minetest.register_node("bitumen:pump_on", {
|
||||||
description = "Pump (Active)",
|
description = "Pump (Active)",
|
||||||
|
@ -136,6 +100,7 @@ minetest.register_node("bitumen:pump_on", {
|
||||||
--bitumen.pipes.on_construct(pos)
|
--bitumen.pipes.on_construct(pos)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
--[[ not working, apparently due to an "undocumented feature" in the engine ;)
|
||||||
on_receive_fields = function(pos, form, fields, player)
|
on_receive_fields = function(pos, form, fields, player)
|
||||||
if fields.stop then
|
if fields.stop then
|
||||||
print("stop")
|
print("stop")
|
||||||
|
@ -146,8 +111,62 @@ minetest.register_node("bitumen:pump_on", {
|
||||||
minetest.show_formspec(player:get_player_name(), "", pump_formspec)
|
minetest.show_formspec(player:get_player_name(), "", pump_formspec)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
]]
|
||||||
|
|
||||||
on_punch = function(pos)
|
on_punch = function(pos)
|
||||||
swap_node(pos, "bitumen:pump")
|
swap_node(pos, "bitumen:pump")
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
minetest.register_abm({
|
||||||
|
nodenames = {"bitumen:pump_on"},
|
||||||
|
interval = 1,
|
||||||
|
chance = 1,
|
||||||
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
|
local node = minetest.get_node(pos)
|
||||||
|
|
||||||
|
local back_dir = minetest.facedir_to_dir(node.param2)
|
||||||
|
local backpos = vector.add(pos, back_dir)
|
||||||
|
local backnet = bitumen.pipes.get_net(backpos)
|
||||||
|
if backnet == nil then
|
||||||
|
-- print("pump no backnet at "..minetest.pos_to_string(backpos))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local front_dir = vector.multiply(back_dir, -1)
|
||||||
|
local frontpos = vector.add(pos, front_dir)
|
||||||
|
local frontnet = bitumen.pipes.get_net(frontpos)
|
||||||
|
if frontnet == nil then
|
||||||
|
-- print("pump no frontnet at "..minetest.pos_to_string(frontpos))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if backnet.fluid ~= frontnet.fluid and backnet.fluid ~= "air" then
|
||||||
|
-- print("pump: bad_fluid")
|
||||||
|
return -- incompatible fluids
|
||||||
|
end
|
||||||
|
|
||||||
|
local lift = 25
|
||||||
|
--print("fpos ".. minetest.pos_to_string(frontpos) .. " | bpos "..minetest.pos_to_string(backpos))
|
||||||
|
--print("fp ".. frontnet.in_pressure .. " | bp "..backnet.in_pressure)
|
||||||
|
local taken, fluid = bitumen.pipes.take_fluid(frontpos, 20)
|
||||||
|
local pushed = bitumen.pipes.push_fluid(backpos, fluid, taken, lift)
|
||||||
|
--print("pumped " ..taken .. " > "..pushed)
|
||||||
|
|
||||||
|
if pushed < taken then
|
||||||
|
--print("pump leaked ".. (taken - pushed))
|
||||||
|
end
|
||||||
|
|
||||||
|
--print("")
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -309,15 +309,6 @@ bitumen.distillation_yield = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bitumen.energy_density = {
|
|
||||||
lpg = { 33 },
|
|
||||||
jet_fuel = { 40 },
|
|
||||||
gasoline = { 30 },
|
|
||||||
diesel = { 25 },
|
|
||||||
fuel_oil = { 18 },
|
|
||||||
lube_oil = { 12 },
|
|
||||||
synth_crude = { 10 }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -242,6 +242,7 @@ minetest.register_node("bitumen:sphere_tank", {
|
||||||
meta:set_string("owner", owner)
|
meta:set_string("owner", owner)
|
||||||
end
|
end
|
||||||
meta:set_float("fluid_level", 0)
|
meta:set_float("fluid_level", 0)
|
||||||
|
meta:set_float("capacity", math.floor(3.14159 * .75 * 9 * 9 * 9 * 64))
|
||||||
meta:set_string("infotext", "0%")
|
meta:set_string("infotext", "0%")
|
||||||
|
|
||||||
set_magic_collision_nodes(pos, gensphere({0, 11, 0}, 9.99))
|
set_magic_collision_nodes(pos, gensphere({0, 11, 0}, 9.99))
|
||||||
|
@ -292,16 +293,16 @@ minetest.register_abm({
|
||||||
|
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local fluid = meta:get_string("fluid") or "air"
|
local fluid = meta:get_string("fluid") or "air"
|
||||||
local capacity = meta:get_float("capacity") or 1000
|
local capacity = meta:get_float("capacity") or 109000
|
||||||
local fill = meta:get_float("fill_level") or 0
|
local fill = meta:get_float("fill_level") or 0
|
||||||
|
|
||||||
meta:set_float("capacity", 1000)
|
-- print("tank fill: ".. fill .. " " ..capacity )
|
||||||
-- print("tank fill: ".. fill .. " " ..capacity )
|
|
||||||
local rem_capacity = capacity - fill
|
local rem_capacity = capacity - fill
|
||||||
local can_change = fill <= 0.01
|
local can_change = fill <= 0.01
|
||||||
local pres = (fill / capacity) * 20 -- the tank is roughly 20 nodes tall, nevermind the sphere part
|
local pres = (fill / capacity) * 20 -- the tank is roughly 20 nodes tall, nevermind the sphere part
|
||||||
|
local cap_take = math.min(rem_capacity, 60)
|
||||||
local delta, new_fluid = bitumen.pipes.buffer(pos, fluid, pres, fill, rem_capacity, can_change)
|
|
||||||
|
local delta, new_fluid = bitumen.pipes.buffer(pos, fluid, pres, fill, cap_take, can_change)
|
||||||
-- print("delta ".. delta .. " " .. new_fluid)
|
-- print("delta ".. delta .. " " .. new_fluid)
|
||||||
if delta > 0.01 or delta < -0.01 then
|
if delta > 0.01 or delta < -0.01 then
|
||||||
|
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 610 B |
Loading…
Reference in New Issue