mirror of
https://github.com/minetest-mods/digtron.git
synced 2024-10-04 00:23:07 +02:00
more fixes
This commit is contained in:
parent
6db2646b23
commit
828cb5bc9b
@ -1,6 +1,4 @@
|
|||||||
-- unused_args = false
|
max_line_length = 180
|
||||||
-- allow_defined_top = true
|
|
||||||
-- ignore = {"512"}
|
|
||||||
|
|
||||||
globals = {
|
globals = {
|
||||||
"digtron"
|
"digtron"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
-- internationalization boilerplate
|
-- internationalization boilerplate
|
||||||
local MP = minetest.get_modpath(minetest.get_current_modname())
|
local MP = minetest.get_modpath(minetest.get_current_modname())
|
||||||
local S, NS = dofile(MP.."/intllib.lua")
|
local S = dofile(MP.."/intllib.lua")
|
||||||
|
|
||||||
local dig_dust = function(pos, facing)
|
local dig_dust = function(pos, facing)
|
||||||
local direction = minetest.facedir_to_dir(facing)
|
local direction = minetest.facedir_to_dir(facing)
|
||||||
@ -50,15 +50,15 @@ local function neighbour_test(layout, status_text, dir)
|
|||||||
minetest.sound_play("buzzer", {gain=0.25, pos=layout.controller})
|
minetest.sound_play("buzzer", {gain=0.25, pos=layout.controller})
|
||||||
return S("Digtron is adjacent to unloaded nodes.") .. "\n" .. status_text, 1
|
return S("Digtron is adjacent to unloaded nodes.") .. "\n" .. status_text, 1
|
||||||
end
|
end
|
||||||
|
|
||||||
if layout.water_touching == true then
|
if layout.water_touching == true then
|
||||||
minetest.sound_play("sploosh", {gain=1.0, pos=layout.controller})
|
minetest.sound_play("sploosh", {gain=1.0, pos=layout.controller})
|
||||||
end
|
end
|
||||||
|
|
||||||
if layout.lava_touching == true then
|
if layout.lava_touching == true then
|
||||||
minetest.sound_play("woopwoopwoop", {gain=1.0, pos=layout.controller})
|
minetest.sound_play("woopwoopwoop", {gain=1.0, pos=layout.controller})
|
||||||
end
|
end
|
||||||
|
|
||||||
if dir and dir.y ~= -1 and layout.traction * digtron.config.traction_factor < table.getn(layout.all) then
|
if dir and dir.y ~= -1 and layout.traction * digtron.config.traction_factor < table.getn(layout.all) then
|
||||||
-- digtrons can't fly, though they can fall
|
-- digtrons can't fly, though they can fall
|
||||||
minetest.sound_play("squeal", {gain=1.0, pos=layout.controller})
|
minetest.sound_play("squeal", {gain=1.0, pos=layout.controller})
|
||||||
@ -117,11 +117,11 @@ digtron.execute_dig_cycle = function(pos, clicker)
|
|||||||
local dir = minetest.facedir_to_dir(facing)
|
local dir = minetest.facedir_to_dir(facing)
|
||||||
local fuel_burning = meta:get_float("fuel_burning") -- get amount of burned fuel left over from last cycle
|
local fuel_burning = meta:get_float("fuel_burning") -- get amount of burned fuel left over from last cycle
|
||||||
local status_text = S("Heat remaining in controller furnace: @1", math.floor(math.max(0, fuel_burning)))
|
local status_text = S("Heat remaining in controller furnace: @1", math.floor(math.max(0, fuel_burning)))
|
||||||
local exhaust = meta:get_int("on_coal")
|
|
||||||
|
|
||||||
local layout = digtron.DigtronLayout.create(pos, clicker)
|
local layout = digtron.DigtronLayout.create(pos, clicker)
|
||||||
|
|
||||||
local status_text, return_code = neighbour_test(layout, status_text, dir)
|
local return_code
|
||||||
|
status_text, return_code = neighbour_test(layout, status_text, dir)
|
||||||
if return_code ~= 0 then
|
if return_code ~= 0 then
|
||||||
return pos, status_text, return_code
|
return pos, status_text, return_code
|
||||||
end
|
end
|
||||||
@ -130,21 +130,21 @@ digtron.execute_dig_cycle = function(pos, clicker)
|
|||||||
if size_check_error then
|
if size_check_error then
|
||||||
return pos, size_check_error, 8
|
return pos, size_check_error, 8
|
||||||
end
|
end
|
||||||
|
|
||||||
local controlling_coordinate = digtron.get_controlling_coordinate(pos, facing)
|
local controlling_coordinate = digtron.get_controlling_coordinate(pos, facing)
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
local items_dropped = {}
|
local items_dropped = {}
|
||||||
local digging_fuel_cost = 0
|
local digging_fuel_cost = 0
|
||||||
local particle_systems = {}
|
local particle_systems = {}
|
||||||
|
|
||||||
-- execute the execute_dig method on all digtron components that have one
|
-- execute the execute_dig method on all digtron components that have one
|
||||||
-- This builds a set of nodes that will be dug and returns a list of products that will be generated
|
-- This builds a set of nodes that will be dug and returns a list of products that will be generated
|
||||||
-- but doesn't actually dig the nodes yet. That comes later.
|
-- but doesn't actually dig the nodes yet. That comes later.
|
||||||
-- If we dug them now, sand would fall and some digtron nodes would die.
|
-- If we dug them now, sand would fall and some digtron nodes would die.
|
||||||
if layout.diggers ~= nil then
|
if layout.diggers ~= nil then
|
||||||
for k, location in pairs(layout.diggers) do
|
for _, location in pairs(layout.diggers) do
|
||||||
local target = minetest.get_node(location.pos)
|
local target = minetest.get_node(location.pos)
|
||||||
local targetdef = minetest.registered_nodes[target.name]
|
local targetdef = minetest.registered_nodes[target.name]
|
||||||
if targetdef.execute_dig ~= nil then
|
if targetdef.execute_dig ~= nil then
|
||||||
@ -163,9 +163,9 @@ digtron.execute_dig_cycle = function(pos, clicker)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- test if any digtrons are obstructed by non-digtron nodes that haven't been marked
|
-- test if any digtrons are obstructed by non-digtron nodes that haven't been marked
|
||||||
-- as having been dug.
|
-- as having been dug.
|
||||||
local can_move = true
|
local can_move = true
|
||||||
@ -175,11 +175,11 @@ digtron.execute_dig_cycle = function(pos, clicker)
|
|||||||
can_move = false
|
can_move = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if test_stop_block(pos, items_dropped) then
|
if test_stop_block(pos, items_dropped) then
|
||||||
can_move = false
|
can_move = false
|
||||||
end
|
end
|
||||||
|
|
||||||
if not can_move then
|
if not can_move then
|
||||||
-- mark this node as waiting, will clear this flag in digtron.config.cycle_time seconds
|
-- mark this node as waiting, will clear this flag in digtron.config.cycle_time seconds
|
||||||
minetest.get_meta(pos):set_string("waiting", "true")
|
minetest.get_meta(pos):set_string("waiting", "true")
|
||||||
@ -190,26 +190,26 @@ digtron.execute_dig_cycle = function(pos, clicker)
|
|||||||
end
|
end
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- ask each builder node if it can get what it needs from inventory to build this cycle.
|
-- ask each builder node if it can get what it needs from inventory to build this cycle.
|
||||||
-- This is a complicated test because each builder needs to actually *take* the item it'll
|
-- This is a complicated test because each builder needs to actually *take* the item it'll
|
||||||
-- need from inventory, and then we put it all back afterward.
|
-- need from inventory, and then we put it all back afterward.
|
||||||
-- Note that this test may overestimate the amount of work that will actually need to be done so don't treat its fuel cost as authoritative.
|
-- Note that this test may overestimate the amount of work that will actually need to be done so don't treat its fuel cost as authoritative.
|
||||||
local can_build = true
|
local can_build = true
|
||||||
local test_build_return_code = nil
|
|
||||||
local test_build_return_items = nil
|
|
||||||
local failed_to_find = nil
|
|
||||||
local test_items = {}
|
local test_items = {}
|
||||||
local test_fuel_items = {}
|
|
||||||
local test_build_fuel_cost = 0
|
local test_build_fuel_cost = 0
|
||||||
|
local test_build_return_code, test_build_return_items
|
||||||
|
|
||||||
if layout.builders ~= nil then
|
if layout.builders ~= nil then
|
||||||
for k, location in pairs(layout.builders) do
|
for _, location in pairs(layout.builders) do
|
||||||
local target = minetest.get_node(location.pos)
|
local target = minetest.get_node(location.pos)
|
||||||
local targetdef = minetest.registered_nodes[target.name]
|
local targetdef = minetest.registered_nodes[target.name]
|
||||||
local test_location = vector.add(location.pos, dir)
|
local test_location = vector.add(location.pos, dir)
|
||||||
if targetdef.test_build ~= nil then
|
if targetdef.test_build ~= nil then
|
||||||
test_build_return_code, test_build_return_items, failed_to_find = targetdef.test_build(location.pos, test_location, layout.inventories, layout.protected, layout.nodes_dug, controlling_coordinate, layout.controller)
|
test_build_return_code, test_build_return_items = targetdef.test_build(
|
||||||
for k, return_item in pairs(test_build_return_items) do
|
location.pos, test_location, layout.inventories, layout.protected, layout.nodes_dug, controlling_coordinate, layout.controller
|
||||||
|
)
|
||||||
|
for _, return_item in pairs(test_build_return_items) do
|
||||||
table.insert(test_items, return_item)
|
table.insert(test_items, return_item)
|
||||||
test_build_fuel_cost = test_build_fuel_cost + digtron.config.build_cost
|
test_build_fuel_cost = test_build_fuel_cost + digtron.config.build_cost
|
||||||
end
|
end
|
||||||
@ -222,7 +222,7 @@ digtron.execute_dig_cycle = function(pos, clicker)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local test_fuel_needed = test_build_fuel_cost + digging_fuel_cost - fuel_burning
|
local test_fuel_needed = test_build_fuel_cost + digging_fuel_cost - fuel_burning
|
||||||
local test_fuel_burned = 0
|
local test_fuel_burned = 0
|
||||||
|
|
||||||
@ -248,7 +248,7 @@ digtron.execute_dig_cycle = function(pos, clicker)
|
|||||||
power_from_cables = power_from_cables / digtron.config.power_ratio
|
power_from_cables = power_from_cables / digtron.config.power_ratio
|
||||||
test_fuel_burned = power_from_cables
|
test_fuel_burned = power_from_cables
|
||||||
end
|
end
|
||||||
|
|
||||||
if test_fuel_needed - test_fuel_burned > 0 then
|
if test_fuel_needed - test_fuel_burned > 0 then
|
||||||
-- check for the available electrical power
|
-- check for the available electrical power
|
||||||
test_fuel_burned = test_fuel_burned + digtron.tap_batteries(layout.battery_holders, test_fuel_needed, true)
|
test_fuel_burned = test_fuel_burned + digtron.tap_batteries(layout.battery_holders, test_fuel_needed, true)
|
||||||
@ -257,31 +257,32 @@ digtron.execute_dig_cycle = function(pos, clicker)
|
|||||||
if (fuel_burning<0) then
|
if (fuel_burning<0) then
|
||||||
test_fuel_needed = test_fuel_needed - fuel_burning
|
test_fuel_needed = test_fuel_needed - fuel_burning
|
||||||
fuel_burning = 0
|
fuel_burning = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local exhaust
|
||||||
if (test_fuel_needed < test_fuel_burned) then
|
if (test_fuel_needed < test_fuel_burned) then
|
||||||
exhaust = 0 -- all power needs met by electricity, don't blow smoke
|
exhaust = 0 -- all power needs met by electricity, don't blow smoke
|
||||||
else
|
else
|
||||||
-- burn combustible fuel if not enough power
|
-- burn combustible fuel if not enough power
|
||||||
test_fuel_burned = test_fuel_burned + digtron.burn(layout.fuelstores, test_fuel_needed - test_fuel_burned, true)
|
test_fuel_burned = test_fuel_burned + digtron.burn(layout.fuelstores, test_fuel_needed - test_fuel_burned, true)
|
||||||
exhaust = 1 -- burning fuel produces smoke
|
exhaust = 1 -- burning fuel produces smoke
|
||||||
end
|
end
|
||||||
|
|
||||||
--Put everything back where it came from
|
--Put everything back where it came from
|
||||||
for k, item_return in pairs(test_items) do
|
for _, item_return in pairs(test_items) do
|
||||||
digtron.place_in_specific_inventory(item_return.item, item_return.location, layout.inventories, layout.controller)
|
digtron.place_in_specific_inventory(item_return.item, item_return.location, layout.inventories, layout.controller)
|
||||||
end
|
end
|
||||||
|
|
||||||
if test_fuel_needed > fuel_burning + test_fuel_burned then
|
if test_fuel_needed > fuel_burning + test_fuel_burned then
|
||||||
minetest.sound_play("buzzer", {gain=0.5, pos=pos})
|
minetest.sound_play("buzzer", {gain=0.5, pos=pos})
|
||||||
return pos, S("Digtron needs more fuel."), 4 -- abort, don't dig and don't build.
|
return pos, S("Digtron needs more fuel."), 4 -- abort, don't dig and don't build.
|
||||||
end
|
end
|
||||||
|
|
||||||
if not can_build then
|
if not can_build then
|
||||||
minetest.get_meta(pos):set_string("waiting", "true")
|
minetest.get_meta(pos):set_string("waiting", "true")
|
||||||
minetest.get_node_timer(pos):start(digtron.config.cycle_time)
|
minetest.get_node_timer(pos):start(digtron.config.cycle_time)
|
||||||
local return_string = nil
|
local return_string = nil
|
||||||
local return_code = 5
|
return_code = 5
|
||||||
if test_build_return_code == 3 then
|
if test_build_return_code == 3 then
|
||||||
minetest.sound_play("honk", {gain=0.5, pos=pos}) -- A builder is not configured
|
minetest.sound_play("honk", {gain=0.5, pos=pos}) -- A builder is not configured
|
||||||
return_string = S("Digtron connected to at least one builder with no output material assigned.") .. "\n"
|
return_string = S("Digtron connected to at least one builder with no output material assigned.") .. "\n"
|
||||||
@ -292,19 +293,19 @@ digtron.execute_dig_cycle = function(pos, clicker)
|
|||||||
return_code = 7
|
return_code = 7
|
||||||
end
|
end
|
||||||
return pos, return_string .. status_text, return_code --Abort, don't dig and don't build.
|
return pos, return_string .. status_text, return_code --Abort, don't dig and don't build.
|
||||||
end
|
end
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- All tests passed, ready to go for real!
|
-- All tests passed, ready to go for real!
|
||||||
minetest.sound_play("construction", {gain=1.0, pos=pos})
|
minetest.sound_play("construction", {gain=1.0, pos=pos})
|
||||||
|
|
||||||
-- if the player is standing within the array or next to it, move him too.
|
-- if the player is standing within the array or next to it, move him too.
|
||||||
local move_player = move_player_test(layout, clicker)
|
local move_player = move_player_test(layout, clicker)
|
||||||
|
|
||||||
-- damage the weak flesh
|
-- damage the weak flesh
|
||||||
if digtron.config.damage_hp > 0 and layout.diggers ~= nil then
|
if digtron.config.damage_hp > 0 and layout.diggers ~= nil then
|
||||||
for k, location in pairs(layout.diggers) do
|
for _, location in pairs(layout.diggers) do
|
||||||
local target = minetest.get_node(location.pos)
|
local target = minetest.get_node(location.pos)
|
||||||
local targetdef = minetest.registered_nodes[target.name]
|
local targetdef = minetest.registered_nodes[target.name]
|
||||||
if targetdef.damage_creatures ~= nil then
|
if targetdef.damage_creatures ~= nil then
|
||||||
@ -312,7 +313,7 @@ digtron.execute_dig_cycle = function(pos, clicker)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--move the array
|
--move the array
|
||||||
layout:move_layout_image(dir)
|
layout:move_layout_image(dir)
|
||||||
if not layout:write_layout_image(clicker) then
|
if not layout:write_layout_image(clicker) then
|
||||||
@ -324,13 +325,13 @@ digtron.execute_dig_cycle = function(pos, clicker)
|
|||||||
if move_player then
|
if move_player then
|
||||||
clicker:moveto(vector.add(dir, clicker:get_pos()), true)
|
clicker:moveto(vector.add(dir, clicker:get_pos()), true)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- store or drop the products of the digger heads
|
-- store or drop the products of the digger heads
|
||||||
for _, itemname in pairs(items_dropped) do
|
for _, itemname in pairs(items_dropped) do
|
||||||
digtron.place_in_inventory(itemname, layout.inventories, oldpos)
|
digtron.place_in_inventory(itemname, layout.inventories, oldpos)
|
||||||
end
|
end
|
||||||
digtron.award_item_dug(items_dropped, clicker) -- Achievements mod hook
|
digtron.award_item_dug(items_dropped, clicker) -- Achievements mod hook
|
||||||
|
|
||||||
local building_fuel_cost = 0
|
local building_fuel_cost = 0
|
||||||
local strange_failure = false
|
local strange_failure = false
|
||||||
-- execute_build on all digtron components that have one
|
-- execute_build on all digtron components that have one
|
||||||
@ -346,7 +347,6 @@ digtron.execute_dig_cycle = function(pos, clicker)
|
|||||||
-- So this should never happen. However, "should never happens" happen sometimes. So
|
-- So this should never happen. However, "should never happens" happen sometimes. So
|
||||||
-- don't interrupt the build cycle as a whole, we've already moved so might as well try to complete as much as possible.
|
-- don't interrupt the build cycle as a whole, we've already moved so might as well try to complete as much as possible.
|
||||||
strange_failure = true
|
strange_failure = true
|
||||||
build_return = (build_return * -1) - 1
|
|
||||||
elseif digtron.config.uses_resources then
|
elseif digtron.config.uses_resources then
|
||||||
building_fuel_cost = building_fuel_cost + (digtron.config.build_cost * build_return)
|
building_fuel_cost = building_fuel_cost + (digtron.config.build_cost * build_return)
|
||||||
end
|
end
|
||||||
@ -355,7 +355,7 @@ digtron.execute_dig_cycle = function(pos, clicker)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if layout.auto_ejectors ~= nil then
|
if layout.auto_ejectors ~= nil then
|
||||||
for k, location in pairs(layout.auto_ejectors) do
|
for k, location in pairs(layout.auto_ejectors) do
|
||||||
local target = minetest.get_node(location.pos)
|
local target = minetest.get_node(location.pos)
|
||||||
@ -368,16 +368,16 @@ digtron.execute_dig_cycle = function(pos, clicker)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local status_text = ""
|
status_text = ""
|
||||||
if strange_failure then
|
if strange_failure then
|
||||||
-- We weren't able to detect this build failure ahead of time, so make a big noise now. This is strange, shouldn't happen.
|
-- We weren't able to detect this build failure ahead of time, so make a big noise now. This is strange, shouldn't happen.
|
||||||
minetest.sound_play("dingding", {gain=1.0, pos=pos})
|
minetest.sound_play("dingding", {gain=1.0, pos=pos})
|
||||||
minetest.sound_play("buzzer", {gain=0.5, pos=pos})
|
minetest.sound_play("buzzer", {gain=0.5, pos=pos})
|
||||||
status_text = S("Digtron unexpectedly failed to execute one or more build operations, likely due to an inventory error.") .. "\n"
|
status_text = S("Digtron unexpectedly failed to execute one or more build operations, likely due to an inventory error.") .. "\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
local total_fuel_cost = math.max(digging_fuel_cost + building_fuel_cost - power_from_cables, 0)
|
local total_fuel_cost = math.max(digging_fuel_cost + building_fuel_cost - power_from_cables, 0)
|
||||||
|
|
||||||
-- actually burn the fuel needed
|
-- actually burn the fuel needed
|
||||||
fuel_burning = fuel_burning - total_fuel_cost
|
fuel_burning = fuel_burning - total_fuel_cost
|
||||||
if digtron.config.particle_effects and exhaust == 1 then
|
if digtron.config.particle_effects and exhaust == 1 then
|
||||||
@ -391,7 +391,7 @@ digtron.execute_dig_cycle = function(pos, clicker)
|
|||||||
fuel_burning = fuel_burning + digtron.burn(layout.fuelstores, -fuel_burning, false)
|
fuel_burning = fuel_burning + digtron.burn(layout.fuelstores, -fuel_burning, false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
meta:set_float("fuel_burning", fuel_burning)
|
meta:set_float("fuel_burning", fuel_burning)
|
||||||
meta:set_int("on_coal", exhaust)
|
meta:set_int("on_coal", exhaust)
|
||||||
status_text = status_text .. S("Heat remaining in controller furnace: @1", math.floor(math.max(0, fuel_burning)))
|
status_text = status_text .. S("Heat remaining in controller furnace: @1", math.floor(math.max(0, fuel_burning)))
|
||||||
@ -400,7 +400,7 @@ digtron.execute_dig_cycle = function(pos, clicker)
|
|||||||
for _, particles in pairs(particle_systems) do
|
for _, particles in pairs(particle_systems) do
|
||||||
minetest.add_particlespawner(particles)
|
minetest.add_particlespawner(particles)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- finally, dig out any nodes remaining to be dug. Some of these will have had their flag revoked because
|
-- finally, dig out any nodes remaining to be dug. Some of these will have had their flag revoked because
|
||||||
-- a builder put something there or because they're another digtron node.
|
-- a builder put something there or because they're another digtron node.
|
||||||
local node_to_dig, whether_to_dig = layout.nodes_dug:pop()
|
local node_to_dig, whether_to_dig = layout.nodes_dug:pop()
|
||||||
@ -420,11 +420,11 @@ end
|
|||||||
|
|
||||||
-- Simplified version of the above method that only moves, and doesn't execute diggers or builders.
|
-- Simplified version of the above method that only moves, and doesn't execute diggers or builders.
|
||||||
digtron.execute_move_cycle = function(pos, clicker)
|
digtron.execute_move_cycle = function(pos, clicker)
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
local layout = digtron.DigtronLayout.create(pos, clicker)
|
local layout = digtron.DigtronLayout.create(pos, clicker)
|
||||||
|
|
||||||
local status_text = ""
|
local status_text = ""
|
||||||
local status_text, return_code = neighbour_test(layout, status_text, nil) -- skip traction check for pusher by passing nil for direction
|
local return_code
|
||||||
|
status_text, return_code = neighbour_test(layout, status_text, nil) -- skip traction check for pusher by passing nil for direction
|
||||||
if return_code ~= 0 then
|
if return_code ~= 0 then
|
||||||
return pos, status_text, return_code
|
return pos, status_text, return_code
|
||||||
end
|
end
|
||||||
@ -436,11 +436,10 @@ digtron.execute_move_cycle = function(pos, clicker)
|
|||||||
|
|
||||||
local facing = minetest.get_node(pos).param2
|
local facing = minetest.get_node(pos).param2
|
||||||
local dir = minetest.facedir_to_dir(facing)
|
local dir = minetest.facedir_to_dir(facing)
|
||||||
local controlling_coordinate = digtron.get_controlling_coordinate(pos, facing)
|
|
||||||
|
|
||||||
-- if the player is standing within the array or next to it, move him too.
|
-- if the player is standing within the array or next to it, move him too.
|
||||||
local move_player = move_player_test(layout, clicker)
|
local move_player = move_player_test(layout, clicker)
|
||||||
|
|
||||||
-- test if any digtrons are obstructed by non-digtron nodes
|
-- test if any digtrons are obstructed by non-digtron nodes
|
||||||
layout:move_layout_image(dir)
|
layout:move_layout_image(dir)
|
||||||
if not layout:can_write_layout_image() then
|
if not layout:can_write_layout_image() then
|
||||||
@ -453,12 +452,12 @@ digtron.execute_move_cycle = function(pos, clicker)
|
|||||||
end
|
end
|
||||||
|
|
||||||
minetest.sound_play("truck", {gain=1.0, pos=pos})
|
minetest.sound_play("truck", {gain=1.0, pos=pos})
|
||||||
|
|
||||||
--move the array
|
--move the array
|
||||||
if not layout:write_layout_image(clicker) then
|
if not layout:write_layout_image(clicker) then
|
||||||
return pos, "unrecoverable write_layout_image error", 1
|
return pos, "unrecoverable write_layout_image error", 1
|
||||||
end
|
end
|
||||||
|
|
||||||
pos = vector.add(pos, dir)
|
pos = vector.add(pos, dir)
|
||||||
if move_player then
|
if move_player then
|
||||||
clicker:moveto(vector.add(clicker:get_pos(), dir), true)
|
clicker:moveto(vector.add(clicker:get_pos(), dir), true)
|
||||||
@ -480,11 +479,12 @@ digtron.execute_downward_dig_cycle = function(pos, clicker)
|
|||||||
local dir = digtron.facedir_to_down_dir(facing)
|
local dir = digtron.facedir_to_down_dir(facing)
|
||||||
local fuel_burning = meta:get_float("fuel_burning") -- get amount of burned fuel left over from last cycle
|
local fuel_burning = meta:get_float("fuel_burning") -- get amount of burned fuel left over from last cycle
|
||||||
local status_text = S("Heat remaining in controller furnace: @1", math.floor(math.max(0, fuel_burning)))
|
local status_text = S("Heat remaining in controller furnace: @1", math.floor(math.max(0, fuel_burning)))
|
||||||
|
local return_code
|
||||||
local exhaust = meta:get_int("on_coal")
|
local exhaust = meta:get_int("on_coal")
|
||||||
|
|
||||||
local layout = digtron.DigtronLayout.create(pos, clicker)
|
local layout = digtron.DigtronLayout.create(pos, clicker)
|
||||||
|
|
||||||
local status_text, return_code = neighbour_test(layout, status_text, dir)
|
status_text, return_code = neighbour_test(layout, status_text, dir)
|
||||||
if return_code ~= 0 then
|
if return_code ~= 0 then
|
||||||
return pos, status_text, return_code
|
return pos, status_text, return_code
|
||||||
end
|
end
|
||||||
@ -494,15 +494,14 @@ digtron.execute_downward_dig_cycle = function(pos, clicker)
|
|||||||
return pos, size_check_error, 8
|
return pos, size_check_error, 8
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local controlling_coordinate = digtron.get_controlling_coordinate(pos, facing)
|
local controlling_coordinate = digtron.get_controlling_coordinate(pos, facing)
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
local items_dropped = {}
|
local items_dropped = {}
|
||||||
local digging_fuel_cost = 0
|
local digging_fuel_cost = 0
|
||||||
local particle_systems = {}
|
local particle_systems = {}
|
||||||
|
|
||||||
-- execute the execute_dig method on all digtron components that have one
|
-- execute the execute_dig method on all digtron components that have one
|
||||||
-- This builds a set of nodes that will be dug and returns a list of products that will be generated
|
-- This builds a set of nodes that will be dug and returns a list of products that will be generated
|
||||||
-- but doesn't actually dig the nodes yet. That comes later.
|
-- but doesn't actually dig the nodes yet. That comes later.
|
||||||
@ -527,9 +526,9 @@ digtron.execute_downward_dig_cycle = function(pos, clicker)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- test if any digtrons are obstructed by non-digtron nodes that haven't been marked
|
-- test if any digtrons are obstructed by non-digtron nodes that haven't been marked
|
||||||
-- as having been dug.
|
-- as having been dug.
|
||||||
local can_move = true
|
local can_move = true
|
||||||
@ -554,13 +553,13 @@ digtron.execute_downward_dig_cycle = function(pos, clicker)
|
|||||||
end
|
end
|
||||||
|
|
||||||
----------------------------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- All tests passed, ready to go for real!
|
-- All tests passed, ready to go for real!
|
||||||
minetest.sound_play("construction", {gain=1.0, pos=pos})
|
minetest.sound_play("construction", {gain=1.0, pos=pos})
|
||||||
|
|
||||||
-- if the player is standing within the array or next to it, move him too.
|
-- if the player is standing within the array or next to it, move him too.
|
||||||
local move_player = move_player_test(layout, clicker)
|
local move_player = move_player_test(layout, clicker)
|
||||||
|
|
||||||
-- damage the weak flesh
|
-- damage the weak flesh
|
||||||
if digtron.config.damage_hp > 0 and layout.diggers ~= nil then
|
if digtron.config.damage_hp > 0 and layout.diggers ~= nil then
|
||||||
for k, location in pairs(layout.diggers) do
|
for k, location in pairs(layout.diggers) do
|
||||||
@ -571,7 +570,7 @@ digtron.execute_downward_dig_cycle = function(pos, clicker)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--move the array
|
--move the array
|
||||||
layout:move_layout_image(digtron.facedir_to_down_dir(facing))
|
layout:move_layout_image(digtron.facedir_to_down_dir(facing))
|
||||||
if not layout:write_layout_image(clicker) then
|
if not layout:write_layout_image(clicker) then
|
||||||
@ -583,15 +582,15 @@ digtron.execute_downward_dig_cycle = function(pos, clicker)
|
|||||||
if move_player then
|
if move_player then
|
||||||
clicker:moveto(vector.add(clicker:get_pos(), dir), true)
|
clicker:moveto(vector.add(clicker:get_pos(), dir), true)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- store or drop the products of the digger heads
|
-- store or drop the products of the digger heads
|
||||||
for _, itemname in pairs(items_dropped) do
|
for _, itemname in pairs(items_dropped) do
|
||||||
digtron.place_in_inventory(itemname, layout.inventories, oldpos)
|
digtron.place_in_inventory(itemname, layout.inventories, oldpos)
|
||||||
end
|
end
|
||||||
digtron.award_item_dug(items_dropped, clicker) -- Achievements mod hook
|
digtron.award_item_dug(items_dropped, clicker) -- Achievements mod hook
|
||||||
|
|
||||||
local status_text = ""
|
status_text = ""
|
||||||
|
|
||||||
-- actually burn the fuel needed
|
-- actually burn the fuel needed
|
||||||
fuel_burning = fuel_burning - digging_fuel_cost
|
fuel_burning = fuel_burning - digging_fuel_cost
|
||||||
if digtron.config.particle_effects and exhaust == 1 then
|
if digtron.config.particle_effects and exhaust == 1 then
|
||||||
@ -614,7 +613,7 @@ digtron.execute_downward_dig_cycle = function(pos, clicker)
|
|||||||
for _, particles in pairs(particle_systems) do
|
for _, particles in pairs(particle_systems) do
|
||||||
minetest.add_particlespawner(particles)
|
minetest.add_particlespawner(particles)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- finally, dig out any nodes remaining to be dug. Some of these will have had their flag revoked because
|
-- finally, dig out any nodes remaining to be dug. Some of these will have had their flag revoked because
|
||||||
-- a builder put something there or because they're another digtron node.
|
-- a builder put something there or because they're another digtron node.
|
||||||
local node_to_dig, whether_to_dig = layout.nodes_dug:pop()
|
local node_to_dig, whether_to_dig = layout.nodes_dug:pop()
|
||||||
|
@ -36,13 +36,13 @@ digtron.whitelisted_on_place = function (item_name)
|
|||||||
for listed_item, value in pairs(digtron.builder_on_place_items) do
|
for listed_item, value in pairs(digtron.builder_on_place_items) do
|
||||||
if item_name == listed_item then return value end
|
if item_name == listed_item then return value end
|
||||||
end
|
end
|
||||||
|
|
||||||
for prefix, value in pairs(digtron.builder_on_place_prefixes) do
|
for prefix, value in pairs(digtron.builder_on_place_prefixes) do
|
||||||
if has_prefix(item_name, prefix) then return value end
|
if has_prefix(item_name, prefix) then return value end
|
||||||
end
|
end
|
||||||
|
|
||||||
if minetest.get_item_group(item_name, "digtron_on_place") > 0 then return true end
|
if minetest.get_item_group(item_name, "digtron_on_place") > 0 then return true end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ digtron.item_place_node = function(itemstack, placer, place_to, param2)
|
|||||||
pointed_thing.type = "node"
|
pointed_thing.type = "node"
|
||||||
pointed_thing.above = {x=place_to.x, y=place_to.y, z=place_to.z}
|
pointed_thing.above = {x=place_to.x, y=place_to.y, z=place_to.z}
|
||||||
pointed_thing.under = {x=place_to.x, y=place_to.y - 1, z=place_to.z}
|
pointed_thing.under = {x=place_to.x, y=place_to.y - 1, z=place_to.z}
|
||||||
|
|
||||||
-- Handle node-specific on_place calls as best we can.
|
-- Handle node-specific on_place calls as best we can.
|
||||||
if def.on_place and def.on_place ~= minetest.nodedef_default.on_place and digtron.whitelisted_on_place(item_name) then
|
if def.on_place and def.on_place ~= minetest.nodedef_default.on_place and digtron.whitelisted_on_place(item_name) then
|
||||||
if def.paramtype2 == "facedir" then
|
if def.paramtype2 == "facedir" then
|
||||||
@ -94,7 +94,7 @@ digtron.item_place_node = function(itemstack, placer, place_to, param2)
|
|||||||
elseif def.paramtype2 == "wallmounted" then
|
elseif def.paramtype2 == "wallmounted" then
|
||||||
pointed_thing.under = vector.add(place_to, minetest.wallmounted_to_dir(param2))
|
pointed_thing.under = vector.add(place_to, minetest.wallmounted_to_dir(param2))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- pass a copy of the item stack parameter because on_place might modify it directly and then we can't tell if we succeeded or not
|
-- pass a copy of the item stack parameter because on_place might modify it directly and then we can't tell if we succeeded or not
|
||||||
-- though note that some mods do "creative_mode" handling within their own on_place methods, which makes it impossible for Digtron
|
-- though note that some mods do "creative_mode" handling within their own on_place methods, which makes it impossible for Digtron
|
||||||
-- to know what to do in that case - if you're in creative_mode Digtron will place such items but it will think it failed and not
|
-- to know what to do in that case - if you're in creative_mode Digtron will place such items but it will think it failed and not
|
||||||
@ -107,10 +107,10 @@ digtron.item_place_node = function(itemstack, placer, place_to, param2)
|
|||||||
placed_node.param2 = param2
|
placed_node.param2 = param2
|
||||||
minetest.set_node(place_to, placed_node)
|
minetest.set_node(place_to, placed_node)
|
||||||
end
|
end
|
||||||
|
|
||||||
return returnstack, success
|
return returnstack, success
|
||||||
end
|
end
|
||||||
|
|
||||||
if minetest.registered_nodes[item_name] == nil then
|
if minetest.registered_nodes[item_name] == nil then
|
||||||
-- Permitted craft items are handled by the node-specific on_place call, above.
|
-- Permitted craft items are handled by the node-specific on_place call, above.
|
||||||
-- if we are a craft item and we get here then we're not whitelisted and we should fail.
|
-- if we are a craft item and we get here then we're not whitelisted and we should fail.
|
||||||
@ -118,7 +118,7 @@ digtron.item_place_node = function(itemstack, placer, place_to, param2)
|
|||||||
-- but this will protect us just in case.
|
-- but this will protect us just in case.
|
||||||
return itemstack, false
|
return itemstack, false
|
||||||
end
|
end
|
||||||
|
|
||||||
local oldnode = minetest.get_node_or_nil(place_to)
|
local oldnode = minetest.get_node_or_nil(place_to)
|
||||||
|
|
||||||
--this should never happen, digtron is testing for adjacent unloaded nodes before getting here.
|
--this should never happen, digtron is testing for adjacent unloaded nodes before getting here.
|
||||||
@ -141,7 +141,7 @@ digtron.item_place_node = function(itemstack, placer, place_to, param2)
|
|||||||
" can not be placed at " .. minetest.pos_to_string(place_to))
|
" can not be placed at " .. minetest.pos_to_string(place_to))
|
||||||
return itemstack, false
|
return itemstack, false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add node and update
|
-- Add node and update
|
||||||
minetest.add_node(place_to, newnode)
|
minetest.add_node(place_to, newnode)
|
||||||
|
|
||||||
@ -162,7 +162,6 @@ digtron.item_place_node = function(itemstack, placer, place_to, param2)
|
|||||||
-- Note that fake_player:update is called in the DigtronLayout class's "create" function,
|
-- Note that fake_player:update is called in the DigtronLayout class's "create" function,
|
||||||
-- which is called before Digtron does any of this building stuff, so it's not necessary
|
-- which is called before Digtron does any of this building stuff, so it's not necessary
|
||||||
-- to update it here.
|
-- to update it here.
|
||||||
local _, callback
|
|
||||||
for _, callback in ipairs(minetest.registered_on_placenodes) do
|
for _, callback in ipairs(minetest.registered_on_placenodes) do
|
||||||
-- Deepcopy pos, node and pointed_thing because callback can modify them
|
-- Deepcopy pos, node and pointed_thing because callback can modify them
|
||||||
local place_to_copy = {x=place_to.x, y=place_to.y, z=place_to.z}
|
local place_to_copy = {x=place_to.x, y=place_to.y, z=place_to.z}
|
||||||
|
Loading…
Reference in New Issue
Block a user