master
Izzy 2018-06-20 00:11:04 -06:00
parent 5bbfa4eb07
commit 43e187c95e
4 changed files with 155 additions and 1 deletions

View File

@ -12,6 +12,7 @@ dofile(modpath.."/fluids.lua")
--dofile(modpath.."/pumping.lua")
dofile(modpath.."/pump.lua")
dofile(modpath.."/oilshale.lua")
dofile(modpath.."/wells.lua")
dofile(modpath.."/sphere_tank.lua")

View File

@ -220,7 +220,7 @@ bitumen.pipes.on_construct = function(pos)
end
local pnet = try_merge(merge_list)
pnet.count = pnet.count + 1 -- TODO: this might be implicit somewhere else
--pnet.count = pnet.count + 1 -- TODO: this might be implicit somewhere else
save_data()
end

152
pump.lua Normal file
View File

@ -0,0 +1,152 @@
local pump_formspec =
"size[10,8;]" ..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
"button[5,1;1,4;start;Start]" ..
"list[current_player;main;0,3.85;8,1;]" ..
"list[current_player;main;0,5.08;8,3;8]" ..
"listring[context;main]" ..
"listring[current_player;main]" ..
default.get_hotbar_bg(0, 3.85)
local pump_formspec_on =
"size[10,8;]" ..
default.gui_bg ..
default.gui_bg_img ..
default.gui_slots ..
"button[5,1;1,4;stop;Stop]" ..
"list[current_player;main;0,3.85;8,1;]" ..
"list[current_player;main;0,5.08;8,3;8]" ..
"listring[context;main]" ..
"listring[current_player;main]" ..
default.get_hotbar_bg(0, 3.85)
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_node("bitumen:pump", {
description = "Pump",
drawtype = "normal",
tiles = {"default_steel_block.png"},
is_ground_content = false,
paramtype2 = "facedir",
groups = {cracky = 1, petroleum_fixture=1, oddly_breakable_by_hand = 3},
sounds = default.node_sound_glass_defaults(),
on_place = minetest.rotate_node,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", pump_formspec)
--bitumen.pipes.on_construct(pos)
end,
on_receive_fields = function(pos, form, fields, player)
local meta = minetest:get_meta(pos)
local mf = meta:get_string("formspec")
print(dump(mf))
if fields.start then
print("start")
swap_node(pos, "bitumen:pump_on")
-- refetch the meta after the node swap just to be sure
local meta = minetest:get_meta(pos)
meta:set_string("formspec", "")
meta:set_string("formspec", pump_formspec_on)
local mf = meta:get_string("formspec")
print(dump(mf))
minetest.show_formspec(player:get_player_name(), "", pump_formspec_on)
end
end,
on_punch = function(pos)
swap_node(pos, "bitumen:pump_on")
end,
})
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", {
description = "Pump (Active)",
drawtype = "normal",
tiles = {"default_tin_block.png"},
is_ground_content = false,
paramtype2 = "facedir",
groups = {cracky = 1, petroleum_fixture=1, oddly_breakable_by_hand = 3, --[[not_in_creaetive_inventory=1]]},
sounds = default.node_sound_glass_defaults(),
on_place = minetest.rotate_node,
drop = "bitumen:pump",
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec", pump_formspec_on)
--bitumen.pipes.on_construct(pos)
end,
on_receive_fields = function(pos, form, fields, player)
if fields.stop then
print("start")
swap_node(pos, {name="bitumen:pump"})
local meta = minetest:get_meta(pos)
meta:set_string("formspec", pump_formspec)
minetest.show_formspec(player:get_player_name(), "", pump_formspec)
end
end,
on_punch = function(pos)
swap_node(pos, "bitumen:pump")
end,
})

View File

@ -138,6 +138,7 @@ minetest.register_node("bitumen:sphere_tank_constructor", {
drawtype = "normal",
paramtype2 = "facedir",
on_rotate = screwdriver.rotate_simple,
groups = {cracky=1},
tiles = {
"default_copper_block.png","default_tin_block.png",
},