From f00b951fe6bc5a2f410492429323a6fb9208d049 Mon Sep 17 00:00:00 2001 From: Izzy Date: Tue, 19 Jun 2018 00:52:09 -0600 Subject: [PATCH] burners, lots of fixes --- gasoline.lua => fluids.lua | 5 + init.lua | 8 +- oilshale.lua | 371 +++++++++++++++++++++++++------------ pipes.lua | 8 +- plastic.lua | 7 - refinery.lua | 224 ++++++++++++++++------ tarsands.lua | 18 -- crude.lua => wells.lua | 127 +++++++++++-- 8 files changed, 543 insertions(+), 225 deletions(-) rename gasoline.lua => fluids.lua (99%) delete mode 100644 plastic.lua delete mode 100644 tarsands.lua rename crude.lua => wells.lua (61%) diff --git a/gasoline.lua b/fluids.lua similarity index 99% rename from gasoline.lua rename to fluids.lua index c121804..868fa04 100644 --- a/gasoline.lua +++ b/fluids.lua @@ -354,6 +354,11 @@ local function register_fluid(modname, name, info) end +bitumen.register_fluid = register_fluid + + + + register_fluid("bitumen", "mineral_spirits", { desc = "Mineral Spirits", groups = {flammable=1, petroleum=1}, diff --git a/init.lua b/init.lua index 3b312e3..f800fdf 100644 --- a/init.lua +++ b/init.lua @@ -5,18 +5,18 @@ bitumen ={} -- first, to initialize the pipe API dofile(modpath.."/pipes.lua") +dofile(modpath.."/fluids.lua") --- dofile(modpath.."/plastic.lua") --dofile(modpath.."/craftitems.lua") --dofile(modpath.."/containers.lua") --dofile(modpath.."/pumping.lua") ---dofile(modpath.."/tarsands.lua") -dofile(modpath.."/crude.lua") dofile(modpath.."/oilshale.lua") +dofile(modpath.."/wells.lua") + dofile(modpath.."/refinery.lua") -dofile(modpath.."/gasoline.lua") + minetest.register_node("bitumen:glass", { diff --git a/oilshale.lua b/oilshale.lua index e64891e..78ae4e3 100644 --- a/oilshale.lua +++ b/oilshale.lua @@ -102,6 +102,8 @@ end local function get_melter_active_formspec(fuel_percent, item_percent) + fuel_percent = fuel_percent or 0 + item_percent = item_percent or 0 return "size[8,8.5]".. default.gui_bg.. default.gui_bg_img.. @@ -117,6 +119,8 @@ local function get_melter_active_formspec(fuel_percent, item_percent) end +bitumen.get_melter_active_formspec = get_melter_active_formspec + local function grab_fuel(inv) @@ -151,130 +155,261 @@ end +bitumen.burners = {} -local function make_burning_fn(begin_cook, finish_cook) - - - local function af_on_timer(pos, elapsed) - - 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_remaining = meta:get_float("cook_time_remaining") or 0 - local cook_item = meta:get_int("is_cooking") or 0 - - local inv = meta:get_inventory() - - local can_cook = false - - local burned = elapsed - local turn_off = false - - print("\n\naf timer") - print("fuel_burned: " .. fuel_burned) - print("fuel_time: " .. fuel_time) - - -- if fuel_burned <= fuel_time or fuel_time == 0 then - -- -- use fuel - -- print("af fuel") - - if fuel_time > 0 and fuel_burned + elapsed < fuel_time then - - fuel_burned = fuel_burned + elapsed - meta:set_float("fuel_burned", fuel_burned + elapsed) - else - local t = 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 - -- roll into the next period - fuel_burned = elapsed - (fuel_time - fuel_burned) - fuel_time = t - - --print("fuel remaining: " .. (fuel_time - fuel_burned)) - - meta:set_float("fuel_time", fuel_time) - meta:set_float("fuel_burned", fuel_burned) - end - end - - -- end - - - - if cook_item == "" then - - - local cooked = grab_raw_item({x=pos.x, y=pos.y+1, z=pos.z}) - if cooked ~= nil then - cook_item = cooked.item:to_table() - cook_time_remaining = cooked.time - print(cook_item) - meta:set_string("cook_item", minetest.serialize(cook_item)) - meta:set_float("cook_time_remaining", cooked.time) - else - -- nothing to cook, carry on - print("nothing to cook") - cook_item = nil - meta:set_string("cook_item", "") - end - - - else - print(cook_item) - cook_item = minetest.deserialize(cook_item) - end - - - - - if cook_item ~= nil and burned > 0 then - - - local remain = cook_time_remaining - burned - print("remain: ".. remain); - if remain > 0 then - meta:set_float("cook_time_remaining", remain) - else - print("finished") - - finished_fn(pos, meta) - - -- cooking is finished - - --meta:set_string("cook_item", "") - meta:set_float("cook_time_remaining", 0) - end - - - end - - - - if turn_off then - swap_node(pos, "machines:autofurnace_off") - return - end - - fuel_pct = math.floor((fuel_burned * 100) / fuel_time) - -- item_pct = math.floor((fuel_burned * 100) / fuel_time) - meta:set_string("formspec", get_boiler_active_formspec(fuel_pct, 0)) - meta:set_string("infotext", "Fuel: " .. fuel_pct) - - return true +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 + + + + + + + + +bitumen.register_burner({"bitumen:engine_on"}, { + start_cook = function() + print("starting-") + return 8 + end, + finish_cook = function() + print("ending-") + end, + get_formspec_on = get_melter_active_formspec, +}) + +minetest.register_node("bitumen:engine", { + description = "Engine", + 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(), + --can_dig = can_dig, + + --on_timer = burner_on_timer, + + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", get_melter_active_formspec()) + local inv = meta:get_inventory() + inv:set_size('fuel', 4) + + minetest.get_node_timer(pos):start(1.0) + + end, + +-- on_metadata_inventory_move = function(pos) +-- minetest.get_node_timer(pos):start(1.0) +-- end, +-- on_metadata_inventory_put = function(pos) +-- -- start timer function, it will sort out whether furnace can burn or not. +-- minetest.get_node_timer(pos):start(1.0) +-- end, +-- + + on_punch = function(pos) + swap_node(pos, "bitumen:engine_on") + minetest.get_node_timer(pos):start(1.0) + end, + + +-- on_blast = function(pos) +-- local drops = {} +-- default.get_inventory_drops(pos, "src", drops) +-- default.get_inventory_drops(pos, "fuel", drops) +-- default.get_inventory_drops(pos, "dst", drops) +-- drops[#drops+1] = "machines:machine" +-- minetest.remove_node(pos) +-- return drops +-- end, + + allow_metadata_inventory_put = allow_metadata_inventory_put, + allow_metadata_inventory_move = allow_metadata_inventory_move, + allow_metadata_inventory_take = allow_metadata_inventory_take, +}) + + +minetest.register_node("bitumen:engine_on", { + description = "Engine", + 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(), + --can_dig = can_dig, + + on_timer = bitumen.burner_on_timer, + + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", get_melter_active_formspec()) + local inv = meta:get_inventory() + inv:set_size('fuel', 4) + + minetest.get_node_timer(pos):start(1.0) + + end, + +-- on_metadata_inventory_move = function(pos) +-- minetest.get_node_timer(pos):start(1.0) +-- end, +-- on_metadata_inventory_put = function(pos) +-- -- start timer function, it will sort out whether furnace can burn or not. +-- minetest.get_node_timer(pos):start(1.0) +-- end, +-- + + on_punch = function(pos) + swap_node(pos, "bitumen:engine") + end, + + allow_metadata_inventory_put = allow_metadata_inventory_put, + allow_metadata_inventory_move = allow_metadata_inventory_move, + allow_metadata_inventory_take = allow_metadata_inventory_take, +}) + + + + + + + + + + diff --git a/pipes.lua b/pipes.lua index a8ef208..2b4ed9e 100644 --- a/pipes.lua +++ b/pipes.lua @@ -131,7 +131,7 @@ end bitumen.pipes = {} -- used by external machines to connect to a network in their on_construct callback -bitumen.pipes.on_construct = function(pos) +bitumen.pipes.on_construct = function(pos) local found_net, merge_list = check_merge(pos) if found_net == 0 then @@ -196,7 +196,7 @@ bitumen.pipes.push_fluid = function(pos, fluid, amount, extra_pressure) end pnet.in_pressure = math.max(pnet.in_pressure, input_pres) - + print("net pressure: ".. pnet.in_pressure) local rate = amount --math.max(1, math.ceil(ulevel / 2)) local cap = 64 @@ -229,10 +229,6 @@ bitumen.pipes.take_fluid = function(pos, max_amount) return 0, "air" end - - pos.y = pos.y - 1 - - local bnode = minetest.get_node(pos) local take = math.min(pnet.buffer, max_amount) pnet.buffer = pnet.buffer - take diff --git a/plastic.lua b/plastic.lua deleted file mode 100644 index d61e40d..0000000 --- a/plastic.lua +++ /dev/null @@ -1,7 +0,0 @@ - --- compatibility for plastic mod. - - --- extractor plastic into oil - - \ No newline at end of file diff --git a/refinery.lua b/refinery.lua index 497b357..cc7ee8e 100644 --- a/refinery.lua +++ b/refinery.lua @@ -1,6 +1,18 @@ -- need: -- bottler? +local function mul(t, x) + local o = {} + + for n,i in ipairs(t) do + o[n] = i * x + end + + o[2] = o[2] / x + o[5] = o[5] / x + + return o +end @@ -20,22 +32,22 @@ minetest.register_node("bitumen:distillation_column", { type = "fixed", fixed = { --11.25 - {-0.49, -0.5, -0.10, 0.49, 0.5, 0.10}, - {-0.10, -0.5, -0.49, 0.10, 0.5, 0.49}, + mul({-0.49, -0.5, -0.10, 0.49, 0.5, 0.10}, 1.5), + mul({-0.10, -0.5, -0.49, 0.10, 0.5, 0.49}, 1.5), --22.5 - {-0.46, -0.5, -0.19, 0.46, 0.5, 0.19}, - {-0.19, -0.5, -0.46, 0.19, 0.5, 0.46}, + mul({-0.46, -0.5, -0.19, 0.46, 0.5, 0.19}, 1.5), + mul({-0.19, -0.5, -0.46, 0.19, 0.5, 0.46}, 1.5), -- 33.75 - {-0.416, -0.5, -0.28, 0.416, 0.5, 0.28}, - {-0.28, -0.5, -0.416, 0.28, 0.5, 0.416}, + mul({-0.416, -0.5, -0.28, 0.416, 0.5, 0.28}, 1.5), + mul({-0.28, -0.5, -0.416, 0.28, 0.5, 0.416}, 1.5), --45 - {-0.35, -0.5, -0.35, 0.35, 0.5, 0.35}, + mul({-0.35, -0.5, -0.35, 0.35, 0.5, 0.35}, 1.5), }, }, selection_box = { type = "fixed", fixed = { - {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + mul({-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, 1.5), }, }, drawtype = "nodebox", @@ -56,22 +68,22 @@ minetest.register_node("bitumen:distillation_column_outlet", { type = "fixed", fixed = { --11.25 - {-0.49, -0.5, -0.10, 0.49, 0.5, 0.10}, - {-0.10, -0.5, -0.49, 0.10, 0.5, 0.49}, + mul({-0.49, -0.5, -0.10, 0.49, 0.5, 0.10}, 1.5), + mul({-0.10, -0.5, -0.49, 0.10, 0.5, 0.49}, 1.5), --22.5 - {-0.46, -0.5, -0.19, 0.46, 0.5, 0.19}, - {-0.19, -0.5, -0.46, 0.19, 0.5, 0.46}, + mul({-0.46, -0.5, -0.19, 0.46, 0.5, 0.19}, 1.5), + mul({-0.19, -0.5, -0.46, 0.19, 0.5, 0.46}, 1.5), -- 33.75 - {-0.416, -0.5, -0.28, 0.416, 0.5, 0.28}, - {-0.28, -0.5, -0.416, 0.28, 0.5, 0.416}, + mul({-0.416, -0.5, -0.28, 0.416, 0.5, 0.28}, 1.5), + mul({-0.28, -0.5, -0.416, 0.28, 0.5, 0.416}, 1.5), --45 - {-0.35, -0.5, -0.35, 0.35, 0.5, 0.35}, + mul({-0.35, -0.5, -0.35, 0.35, 0.5, 0.35}, 1.5), }, }, selection_box = { type = "fixed", fixed = { - {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + mul({-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, 1.0) }, }, drawtype = "nodebox", @@ -95,30 +107,34 @@ bitumen.distillation_stack = { -- "lpg", } -local function check_stack(pos) +local function check_stack(opos) local ret = { } - local oh = pos.y - pos.y = pos.y + 1 + local oh = opos.y + local pos = {x=opos.x, y=opos.y+1, z=opos.z} local height = 0 local n - while height < 8*2 do - if minetest.get_node(pos).name == "bitumen:distillation_column" then + while height < 7 do + local n = minetest.get_node(pos) + if n.name == "bitumen:distillation_column" then -- noop - elseif minetest.get_node(pos).name == "bitumen:distillation_column_outlet" then + --print("col") + elseif n.name == "bitumen:distillation_column_outlet" then height = height+1 local t = bitumen.distillation_stack[height] ret[t] = {x=pos.x, y=pos.y, z=pos.z} - print(t.." at ".. (pos.y).. " - " .. height) + --print(t.." at ".. (pos.y).. " - " .. height) else + --print("n "..n.name) -- end of the stack break end + pos.y = pos.y+1 end - + --print("returning") return ret end @@ -130,53 +146,155 @@ local function dcb_node_timer(pos, elapsed) end + +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 + + +bitumen.register_burner({"bitumen:distillation_column_boiler_on"}, { + start_cook = function() + --print("starting") + + return 2 + end, + finish_cook = function(pos) + --print("y1 ".. pos.y) + local input = bitumen.pipes.take_fluid(pos, 64) + ---print("crude taken: ".. input) + if input <= 0 then + return + end + --print("y2 ".. pos.y) + local stack = check_stack(pos) + --print("y3 ".. pos.y) + for fluid,p in pairs(stack) do + print("pushing "..fluid.." at "..p.y) + local yield = bitumen.distillation_yield[fluid] * (input / 100) -- convert to levels + bitumen.pipes.push_fluid(p, "bitumen:"..fluid, yield, 20) + end + end, + get_formspec_on = get_melter_active_formspec, +}) + minetest.register_node("bitumen:distillation_column_boiler", { description = "Distillation Column Boiler", - tiles = {"default_steel_block.png", "default_steel_block.png", "default_steel_block.png", - "default_steel_block.png", "default_steel_block.png", "default_steel_block.png"}, + 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}, - sounds = default.node_sound_wood_defaults(), - can_dig = function(pos,player) - return true - end, + is_ground_content = false, + sounds = default.node_sound_stone_defaults(), + --can_dig = can_dig, - on_timer = dcb_node_timer, + --on_timer = burner_on_timer, + on_construct = function(pos) local meta = minetest.get_meta(pos) - meta:set_string("infotext", "Boiler") - meta:set_string("formspec", "") + meta:set_string("formspec", bitumen.get_melter_active_formspec()) local inv = meta:get_inventory() - inv:set_size('fuel', 6) + inv:set_size('fuel', 4) - -- connect to the pipe network bitumen.pipes.on_construct(pos) - print("constructed") minetest.get_node_timer(pos):start(1.0) end, + +-- on_metadata_inventory_move = function(pos) +-- minetest.get_node_timer(pos):start(1.0) +-- end, +-- on_metadata_inventory_put = function(pos) +-- -- start timer function, it will sort out whether furnace can burn or not. +-- minetest.get_node_timer(pos):start(1.0) +-- end, +-- + on_punch = function(pos) + swap_node(pos, "bitumen:distillation_column_boiler_on") + minetest.get_node_timer(pos):start(1.0) + end, + + +-- on_blast = function(pos) +-- local drops = {} +-- default.get_inventory_drops(pos, "src", drops) +-- default.get_inventory_drops(pos, "fuel", drops) +-- default.get_inventory_drops(pos, "dst", drops) +-- drops[#drops+1] = "machines:machine" +-- minetest.remove_node(pos) +-- return drops +-- end, + + allow_metadata_inventory_put = allow_metadata_inventory_put, + allow_metadata_inventory_move = allow_metadata_inventory_move, + allow_metadata_inventory_take = allow_metadata_inventory_take, }) ---temp hack for dev -minetest.register_abm({ - nodenames = {"bitumen:distillation_column_boiler"}, - interval = 3, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - local stack = check_stack(pos) - - for fluid,p in pairs(stack) do - print("pushing "..fluid.." at "..p.y) - local yield = bitumen.distillation_yield[fluid] * .64 -- convert to levels - bitumen.pipes.push_fluid(p, "bitumen:"..fluid, yield, 10) - end - - - end -}) +minetest.register_node("bitumen:distillation_column_boiler_on", { + description = "Distillation Column Boiler", + 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(), + --can_dig = can_dig, + + on_timer = bitumen.burner_on_timer, + + on_construct = function(pos) + local meta = minetest.get_meta(pos) + meta:set_string("formspec", bitumen.get_melter_active_formspec()) + local inv = meta:get_inventory() + inv:set_size('fuel', 4) + + bitumen.pipes.on_construct(pos) + + minetest.get_node_timer(pos):start(1.0) + + end, + +-- on_metadata_inventory_move = function(pos) +-- minetest.get_node_timer(pos):start(1.0) +-- end, +-- on_metadata_inventory_put = function(pos) +-- -- start timer function, it will sort out whether furnace can burn or not. +-- minetest.get_node_timer(pos):start(1.0) +-- end, +-- + + on_punch = function(pos) + swap_node(pos, "bitumen:distillation_column_boiler") + end, + + allow_metadata_inventory_put = allow_metadata_inventory_put, + allow_metadata_inventory_move = allow_metadata_inventory_move, + allow_metadata_inventory_take = allow_metadata_inventory_take, +}) + -- must add up to 100 bitumen.distillation_yield = { tar = 20, diff --git a/tarsands.lua b/tarsands.lua deleted file mode 100644 index ff56803..0000000 --- a/tarsands.lua +++ /dev/null @@ -1,18 +0,0 @@ - - --- oil drums. plastic and steel --- oil containers, for carrying --- oil storage tanks --- cracking tower - --- generators - - --- add bananas/cocoa to chainsaw --- flower seeds and garden --- "sucker"/"fetcher" that will pull an item from the connected system - --- need to get the info for sand-type things - - - diff --git a/crude.lua b/wells.lua similarity index 61% rename from crude.lua rename to wells.lua index cb12e20..e87d695 100644 --- a/crude.lua +++ b/wells.lua @@ -1,6 +1,47 @@ + +bitumen.register_fluid("bitumen", "drill_mud", { + desc = "Drilling Mud", + groups = {petroleum=1}, + + reflow_interval = 5, + reflow_chance = 1, + flow_interval = 1, + flow_chance = 1, + + colorize = "^[colorize:brown:40", + post_effect_color = {a = 103, r = 80, g = 76, b = 90}, + + evap_chance = 0, +}) + +bitumen.register_fluid("bitumen", "drill_mud_dirty", { + desc = "Dirty Drilling Mud", + groups = {petroleum=1}, + + reflow_interval = 5, + reflow_chance = 1, + flow_interval = 1, + flow_chance = 1, + + colorize = "^[colorize:brown:140", + post_effect_color = {a = 103, r = 80, g = 76, b = 90}, + + evap_chance = 0, +}) + + + + + + + + + + + local function check_drill_stack(opos) local pos = vector.new(opos) pos.y = pos.y - 1 @@ -16,7 +57,7 @@ local function check_drill_stack(opos) end - print("well depth: "..pos.y) + print("check stack well depth: "..pos.y) return {x=pos.x, y=pos.y, z=pos.z} @@ -25,6 +66,19 @@ end +local function mul(t, x) + local o = {} + + for n,i in ipairs(t) do + o[n] = i * x + end + + o[2] = o[2] / x + o[5] = o[5] / x + + return o +end + minetest.register_node("bitumen:drill_pipe", { @@ -36,22 +90,22 @@ minetest.register_node("bitumen:drill_pipe", { type = "fixed", fixed = { --11.25 - {-0.49, -0.5, -0.10, 0.49, 0.5, 0.10}, - {-0.10, -0.5, -0.49, 0.10, 0.5, 0.49}, + mul({-0.49, -0.5, -0.10, 0.49, 0.5, 0.10}, .3), + mul({-0.10, -0.5, -0.49, 0.10, 0.5, 0.49}, .3), --22.5 - {-0.46, -0.5, -0.19, 0.46, 0.5, 0.19}, - {-0.19, -0.5, -0.46, 0.19, 0.5, 0.46}, + mul({-0.46, -0.5, -0.19, 0.46, 0.5, 0.19}, .3), + mul({-0.19, -0.5, -0.46, 0.19, 0.5, 0.46}, .3), -- 33.75 - {-0.416, -0.5, -0.28, 0.416, 0.5, 0.28}, - {-0.28, -0.5, -0.416, 0.28, 0.5, 0.416}, + mul({-0.416, -0.5, -0.28, 0.416, 0.5, 0.28}, .3), + mul({-0.28, -0.5, -0.416, 0.28, 0.5, 0.416}, .3), --45 - {-0.35, -0.5, -0.35, 0.35, 0.5, 0.35}, + mul({-0.35, -0.5, -0.35, 0.35, 0.5, 0.35}, .3), }, }, selection_box = { type = "fixed", fixed = { - {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + mul({-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, .3), }, }, drawtype = "nodebox", @@ -64,6 +118,18 @@ minetest.register_node("bitumen:drill_pipe", { }) + +minetest.register_craft({ + output = 'bitumen:drill_pipe 12', + recipe = { + {'default:steel_ingot', '', 'default:steel_ingot'}, + {'default:steel_ingot', '', 'default:steel_ingot'}, + {'default:steel_ingot', '', 'default:steel_ingot'}, + } +}) + + + minetest.register_node("bitumen:well_siphon", { paramtype = "light", description = "Well Siphon", @@ -102,32 +168,55 @@ minetest.register_node("bitumen:well_siphon", { local function drill(pos) - - local dp = check_drill_stack(pos) + + local meta = minetest.get_meta(pos) + local dp = meta:get_string("drilldepth") or "" + --print("dp" .. dump(dp)) + if dp == "" then + dp = check_drill_stack(pos) + else + dp = minetest.deserialize(dp) + --print("deserialized " .. dump(pos)) + dp.y = dp.y - 1 + end local n = minetest.get_node(dp) + if n.name == "ignore" then - if minetest.forceload_block(pos, true) then - print("forceload successful") - minetest.emerge_area(pos, pos) + if minetest.forceload_block(dp, true) then + print("forceload successful: ".. minetest.pos_to_string(dp)) + local n = minetest.get_node(dp) else - print("forceload failed") - return + --minetest.emerge_area(dp, {x=dp.x, y=dp.y - 20, z=dp.z}) + -- print("forceload failed, emerging " .. minetest.pos_to_string(dp)) + -- return end -- minetest.emerge_area(pos, pos) end - if n.name == "bitumen:crude_oil" then + if n.name == "ignore" then + minetest.emerge_area(dp, {x=dp.x, y=dp.y - 20, z=dp.z}) + print("emerging " .. minetest.pos_to_string(dp)) + + return + elseif n.name == "bitumen:drill_pipe" then + dp = check_drill_stack(pos) + elseif n.name == "bitumen:crude_oil" or n.name == "bitumen:crude_oil_full" then pos.y = pos.y + 2 minetest.set_node(pos, {name = "bitumen:crude_oil"}) minetest.set_node_level(pos, 64) else - print("drilling "..n.name) + print("drilling at "..dp.y.." of "..n.name ) minetest.set_node(dp, {name = "bitumen:drill_pipe"}) end + + meta:set_string("drilldepth", minetest.serialize(dp)) + + + end @@ -156,7 +245,7 @@ minetest.register_abm({ interval = 1, chance = 1, action = function(pos, node, active_object_count, active_object_count_wider) - print("trydrill") + --print("trydrill") drill(pos) end