a little more optimization, and sounds when placing nodes on builders and diggers

This commit is contained in:
FaceDeer 2019-01-09 00:20:02 -07:00
parent d4a03478e2
commit 1d5d1d20df
6 changed files with 35 additions and 13 deletions

@ -32,6 +32,10 @@ local get_node_image = function(pos, node)
return node_image
end
-- temporary pointsets used while searching
local to_test = Pointset.create()
local tested = Pointset.create()
function DigtronLayout.create(pos, player)
local self = {}
setmetatable(self, DigtronLayout)
@ -57,10 +61,6 @@ function DigtronLayout.create(pos, player)
self.extents.max_z = pos.z
self.extents.min_z = pos.z
-- temporary pointsets used while searching
local to_test = Pointset.create()
local tested = Pointset.create()
tested:set(pos.x, pos.y, pos.z, true)
to_test:set(pos.x + 1, pos.y, pos.z, true)
to_test:set(pos.x - 1, pos.y, pos.z, true)
@ -168,6 +168,9 @@ function DigtronLayout.create(pos, player)
digtron.award_layout(self, player) -- hook for achievements mod
to_test:clear()
tested:clear()
return self
end

@ -17,6 +17,13 @@ function Pointset.create()
return set
end
function Pointset:clear()
local points = self.points
for k, v in pairs(points) do
points[k] = nil
end
end
function Pointset:set(x, y, z, value)
-- sets a value in the 3D array "points".
self.points[hash_node_position_values(x,y,z)] = value

@ -53,8 +53,13 @@ local builder_formspec = function(pos, meta)
end
local builder_on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
if itemstack:get_definition().type == "node" and minetest.get_item_group(itemstack:get_name(), "digtron") > 0 then
return minetest.item_place_node(itemstack, clicker, pointed_thing)
local item_def = itemstack:get_definition()
if item_def.type == "node" and minetest.get_item_group(itemstack:get_name(), "digtron") > 0 then
local returnstack, success = minetest.item_place_node(itemstack, clicker, pointed_thing)
if success and item_def.sounds and item_def.sounds.place and item_def.sounds.place.name then
minetest.sound_play(item_def.sounds.place, {pos = pos})
end
return returnstack, success
end
local meta = minetest.get_meta(pos)
minetest.show_formspec(clicker:get_player_name(),

@ -61,8 +61,13 @@ local intermittent_on_construct = function(pos)
end
local intermittent_on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
if itemstack:get_definition().type == "node" and minetest.get_item_group(itemstack:get_name(), "digtron") > 0 then
return minetest.item_place_node(itemstack, clicker, pointed_thing)
local item_def = itemstack:get_definition()
if item_def.type == "node" and minetest.get_item_group(itemstack:get_name(), "digtron") > 0 then
local returnstack, success = minetest.item_place_node(itemstack, clicker, pointed_thing)
if success and item_def.sounds and item_def.sounds.place and item_def.sounds.place.name then
minetest.sound_play(item_def.sounds.place, {pos = pos})
end
return returnstack, success
end
local meta = minetest.get_meta(pos)
minetest.show_formspec(clicker:get_player_name(),

@ -31,7 +31,7 @@ local ejector_formspec = function(pos, meta)
"tooltip[autoeject;" .. S("When checked, will eject items automatically with every Digtron cycle.\nItem ejectors can always be operated manually by punching them.") .. "]"
end
local function eject_items(pos, node, player, eject_even_without_pipeworks)
local function eject_items(pos, node, player, eject_even_without_pipeworks, layout)
local dir = minetest.facedir_to_dir(node.param2)
local destination_pos = vector.add(pos, dir)
local destination_node_name = minetest.get_node(destination_pos).name
@ -54,7 +54,9 @@ local function eject_items(pos, node, player, eject_even_without_pipeworks)
return false
end
local layout = DigtronLayout.create(pos, player)
if layout == nil then
layout = DigtronLayout.create(pos, player)
end
-- Build a list of all the items that builder nodes want to use.
local filter_items = {}
@ -141,9 +143,9 @@ minetest.register_node("digtron:inventory_ejector", {
eject_items(pos, node, player, true)
end,
execute_eject = function(pos, node, player)
execute_eject = function(pos, node, player, layout)
local meta = minetest.get_meta(pos)
eject_items(pos, node, player, meta:get_string("nonpipe") == "true")
eject_items(pos, node, player, meta:get_string("nonpipe") == "true", layout)
end,
on_receive_fields = function(pos, formname, fields, sender)

@ -337,7 +337,7 @@ digtron.execute_dig_cycle = function(pos, clicker)
local target = minetest.get_node(location.pos)
local targetdef = minetest.registered_nodes[target.name]
if targetdef.execute_eject ~= nil then
targetdef.execute_eject(location.pos, target, clicker)
targetdef.execute_eject(location.pos, target, clicker, layout)
else
minetest.log(string.format("%s has an ejector group but is missing execute_eject method! This is an error in mod programming, file a bug.", targetdef.name))
end