mirror of
https://github.com/minetest-mods/digtron.git
synced 2024-12-22 20:32:22 +01:00
a little more optimization, and sounds when placing nodes on builders and diggers
This commit is contained in:
parent
d4a03478e2
commit
1d5d1d20df
@ -32,6 +32,10 @@ local get_node_image = function(pos, node)
|
|||||||
return node_image
|
return node_image
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- temporary pointsets used while searching
|
||||||
|
local to_test = Pointset.create()
|
||||||
|
local tested = Pointset.create()
|
||||||
|
|
||||||
function DigtronLayout.create(pos, player)
|
function DigtronLayout.create(pos, player)
|
||||||
local self = {}
|
local self = {}
|
||||||
setmetatable(self, DigtronLayout)
|
setmetatable(self, DigtronLayout)
|
||||||
@ -57,10 +61,6 @@ function DigtronLayout.create(pos, player)
|
|||||||
self.extents.max_z = pos.z
|
self.extents.max_z = pos.z
|
||||||
self.extents.min_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)
|
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)
|
||||||
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
|
digtron.award_layout(self, player) -- hook for achievements mod
|
||||||
|
|
||||||
|
to_test:clear()
|
||||||
|
tested:clear()
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -17,6 +17,13 @@ function Pointset.create()
|
|||||||
return set
|
return set
|
||||||
end
|
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)
|
function Pointset:set(x, y, z, value)
|
||||||
-- sets a value in the 3D array "points".
|
-- sets a value in the 3D array "points".
|
||||||
self.points[hash_node_position_values(x,y,z)] = value
|
self.points[hash_node_position_values(x,y,z)] = value
|
||||||
|
@ -53,8 +53,13 @@ local builder_formspec = function(pos, meta)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local builder_on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
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
|
local item_def = itemstack:get_definition()
|
||||||
return minetest.item_place_node(itemstack, clicker, pointed_thing)
|
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
|
end
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
minetest.show_formspec(clicker:get_player_name(),
|
minetest.show_formspec(clicker:get_player_name(),
|
||||||
|
@ -61,8 +61,13 @@ local intermittent_on_construct = function(pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local intermittent_on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
|
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
|
local item_def = itemstack:get_definition()
|
||||||
return minetest.item_place_node(itemstack, clicker, pointed_thing)
|
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
|
end
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
minetest.show_formspec(clicker:get_player_name(),
|
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.") .. "]"
|
"tooltip[autoeject;" .. S("When checked, will eject items automatically with every Digtron cycle.\nItem ejectors can always be operated manually by punching them.") .. "]"
|
||||||
end
|
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 dir = minetest.facedir_to_dir(node.param2)
|
||||||
local destination_pos = vector.add(pos, dir)
|
local destination_pos = vector.add(pos, dir)
|
||||||
local destination_node_name = minetest.get_node(destination_pos).name
|
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
|
return false
|
||||||
end
|
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.
|
-- Build a list of all the items that builder nodes want to use.
|
||||||
local filter_items = {}
|
local filter_items = {}
|
||||||
@ -141,9 +143,9 @@ minetest.register_node("digtron:inventory_ejector", {
|
|||||||
eject_items(pos, node, player, true)
|
eject_items(pos, node, player, true)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
execute_eject = function(pos, node, player)
|
execute_eject = function(pos, node, player, layout)
|
||||||
local meta = minetest.get_meta(pos)
|
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,
|
end,
|
||||||
|
|
||||||
on_receive_fields = function(pos, formname, fields, sender)
|
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 target = minetest.get_node(location.pos)
|
||||||
local targetdef = minetest.registered_nodes[target.name]
|
local targetdef = minetest.registered_nodes[target.name]
|
||||||
if targetdef.execute_eject ~= nil then
|
if targetdef.execute_eject ~= nil then
|
||||||
targetdef.execute_eject(location.pos, target, clicker)
|
targetdef.execute_eject(location.pos, target, clicker, layout)
|
||||||
else
|
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))
|
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
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user