oil tower added

master
Joachim Stolberg 2019-06-09 00:25:25 +02:00
parent 9b0c84c4d7
commit a067e77723
7 changed files with 62 additions and 58 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
--

View File

@ -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

View File

@ -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)

View File

@ -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