2017-04-01 16:28:03 +02:00
|
|
|
--[[
|
|
|
|
Minetest Mod Storage Drawers - A Mod adding storage drawers
|
|
|
|
|
2019-05-18 23:02:00 +02:00
|
|
|
Copyright (C) 2017-2019 Linus Jahn <lnj@kaidan.im>
|
2017-04-01 16:28:03 +02:00
|
|
|
|
|
|
|
MIT License
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
]]
|
|
|
|
|
2022-12-23 21:38:06 +01:00
|
|
|
local S = minetest.get_translator('drawers')
|
2017-04-11 13:02:31 +02:00
|
|
|
|
2017-04-01 16:28:03 +02:00
|
|
|
core.register_entity("drawers:visual", {
|
|
|
|
initial_properties = {
|
|
|
|
hp_max = 1,
|
|
|
|
physical = false,
|
|
|
|
collide_with_objects = false,
|
|
|
|
collisionbox = {-0.4374, -0.4374, 0, 0.4374, 0.4374, 0}, -- for param2 0, 2
|
|
|
|
visual = "upright_sprite", -- "wielditem" for items without inv img?
|
|
|
|
visual_size = {x = 0.6, y = 0.6},
|
2017-04-10 17:42:51 +02:00
|
|
|
textures = {"blank.png"},
|
2017-04-01 16:28:03 +02:00
|
|
|
spritediv = {x = 1, y = 1},
|
|
|
|
initial_sprite_basepos = {x = 0, y = 0},
|
|
|
|
is_visible = true,
|
|
|
|
},
|
|
|
|
|
|
|
|
get_staticdata = function(self)
|
|
|
|
return core.serialize({
|
|
|
|
drawer_posx = self.drawer_pos.x,
|
|
|
|
drawer_posy = self.drawer_pos.y,
|
|
|
|
drawer_posz = self.drawer_pos.z,
|
2017-04-02 21:29:32 +02:00
|
|
|
texture = self.texture,
|
|
|
|
drawerType = self.drawerType,
|
|
|
|
visualId = self.visualId
|
2017-04-01 16:28:03 +02:00
|
|
|
})
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_activate = function(self, staticdata, dtime_s)
|
|
|
|
-- Restore data
|
2017-04-09 23:31:33 +02:00
|
|
|
local data = core.deserialize(staticdata)
|
2017-04-01 16:28:03 +02:00
|
|
|
if data then
|
|
|
|
self.drawer_pos = {
|
|
|
|
x = data.drawer_posx,
|
|
|
|
y = data.drawer_posy,
|
|
|
|
z = data.drawer_posz,
|
|
|
|
}
|
|
|
|
self.texture = data.texture
|
2017-04-02 21:29:32 +02:00
|
|
|
self.drawerType = data.drawerType or 1
|
|
|
|
self.visualId = data.visualId or ""
|
2017-04-11 13:31:43 +02:00
|
|
|
|
|
|
|
-- backwards compatibility
|
|
|
|
if self.texture == "drawers_empty.png" then
|
|
|
|
self.texture = "blank.png"
|
|
|
|
end
|
2017-04-01 16:28:03 +02:00
|
|
|
else
|
|
|
|
self.drawer_pos = drawers.last_drawer_pos
|
2017-04-10 17:42:51 +02:00
|
|
|
self.texture = drawers.last_texture or "blank.png"
|
2017-04-02 21:29:32 +02:00
|
|
|
self.visualId = drawers.last_visual_id
|
|
|
|
self.drawerType = drawers.last_drawer_type
|
2017-04-01 16:28:03 +02:00
|
|
|
end
|
|
|
|
|
2019-04-21 11:37:27 +02:00
|
|
|
local node = minetest.get_node(self.object:get_pos())
|
2020-09-05 23:54:15 +02:00
|
|
|
if core.get_item_group(node.name, "drawer") == 0 then
|
2019-04-21 11:37:27 +02:00
|
|
|
self.object:remove()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-04-01 19:13:09 +02:00
|
|
|
-- add self to public drawer visuals
|
|
|
|
-- this is needed because there is no other way to get this class
|
2017-04-05 13:17:08 +02:00
|
|
|
-- only the underlying LuaEntitySAO
|
2017-04-01 19:13:09 +02:00
|
|
|
-- PLEASE contact me, if this is wrong
|
2017-04-05 13:17:08 +02:00
|
|
|
local vId = self.visualId
|
|
|
|
if vId == "" then vId = 1 end
|
2021-03-26 23:02:37 +01:00
|
|
|
local posstr = core.hash_node_position(self.drawer_pos)
|
2017-04-05 13:17:08 +02:00
|
|
|
if not drawers.drawer_visuals[posstr] then
|
|
|
|
drawers.drawer_visuals[posstr] = {[vId] = self}
|
|
|
|
else
|
|
|
|
drawers.drawer_visuals[posstr][vId] = self
|
|
|
|
end
|
|
|
|
|
2017-04-17 16:04:16 +02:00
|
|
|
-- get meta
|
|
|
|
self.meta = core.get_meta(self.drawer_pos)
|
2017-04-01 16:28:03 +02:00
|
|
|
|
|
|
|
-- collisionbox
|
2020-02-13 13:12:01 +01:00
|
|
|
node = core.get_node(self.drawer_pos)
|
2017-04-05 14:52:34 +02:00
|
|
|
local colbox
|
|
|
|
if self.drawerType ~= 2 then
|
|
|
|
if node.param2 == 1 or node.param2 == 3 then
|
|
|
|
colbox = {0, -0.4374, -0.4374, 0, 0.4374, 0.4374}
|
|
|
|
else
|
|
|
|
colbox = {-0.4374, -0.4374, 0, 0.4374, 0.4374, 0} -- for param2 = 0 or 2
|
|
|
|
end
|
|
|
|
-- only half the size if it's a small drawer
|
|
|
|
if self.drawerType > 1 then
|
|
|
|
for i,j in pairs(colbox) do
|
|
|
|
colbox[i] = j * 0.5
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if node.param2 == 1 or node.param2 == 3 then
|
|
|
|
colbox = {0, -0.2187, -0.4374, 0, 0.2187, 0.4374}
|
|
|
|
else
|
|
|
|
colbox = {-0.4374, -0.2187, 0, 0.4374, 0.2187, 0} -- for param2 = 0 or 2
|
2017-04-02 21:29:32 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- visual size
|
|
|
|
local visual_size = {x = 0.6, y = 0.6}
|
|
|
|
if self.drawerType >= 2 then
|
|
|
|
visual_size = {x = 0.3, y = 0.3}
|
|
|
|
end
|
|
|
|
|
2017-04-01 16:28:03 +02:00
|
|
|
|
2017-04-01 20:04:27 +02:00
|
|
|
-- drawer values
|
2017-04-02 21:29:32 +02:00
|
|
|
local vid = self.visualId
|
2017-04-17 16:04:16 +02:00
|
|
|
self.count = self.meta:get_int("count"..vid)
|
|
|
|
self.itemName = self.meta:get_string("name"..vid)
|
|
|
|
self.maxCount = self.meta:get_int("max_count"..vid)
|
|
|
|
self.itemStackMax = self.meta:get_int("base_stack_max"..vid)
|
|
|
|
self.stackMaxFactor = self.meta:get_int("stack_max_factor"..vid)
|
2017-04-01 20:04:27 +02:00
|
|
|
|
2017-04-01 16:28:03 +02:00
|
|
|
|
|
|
|
-- infotext
|
2017-04-17 16:04:16 +02:00
|
|
|
local infotext = self.meta:get_string("entity_infotext"..vid) .. "\n\n\n\n\n"
|
2017-04-01 16:28:03 +02:00
|
|
|
|
|
|
|
self.object:set_properties({
|
|
|
|
collisionbox = colbox,
|
|
|
|
infotext = infotext,
|
2017-04-02 21:29:32 +02:00
|
|
|
textures = {self.texture},
|
|
|
|
visual_size = visual_size
|
2017-04-01 16:28:03 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
-- make entity undestroyable
|
|
|
|
self.object:set_armor_groups({immortal = 1})
|
|
|
|
end,
|
|
|
|
|
|
|
|
on_rightclick = function(self, clicker)
|
2019-06-20 19:32:19 +02:00
|
|
|
if core.is_protected(self.drawer_pos, clicker:get_player_name()) then
|
|
|
|
core.record_protection_violation(self.drawer_pos, clicker:get_player_name())
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
-- used to check if we need to play a sound in the end
|
|
|
|
local inventoryChanged = false
|
|
|
|
|
|
|
|
-- When the player uses the drawer with their bare hand all
|
|
|
|
-- stacks from the inventory will be added to the drawer.
|
|
|
|
if self.itemName ~= "" and
|
|
|
|
clicker:get_wielded_item():get_name() == "" and
|
|
|
|
not clicker:get_player_control().sneak then
|
|
|
|
-- try to insert all items from inventory
|
|
|
|
local i = 0
|
|
|
|
local inv = clicker:get_inventory()
|
|
|
|
|
2020-01-15 02:20:35 +01:00
|
|
|
while i <= inv:get_size("main") do
|
2019-06-20 19:32:19 +02:00
|
|
|
-- set current stack to leftover of insertion
|
|
|
|
local leftover = self.try_insert_stack(
|
|
|
|
self,
|
|
|
|
inv:get_stack("main", i),
|
|
|
|
true
|
|
|
|
)
|
|
|
|
|
|
|
|
-- check if something was added
|
|
|
|
if leftover:get_count() < inv:get_stack("main", i):get_count() then
|
|
|
|
inventoryChanged = true
|
|
|
|
end
|
|
|
|
|
|
|
|
-- set new stack
|
|
|
|
inv:set_stack("main", i, leftover)
|
|
|
|
i = i + 1
|
|
|
|
end
|
|
|
|
else
|
|
|
|
-- try to insert wielded item only
|
|
|
|
local leftover = self.try_insert_stack(
|
|
|
|
self,
|
|
|
|
clicker:get_wielded_item(),
|
|
|
|
not clicker:get_player_control().sneak
|
|
|
|
)
|
|
|
|
|
|
|
|
-- check if something was added
|
|
|
|
if clicker:get_wielded_item():get_count() > leftover:get_count() then
|
|
|
|
inventoryChanged = true
|
|
|
|
end
|
|
|
|
-- set the leftover as new wielded item for the player
|
|
|
|
clicker:set_wielded_item(leftover)
|
2017-10-10 20:17:43 +02:00
|
|
|
end
|
2017-04-01 16:28:03 +02:00
|
|
|
|
2019-06-20 19:32:19 +02:00
|
|
|
if inventoryChanged then
|
2017-05-30 19:09:37 +02:00
|
|
|
self:play_interact_sound()
|
|
|
|
end
|
2017-04-01 16:28:03 +02:00
|
|
|
end,
|
|
|
|
|
|
|
|
on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir)
|
2019-03-27 17:27:55 +01:00
|
|
|
local node = minetest.get_node(self.object:get_pos())
|
2020-09-05 23:54:15 +02:00
|
|
|
|
|
|
|
if core.get_item_group(node.name, "drawer") == 0 then
|
2019-03-27 17:27:55 +01:00
|
|
|
self.object:remove()
|
|
|
|
return
|
|
|
|
end
|
2017-05-30 19:09:37 +02:00
|
|
|
local add_stack = not puncher:get_player_control().sneak
|
2017-10-10 20:17:43 +02:00
|
|
|
if core.is_protected(self.drawer_pos, puncher:get_player_name()) then
|
|
|
|
core.record_protection_violation(self.drawer_pos, puncher:get_player_name())
|
|
|
|
return
|
|
|
|
end
|
2017-05-30 19:09:37 +02:00
|
|
|
local inv = puncher:get_inventory()
|
2019-05-05 14:21:46 +02:00
|
|
|
if inv == nil then
|
2020-02-13 13:12:01 +01:00
|
|
|
return
|
2019-05-05 14:21:46 +02:00
|
|
|
end
|
2017-05-30 19:09:37 +02:00
|
|
|
local spaceChecker = ItemStack(self.itemName)
|
|
|
|
if add_stack then
|
|
|
|
spaceChecker:set_count(spaceChecker:get_stack_max())
|
|
|
|
end
|
|
|
|
if not inv:room_for_item("main", spaceChecker) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-01-09 14:20:43 +01:00
|
|
|
local stack
|
|
|
|
if add_stack then
|
|
|
|
stack = self:take_stack()
|
|
|
|
else
|
|
|
|
stack = self:take_items(1)
|
|
|
|
end
|
|
|
|
|
2017-05-30 19:09:37 +02:00
|
|
|
if stack ~= nil then
|
|
|
|
-- add removed stack to player's inventory
|
|
|
|
inv:add_item("main", stack)
|
|
|
|
|
|
|
|
-- play the interact sound
|
|
|
|
self:play_interact_sound()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
2020-01-09 14:20:43 +01:00
|
|
|
take_items = function(self, removeCount)
|
2017-04-01 16:28:03 +02:00
|
|
|
local meta = core.get_meta(self.drawer_pos)
|
|
|
|
|
2017-04-01 20:04:27 +02:00
|
|
|
if self.count <= 0 then
|
2017-04-01 16:28:03 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-05-30 19:09:37 +02:00
|
|
|
if removeCount > self.count then
|
|
|
|
removeCount = self.count
|
|
|
|
end
|
2017-04-01 16:28:03 +02:00
|
|
|
|
2017-04-01 20:04:27 +02:00
|
|
|
local stack = ItemStack(self.itemName)
|
|
|
|
stack:set_count(removeCount)
|
2017-04-01 16:28:03 +02:00
|
|
|
|
2017-05-30 19:09:37 +02:00
|
|
|
-- update the drawer count
|
2017-04-01 20:04:27 +02:00
|
|
|
self.count = self.count - removeCount
|
2017-05-30 19:09:37 +02:00
|
|
|
|
2017-04-17 16:04:16 +02:00
|
|
|
self:updateInfotext()
|
|
|
|
self:updateTexture()
|
|
|
|
self:saveMetaData()
|
2017-05-30 19:09:37 +02:00
|
|
|
|
|
|
|
-- return the stack that was removed from the drawer
|
|
|
|
return stack
|
2017-04-01 19:13:09 +02:00
|
|
|
end,
|
|
|
|
|
2020-01-09 14:20:43 +01:00
|
|
|
take_stack = function(self)
|
|
|
|
return self:take_items(ItemStack(self.itemName):get_stack_max())
|
|
|
|
end,
|
|
|
|
|
2020-06-09 20:01:17 +02:00
|
|
|
can_insert_stack = function(self, stack)
|
|
|
|
if stack:get_name() == "" or stack:get_count() <= 0 then
|
|
|
|
return 0
|
|
|
|
end
|
2017-04-01 19:13:09 +02:00
|
|
|
|
2020-06-09 20:01:17 +02:00
|
|
|
-- don't allow unstackable stacks
|
|
|
|
if self.itemName == "" and stack:get_stack_max() ~= 1 then
|
|
|
|
return stack:get_count()
|
2017-04-01 19:13:09 +02:00
|
|
|
end
|
|
|
|
|
2020-06-09 20:01:17 +02:00
|
|
|
if self.itemName ~= stack:get_name() then
|
|
|
|
return 0
|
|
|
|
end
|
2017-04-01 19:13:09 +02:00
|
|
|
|
2020-06-09 20:01:17 +02:00
|
|
|
if (self.count + stack:get_count()) <= self.maxCount then
|
|
|
|
return stack:get_count()
|
2017-04-23 18:13:25 +02:00
|
|
|
end
|
2020-06-09 20:01:17 +02:00
|
|
|
return self.maxCount - self.count
|
|
|
|
end,
|
2017-04-01 19:13:09 +02:00
|
|
|
|
2020-06-09 20:01:17 +02:00
|
|
|
try_insert_stack = function(self, itemstack, insert_all)
|
|
|
|
local stackCount = itemstack:get_count()
|
|
|
|
local stackName = itemstack:get_name()
|
|
|
|
|
|
|
|
local insertCount = self:can_insert_stack(itemstack)
|
|
|
|
|
|
|
|
if insertCount == 0 then
|
2017-04-23 18:13:25 +02:00
|
|
|
return itemstack
|
2017-04-01 19:13:09 +02:00
|
|
|
end
|
|
|
|
|
2020-06-09 20:01:17 +02:00
|
|
|
-- only add one, if player holding sneak key
|
|
|
|
if not insert_all then
|
|
|
|
insertCount = 1
|
2017-04-01 19:13:09 +02:00
|
|
|
end
|
2017-04-01 20:04:27 +02:00
|
|
|
|
2020-06-09 20:01:17 +02:00
|
|
|
-- in case the drawer was empty, initialize count, itemName, maxCount
|
|
|
|
if self.itemName == "" then
|
|
|
|
self.count = 0
|
|
|
|
self.itemName = itemstack:get_name()
|
|
|
|
self.maxCount = itemstack:get_stack_max() * self.stackMaxFactor
|
2020-09-23 16:10:39 +02:00
|
|
|
self.itemStackMax = itemstack:get_stack_max()
|
2020-06-09 20:01:17 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- update everything
|
|
|
|
self.count = self.count + insertCount
|
2017-04-17 16:04:16 +02:00
|
|
|
self:updateInfotext()
|
|
|
|
self:updateTexture()
|
|
|
|
self:saveMetaData()
|
2017-04-01 19:13:09 +02:00
|
|
|
|
2020-06-09 20:01:17 +02:00
|
|
|
-- return leftover
|
|
|
|
itemstack:take_item(insertCount)
|
|
|
|
if itemstack:get_count() == 0 then
|
|
|
|
return ItemStack("")
|
|
|
|
end
|
2017-04-17 16:04:16 +02:00
|
|
|
return itemstack
|
|
|
|
end,
|
|
|
|
|
|
|
|
updateInfotext = function(self)
|
|
|
|
local itemDescription = ""
|
2017-04-01 20:04:27 +02:00
|
|
|
if core.registered_items[self.itemName] then
|
|
|
|
itemDescription = core.registered_items[self.itemName].description
|
2017-04-17 16:04:16 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
if self.count <= 0 then
|
|
|
|
self.itemName = ""
|
|
|
|
self.meta:set_string("name"..self.visualId, self.itemName)
|
|
|
|
self.texture = "blank.png"
|
2017-04-11 13:02:31 +02:00
|
|
|
itemDescription = S("Empty")
|
2017-04-01 20:04:27 +02:00
|
|
|
end
|
2017-04-17 16:04:16 +02:00
|
|
|
|
2017-04-01 20:04:27 +02:00
|
|
|
local infotext = drawers.gen_info_text(itemDescription,
|
|
|
|
self.count, self.stackMaxFactor, self.itemStackMax)
|
2017-04-17 16:04:16 +02:00
|
|
|
self.meta:set_string("entity_infotext"..self.visualId, infotext)
|
2017-04-01 19:13:09 +02:00
|
|
|
|
2017-04-17 16:04:16 +02:00
|
|
|
self.object:set_properties({
|
|
|
|
infotext = infotext .. "\n\n\n\n\n"
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
|
|
|
|
updateTexture = function(self)
|
2017-04-01 19:13:09 +02:00
|
|
|
-- texture
|
2017-04-01 20:04:27 +02:00
|
|
|
self.texture = drawers.get_inv_image(self.itemName)
|
2017-04-01 19:13:09 +02:00
|
|
|
|
|
|
|
self.object:set_properties({
|
|
|
|
textures = {self.texture}
|
|
|
|
})
|
2017-04-17 16:04:16 +02:00
|
|
|
end,
|
2017-04-01 19:13:09 +02:00
|
|
|
|
2017-04-17 16:04:16 +02:00
|
|
|
dropStack = function(self, itemStack)
|
|
|
|
-- print warning if dropping higher stack counts than allowed
|
|
|
|
if itemStack:get_count() > itemStack:get_stack_max() then
|
|
|
|
core.log("warning", "[drawers] Dropping item stack with higher count than allowed")
|
|
|
|
end
|
|
|
|
-- find a position containing air
|
|
|
|
local dropPos = core.find_node_near(self.drawer_pos, 1, {"air"}, false)
|
|
|
|
-- if no pos found then drop on the top of the drawer
|
|
|
|
if not dropPos then
|
2021-07-31 12:07:28 +02:00
|
|
|
dropPos = self.object:get_pos()
|
2017-04-17 16:04:16 +02:00
|
|
|
dropPos.y = dropPos.y + 1
|
|
|
|
end
|
|
|
|
-- drop the item stack
|
|
|
|
core.item_drop(itemStack, nil, dropPos)
|
|
|
|
end,
|
2017-04-01 20:04:27 +02:00
|
|
|
|
2017-04-17 16:04:16 +02:00
|
|
|
dropItemOverload = function(self)
|
|
|
|
-- drop stacks until there are no more items than allowed
|
|
|
|
while self.count > self.maxCount do
|
|
|
|
-- remove the overflow
|
|
|
|
local removeCount = self.count - self.maxCount
|
|
|
|
-- if this is too much for a single stack, only take the
|
|
|
|
-- stack limit
|
|
|
|
if removeCount > self.itemStackMax then
|
|
|
|
removeCount = self.itemStackMax
|
|
|
|
end
|
|
|
|
-- remove this count from the drawer
|
|
|
|
self.count = self.count - removeCount
|
|
|
|
-- create a new item stack having the size of the remove
|
|
|
|
-- count
|
|
|
|
local stack = ItemStack(self.itemName)
|
|
|
|
stack:set_count(removeCount)
|
|
|
|
print(stack:to_string())
|
|
|
|
-- drop the stack
|
|
|
|
self:dropStack(stack)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
|
|
|
|
setStackMaxFactor = function(self, stackMaxFactor)
|
|
|
|
self.stackMaxFactor = stackMaxFactor
|
|
|
|
self.maxCount = self.stackMaxFactor * self.itemStackMax
|
|
|
|
|
|
|
|
-- will drop possible overflowing items
|
|
|
|
self:dropItemOverload()
|
|
|
|
self:updateInfotext()
|
|
|
|
self:saveMetaData()
|
2017-04-01 20:04:27 +02:00
|
|
|
end,
|
|
|
|
|
2017-05-30 19:09:37 +02:00
|
|
|
play_interact_sound = function(self)
|
|
|
|
core.sound_play("drawers_interact", {
|
2019-03-24 20:01:49 +01:00
|
|
|
pos = self.object:get_pos(),
|
2017-05-30 19:09:37 +02:00
|
|
|
max_hear_distance = 6,
|
|
|
|
gain = 2.0
|
|
|
|
})
|
|
|
|
end,
|
|
|
|
|
2017-04-01 20:04:27 +02:00
|
|
|
saveMetaData = function(self, meta)
|
2017-04-17 16:04:16 +02:00
|
|
|
self.meta:set_int("count"..self.visualId, self.count)
|
|
|
|
self.meta:set_string("name"..self.visualId, self.itemName)
|
|
|
|
self.meta:set_int("max_count"..self.visualId, self.maxCount)
|
|
|
|
self.meta:set_int("base_stack_max"..self.visualId, self.itemStackMax)
|
|
|
|
self.meta:set_int("stack_max_factor"..self.visualId, self.stackMaxFactor)
|
2017-04-01 16:28:03 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
core.register_lbm({
|
|
|
|
name = "drawers:restore_visual",
|
|
|
|
nodenames = {"group:drawer"},
|
|
|
|
run_at_every_load = true,
|
|
|
|
action = function(pos, node)
|
2017-06-03 17:40:29 +02:00
|
|
|
local meta = core.get_meta(pos)
|
|
|
|
-- create drawer upgrade inventory
|
|
|
|
meta:get_inventory():set_size("upgrades", 5)
|
|
|
|
-- set the formspec
|
|
|
|
meta:set_string("formspec", drawers.drawer_formspec)
|
|
|
|
|
|
|
|
-- count the drawer visuals
|
2017-04-05 12:01:23 +02:00
|
|
|
local drawerType = core.registered_nodes[node.name].groups.drawer
|
|
|
|
local foundVisuals = 0
|
2020-05-16 14:54:08 +02:00
|
|
|
local objs = core.get_objects_inside_radius(pos, 0.56)
|
2017-04-01 16:28:03 +02:00
|
|
|
if objs then
|
|
|
|
for _, obj in pairs(objs) do
|
|
|
|
if obj and obj:get_luaentity() and
|
|
|
|
obj:get_luaentity().name == "drawers:visual" then
|
2017-04-05 12:01:23 +02:00
|
|
|
foundVisuals = foundVisuals + 1
|
2017-04-01 16:28:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-04-05 12:01:23 +02:00
|
|
|
-- if all drawer visuals were found, return
|
|
|
|
if foundVisuals == drawerType then
|
|
|
|
return
|
|
|
|
end
|
2017-04-01 16:28:03 +02:00
|
|
|
|
2017-04-05 12:01:23 +02:00
|
|
|
-- not enough visuals found, remove existing and create new ones
|
|
|
|
drawers.remove_visuals(pos)
|
|
|
|
drawers.spawn_visuals(pos)
|
2017-04-01 16:28:03 +02:00
|
|
|
end
|
|
|
|
})
|