improvements

This commit is contained in:
Joachim Stolberg 2019-06-09 21:24:39 +02:00
parent 17246c13cd
commit 8cf9fae205
4 changed files with 34 additions and 28 deletions

View File

@ -74,17 +74,21 @@ function techage.is_primary_node(pos, dir)
return param2 ~= 0 return param2 ~= 0
end end
-- returns true, if node can be dug, or false -- returns true, if node can be dug, otherwise false
-- Table result can be used to read the node name of the dropped node when dug function techage.can_node_dig(node, ndef)
function techage.can_node_dig(node, result) if not ndef then return false end
-- don't remove nodes with some intelligence or undiggable nodes if node.name == "ignore" then return false end
local ndef = minetest.registered_nodes[node.name] if node.name == "air" then return true end
if not ndef or node.name == "air" then return false end if ndef.buildable_to == true then return true end
if ndef.drop == "" then return false end
if ndef.diggable == false then return false end if ndef.diggable == false then return false end
if ndef.after_dig_node then return false end if ndef.after_dig_node then return false end
if result and type(result) == "table" then
result.name = ndef.drop or node.name
end
return true return true
end end
-- returns the node name, if node can be dropped, otherwise nil
function techage.dropped_node(node, ndef)
if node.name == "air" then return end
if ndef.buildable_to == true then return end
if ndef.drop == "" then return end
return ndef.drop or node.name
end

View File

@ -3,7 +3,7 @@ local S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local P = minetest.string_to_pos local P = minetest.string_to_pos
local M = minetest.get_meta local M = minetest.get_meta
local POWER_CONSUMPTION = 1 local POWER_CONSUMPTION = 0.5
local Power = techage.ElectricCable local Power = techage.ElectricCable

View File

@ -36,11 +36,13 @@ local formspec0 = "size[5,4]"..
local function play_sound(pos) local function play_sound(pos)
local mem = tubelib2.get_mem(pos) local mem = tubelib2.get_mem(pos)
mem.handle = minetest.sound_play("techage_oildrill", { if mem.techage_state == techage.RUNNING then
pos = pos, mem.handle = minetest.sound_play("techage_oildrill", {
gain = 1, pos = pos,
max_hear_distance = 15}) gain = 1,
minetest.after(4, play_sound, pos) max_hear_distance = 15})
minetest.after(4, play_sound, pos)
end
end end
local function stop_sound(pos) local function stop_sound(pos)
@ -126,7 +128,7 @@ local function drilling(pos, crd, mem, inv)
local depth = M(pos):get_int("depth") local depth = M(pos):get_int("depth")
local curr_depth = pos.y - (mem.drill_pos or pos).y local curr_depth = pos.y - (mem.drill_pos or pos).y
local node = techage.get_node_lvm(mem.drill_pos) local node = techage.get_node_lvm(mem.drill_pos)
local dropped_node = {} local ndef = minetest.registered_nodes[node.name]
if not inv:contains_item("src", ItemStack("techage:oil_drillbit")) then if not inv:contains_item("src", ItemStack("techage:oil_drillbit")) then
crd.State:idle(pos, mem) crd.State:idle(pos, mem)
@ -138,22 +140,22 @@ local function drilling(pos, crd, mem, inv)
elseif node.name == "techage:oil_drillbit2" then elseif node.name == "techage:oil_drillbit2" then
mem.drill_pos.y = mem.drill_pos.y-1 mem.drill_pos.y = mem.drill_pos.y-1
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) crd.State:keep_running(pos, mem, COUNTDOWN_TICKS)
elseif techage.can_node_dig(node, dropped_node) then elseif techage.can_node_dig(node, ndef) then
local item = ItemStack(dropped_node.name) local drop_name = techage.dropped_node(node, ndef)
if inv:room_for_item("dst", item) then if drop_name then
local item = ItemStack(drop_name)
if not inv:room_for_item("dst", item) then
crd.State:blocked(pos, mem)
return
end
inv:add_item("dst", item) 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)
else
crd.State:blocked(pos, mem)
end end
else
minetest.swap_node(mem.drill_pos, {name = "techage:oil_drillbit2"}) minetest.swap_node(mem.drill_pos, {name = "techage:oil_drillbit2"})
inv:remove_item("src", ItemStack("techage:oil_drillbit")) inv:remove_item("src", ItemStack("techage:oil_drillbit"))
mem.drill_pos.y = mem.drill_pos.y-1 mem.drill_pos.y = mem.drill_pos.y-1
crd.State:keep_running(pos, mem, COUNTDOWN_TICKS) crd.State:keep_running(pos, mem, COUNTDOWN_TICKS)
else
crd.State:fault(pos, mem)
end end
end end

View File

@ -188,7 +188,7 @@ local _, node_name_ta3, _ =
is_ground_content = false, is_ground_content = false,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
num_items = {0,1,1,1}, num_items = {0,1,1,1},
power_consumption = {0,20,20,20}, power_consumption = {0,16,16,16},
}, },
{false, false, true, false}) -- TA3 only {false, false, true, false}) -- TA3 only