diff --git a/basic_machines/forceload.lua b/basic_machines/forceload.lua index 3419b7f..cc05167 100644 --- a/basic_machines/forceload.lua +++ b/basic_machines/forceload.lua @@ -53,24 +53,6 @@ local function chat(player, text) minetest.chat_send_player(player:get_player_name(), "[Techage] "..text) end -local function get_node_lvm(pos) - local node = minetest.get_node_or_nil(pos) - if node then - return node - end - local vm = minetest.get_voxel_manip() - local MinEdge, MaxEdge = vm:read_from_map(pos, pos) - local data = vm:get_data() - local param2_data = vm:get_param2_data() - local area = VoxelArea:new({MinEdge = MinEdge, MaxEdge = MaxEdge}) - local idx = area:index(pos.x, pos.y, pos.z) - node = { - name = minetest.get_name_from_content_id(data[idx]), - param2 = param2_data[idx] - } - return node -end - local function add_pos(pos, player) local lPos = minetest.deserialize(player:get_attribute("techage_forceload_blocks")) or {} if not in_list(lPos, pos) and #lPos < techage.max_num_forceload_blocks then @@ -202,7 +184,7 @@ end minetest.register_on_joinplayer(function(player) local lPos = {} for _,pos in ipairs(get_pos_list(player)) do - local node = get_node_lvm(pos) + local node = techage.get_node_lvm(pos) if node.name == "techage:forceload" then minetest.forceload_block(pos, true) lPos[#lPos+1] = pos diff --git a/basis/command.lua b/basis/command.lua index 4012e41..a8fa6b0 100644 --- a/basis/command.lua +++ b/basis/command.lua @@ -316,7 +316,7 @@ end function techage.transfer(pos, outdir, topic, payload, network, nodenames) -- determine out-dir if outdir and type(outdir) == "string" then - local param2 = Tube:get_node_lvm(pos).param2 + local param2 = techage.get_node_lvm(pos).param2 outdir = side_to_dir(outdir, param2) end -- determine destination pos @@ -327,7 +327,7 @@ function techage.transfer(pos, outdir, topic, payload, network, nodenames) dpos, indir = tubelib2.get_pos(pos, outdir) end -- check node name - local name = Tube:get_node_lvm(dpos).name + local name = techage.get_node_lvm(dpos).name if nodenames and not in_list(nodenames, name) then return false end diff --git a/basis/consumer.lua b/basis/consumer.lua index 06a370f..210a9a8 100644 --- a/basis/consumer.lua +++ b/basis/consumer.lua @@ -56,7 +56,7 @@ local function on_power_pass2(pos, mem, sum) if sum > 0 and state == techage.NOPOWER then crd.State:start(pos, mem) return 0 - elseif sum <= 0 and ValidPowerConsumingStates[state] then + elseif sum <= 0 and ValidPowerConsumingStates[state] or state == techage.STANDBY then crd.State:nopower(pos, mem) return -crd.power_consumption end diff --git a/basis/lib.lua b/basis/lib.lua index 49c1580..178f124 100644 --- a/basis/lib.lua +++ b/basis/lib.lua @@ -35,6 +35,26 @@ function techage.one_of(val, selection) return selection[1] end +function techage.get_node_lvm(pos) + local node = minetest.get_node_or_nil(pos) + if node then + return node + end + local vm = minetest.get_voxel_manip() + local MinEdge, MaxEdge = vm:read_from_map(pos, pos) + local data = vm:get_data() + local param2_data = vm:get_param2_data() + local area = VoxelArea:new({MinEdge = MinEdge, MaxEdge = MaxEdge}) + local idx = area:index(pos.x, pos.y, pos.z) + node = { + name = minetest.get_name_from_content_id(data[idx]), + param2 = param2_data[idx] + } + return node +end + + + -- -- Functions used to hide electric cable and biogas pipes -- diff --git a/lamps/lib.lua b/lamps/lib.lua index 79a1b4b..579cd24 100644 --- a/lamps/lib.lua +++ b/lamps/lib.lua @@ -29,7 +29,7 @@ local function rotate(param2) end local function swap_node(pos, postfix) - local node = Power:get_node_lvm(pos) + local node = techage.get_node_lvm(pos) local parts = string.split(node.name, "_") if postfix == parts[2] then return diff --git a/oil/drillbox.lua b/oil/drillbox.lua index 215e32d..52093a3 100644 --- a/oil/drillbox.lua +++ b/oil/drillbox.lua @@ -36,7 +36,7 @@ local formspec0 = "size[5,4]".. local function play_sound(pos) local mem = tubelib2.get_mem(pos) - if mem.techage_state == techage.RUNNING then + if CRD(pos).State:is_active(mem) then mem.handle = minetest.sound_play("techage_oildrill", { pos = pos, gain = 1, @@ -47,7 +47,7 @@ end local function stop_sound(pos) local mem = tubelib2.get_mem(pos) - if mem.techage_state ~= techage.RUNNING and mem.handle then + if mem.handle then minetest.sound_stop(mem.handle) mem.handle = nil end @@ -117,41 +117,41 @@ end local function drilling(pos, crd, mem, inv) M(pos):set_string("formspec", formspec(CRD(pos).State, pos, mem)) - print("drilling") - if inv:contains_item("src", ItemStack("techage:oil_drillbit")) then - mem.drill_pos = mem.drill_pos or {x=pos.x, y=pos.y, z=pos.z} + mem.drill_pos = mem.drill_pos or {x=pos.x, y=pos.y-1, z=pos.z} + local owner = M(pos):get_string("owner") + local depth = M(pos):get_int("depth") + local curr_depth = pos.y - (mem.drill_pos or pos).y + local node = techage.get_node_lvm(mem.drill_pos) + local item = ItemStack(node.name) + + if not inv:contains_item("src", ItemStack("techage:oil_drillbit")) then + crd.State:idle(pos, mem) + elseif curr_depth >= depth then + M(pos):set_string("oil_found", "true") + stop_sound(pos) + crd.State:stop(pos, mem) + elseif minetest.is_protected(mem.drill_pos, owner) then + stop_sound(pos) + crd.State:fault(pos, mem) + elseif node.name == "techage:oil_drillbit2" then mem.drill_pos.y = mem.drill_pos.y-1 - local owner = M(pos):get_string("owner") - local depth = M(pos):get_int("depth") - if mem.drill_pos.y > -depth then - if not minetest.is_protected(mem.drill_pos, owner) then - local node = minetest.get_node(mem.drill_pos) - if node.name ~= "techage:oil_drillbit2" then - local item = ItemStack(node.name) - if techage.can_node_dig(node) then - if inv:room_for_item("dst", item) then - inv:add_item("dst", item) - else - stop_sound(pos) - crd.State:blocked(pos, mem) - end - end - minetest.swap_node(mem.drill_pos, {name = "techage:oil_drillbit2"}) - inv:remove_item("src", ItemStack("techage:oil_drillbit")) - end - else - stop_sound(pos) - crd.State:fault(pos, mem) - end + crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) + elseif techage.can_node_dig(node) then + if inv:room_for_item("dst", item) then + inv:add_item("dst", item) + minetest.swap_node(mem.drill_pos, {name = "techage:oil_drillbit2"}) + inv:remove_item("src", ItemStack("techage:oil_drillbit")) + mem.drill_pos.y = mem.drill_pos.y-1 crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) - return else - M(pos):set_string("oil_found", "true") - stop_sound(pos) - crd.State:stop(pos, mem) + crd.State:blocked(pos, mem) end + else + minetest.swap_node(mem.drill_pos, {name = "techage:oil_drillbit2"}) + inv:remove_item("src", ItemStack("techage:oil_drillbit")) + mem.drill_pos.y = mem.drill_pos.y-1 + crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) end - crd.State:idle(pos, mem) end local function keep_running(pos, elapsed) diff --git a/oil/explore.lua b/oil/explore.lua index 7428743..b42c454 100644 --- a/oil/explore.lua +++ b/oil/explore.lua @@ -188,7 +188,9 @@ minetest.register_node("techage:oilexplorer", { on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) emerge_area(pos, node, clicker:get_player_name()) end, - + after_dig_node = function(pos, oldnode, oldmetadata, digger) + techage.unmark_region(digger:get_player_name()) + end, is_ground_content = false, groups = {snappy=2,cracky=2,oddly_breakable_by_hand=2}, sounds = default.node_sound_wood_defaults(), @@ -347,8 +349,8 @@ function techage.explore.get_oil_info(pos) while amount == 0 and depth < DEPTH_MAX do depth = depth + DEPTH_STEP local posC = {x = center(pos.x), y = center(-depth), z = center(pos.z)} - amount = oil_amount(posC) + amount = get_oil_amount(posC) end - return {depth = center(depth) - 2 + pos.y, amount = amount} + return {depth = center(depth) - 1 + pos.y, amount = amount} end