mirror of
https://github.com/minetest-mods/drawers.git
synced 2024-11-09 16:33:44 +01:00
Add basic 2x2 Drawers
They're still missing some functionality as pipeworks and drops after dug. This will be done in the next commit(s).
This commit is contained in:
parent
06beee4652
commit
d3d29fb497
@ -32,7 +32,8 @@ License of media:
|
|||||||
-----------------
|
-----------------
|
||||||
Copyright (C) 2014 Justin Aquadro (MIT):
|
Copyright (C) 2014 Justin Aquadro (MIT):
|
||||||
textures/drawers_wood.png
|
textures/drawers_wood.png
|
||||||
textures/drawers_wood_front.png
|
textures/drawers_wood_front_1.png
|
||||||
|
textures/drawers_wood_front_4.png
|
||||||
|
|
||||||
Everything not listed in here:
|
Everything not listed in here:
|
||||||
Copyright (C) 2017 LNJ <git@lnj.li> (CC0 1.0)
|
Copyright (C) 2017 LNJ <git@lnj.li> (CC0 1.0)
|
||||||
|
6
init.lua
6
init.lua
@ -59,8 +59,10 @@ dofile(modpath .. "/lua/api.lua")
|
|||||||
|
|
||||||
drawers.register_drawer("drawers:wood", {
|
drawers.register_drawer("drawers:wood", {
|
||||||
description = "Wooden Drawer",
|
description = "Wooden Drawer",
|
||||||
tiles = {"drawers_wood.png", "drawers_wood.png", "drawers_wood.png",
|
tiles1 = {"drawers_wood.png", "drawers_wood.png", "drawers_wood.png",
|
||||||
"drawers_wood.png", "drawers_wood.png", "drawers_wood_front.png"},
|
"drawers_wood.png", "drawers_wood.png", "drawers_wood_front_1.png"},
|
||||||
|
tiles4 = {"drawers_wood.png", "drawers_wood.png", "drawers_wood.png",
|
||||||
|
"drawers_wood.png", "drawers_wood.png", "drawers_wood_front_4.png"},
|
||||||
groups = {choppy = 3, oddly_breakable_by_hand = 2},
|
groups = {choppy = 3, oddly_breakable_by_hand = 2},
|
||||||
sounds = drawers.WOOD_SOUNDS,
|
sounds = drawers.WOOD_SOUNDS,
|
||||||
drawer_stack_max_factor = 3 * 8, -- normal chest size
|
drawer_stack_max_factor = 3 * 8, -- normal chest size
|
||||||
|
46
lua/api.lua
46
lua/api.lua
@ -37,33 +37,40 @@ drawers.node_box_simple = {
|
|||||||
function drawers.drawer_on_construct(pos)
|
function drawers.drawer_on_construct(pos)
|
||||||
local node = core.get_node(pos)
|
local node = core.get_node(pos)
|
||||||
local ndef = core.registered_nodes[node.name]
|
local ndef = core.registered_nodes[node.name]
|
||||||
|
local drawerType = ndef.groups.drawer
|
||||||
|
|
||||||
local base_stack_max = core.nodedef_default.stack_max or 99
|
local base_stack_max = core.nodedef_default.stack_max or 99
|
||||||
local stack_max_factor = ndef.drawer_stack_max_factor or 24 -- 3x8
|
local stack_max_factor = ndef.drawer_stack_max_factor or 24 -- 3x8
|
||||||
|
stack_max_factor = math.floor(stack_max_factor / drawerType) -- drawerType => number of drawers in node
|
||||||
|
|
||||||
-- meta
|
-- meta
|
||||||
local meta = core.get_meta(pos)
|
local meta = core.get_meta(pos)
|
||||||
meta:set_string("name", "")
|
|
||||||
meta:set_int("count", 0)
|
i = 1
|
||||||
meta:set_int("max_count", base_stack_max * stack_max_factor)
|
while i <= drawerType do
|
||||||
meta:set_int("stack_max_factor", stack_max_factor)
|
meta:set_string("name"..i, "")
|
||||||
meta:set_int("base_stack_max", base_stack_max)
|
meta:set_int("count"..i, 0)
|
||||||
meta:set_string("entity_infotext", drawers.gen_info_text("Empty", 0,
|
meta:set_int("max_count"..i, base_stack_max * stack_max_factor)
|
||||||
|
meta:set_int("base_stack_max"..i, base_stack_max)
|
||||||
|
meta:set_string("entity_infotext"..i, drawers.gen_info_text("Empty", 0,
|
||||||
stack_max_factor, base_stack_max))
|
stack_max_factor, base_stack_max))
|
||||||
|
meta:set_int("stack_max_factor"..i, stack_max_factor)
|
||||||
|
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
|
||||||
drawers.spawn_visual(pos)
|
drawers.spawn_visual(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- destruct drawer
|
-- destruct drawer
|
||||||
function drawers.drawer_on_destruct(pos)
|
function drawers.drawer_on_destruct(pos)
|
||||||
local objs = core.get_objects_inside_radius(pos, 0.5)
|
local objs = core.get_objects_inside_radius(pos, 0.537)
|
||||||
if objs then
|
if not objs then return end
|
||||||
|
|
||||||
for _, obj in pairs(objs) do
|
for _, obj in pairs(objs) do
|
||||||
if obj and obj:get_luaentity() and
|
if obj and obj:get_luaentity() and
|
||||||
obj:get_luaentity().name == "drawers:visual" then
|
obj:get_luaentity().name == "drawers:visual" then
|
||||||
obj:remove()
|
obj:remove()
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -110,7 +117,6 @@ function drawers.register_drawer(name, def)
|
|||||||
def.paramtype2 = "facedir"
|
def.paramtype2 = "facedir"
|
||||||
def.legacy_facedir_simple = true
|
def.legacy_facedir_simple = true
|
||||||
def.groups = def.groups or {}
|
def.groups = def.groups or {}
|
||||||
def.groups.drawer = def.groups.drawer or 1
|
|
||||||
def.drawer_stack_max_factor = def.drawer_stack_max_factor or 24
|
def.drawer_stack_max_factor = def.drawer_stack_max_factor or 24
|
||||||
|
|
||||||
-- events
|
-- events
|
||||||
@ -134,7 +140,23 @@ function drawers.register_drawer(name, def)
|
|||||||
def.after_dig_node = pipeworks.after_dig
|
def.after_dig_node = pipeworks.after_dig
|
||||||
end
|
end
|
||||||
|
|
||||||
core.register_node(name, def)
|
-- normal drawer 1x1 = 1
|
||||||
|
def1 = table.copy(def)
|
||||||
|
def1.tiles = def.tiles or def.tiles1
|
||||||
|
def1.tiles1 = nil
|
||||||
|
def1.tiles4 = nil
|
||||||
|
def1.groups.drawer = 1
|
||||||
|
core.register_node(name .. "1", def1)
|
||||||
|
core.register_alias(name, name .. "1") -- 1x1 drawer is the default one
|
||||||
|
|
||||||
|
-- 2x2 = 4
|
||||||
|
def4 = table.copy(def)
|
||||||
|
def4.description = def4.description .. " (2x2)"
|
||||||
|
def4.tiles = def.tiles4
|
||||||
|
def4.tiles1 = nil
|
||||||
|
def4.tiles4 = nil
|
||||||
|
def4.groups.drawer = 4
|
||||||
|
core.register_node(name .. "4", def4)
|
||||||
|
|
||||||
if (not def.no_craft) and def.material then
|
if (not def.no_craft) and def.material then
|
||||||
core.register_craft({
|
core.register_craft({
|
||||||
|
@ -68,9 +68,15 @@ end
|
|||||||
|
|
||||||
function drawers.spawn_visual(pos)
|
function drawers.spawn_visual(pos)
|
||||||
local node = core.get_node(pos)
|
local node = core.get_node(pos)
|
||||||
|
local ndef = core.registered_nodes[node.name]
|
||||||
|
local drawerType = ndef.groups.drawer
|
||||||
|
|
||||||
-- data for the new visual
|
-- data for the new visual
|
||||||
drawers.last_drawer_pos = pos
|
drawers.last_drawer_pos = pos
|
||||||
|
drawers.last_drawer_type = drawerType
|
||||||
|
|
||||||
|
if drawerType == 1 then -- 1x1 drawer
|
||||||
|
drawers.last_visual_id = ""
|
||||||
drawers.last_texture = drawers.get_inv_image(core.get_meta(pos):get_string("name"))
|
drawers.last_texture = drawers.get_inv_image(core.get_meta(pos):get_string("name"))
|
||||||
|
|
||||||
local bdir = core.facedir_to_dir(node.param2)
|
local bdir = core.facedir_to_dir(node.param2)
|
||||||
@ -84,4 +90,62 @@ function drawers.spawn_visual(pos)
|
|||||||
if bdir.x > 0 then obj:setyaw(1.5 * math.pi) end
|
if bdir.x > 0 then obj:setyaw(1.5 * math.pi) end
|
||||||
|
|
||||||
drawers.last_texture = nil
|
drawers.last_texture = nil
|
||||||
|
else -- 2x2 drawer
|
||||||
|
local bdir = core.facedir_to_dir(node.param2)
|
||||||
|
|
||||||
|
local fdir1
|
||||||
|
local fdir2
|
||||||
|
local fdir3
|
||||||
|
local fdir4
|
||||||
|
if node.param2 == 2 then
|
||||||
|
fdir1 = vector.new(-bdir.x + 0.5, 0.5, -bdir.z)
|
||||||
|
fdir2 = vector.new(-bdir.x - 0.5, 0.5, -bdir.z)
|
||||||
|
fdir3 = vector.new(-bdir.x + 0.5, -0.5, -bdir.z)
|
||||||
|
fdir4 = vector.new(-bdir.x - 0.5, -0.5, -bdir.z)
|
||||||
|
elseif node.param2 == 0 then
|
||||||
|
fdir1 = vector.new(-bdir.x - 0.5, 0.5, -bdir.z)
|
||||||
|
fdir2 = vector.new(-bdir.x + 0.5, 0.5, -bdir.z)
|
||||||
|
fdir3 = vector.new(-bdir.x - 0.5, -0.5, -bdir.z)
|
||||||
|
fdir4 = vector.new(-bdir.x + 0.5, -0.5, -bdir.z)
|
||||||
|
elseif node.param2 == 1 then
|
||||||
|
fdir1 = vector.new(-bdir.x, 0.5, -bdir.z + 0.5)
|
||||||
|
fdir2 = vector.new(-bdir.x, 0.5, -bdir.z - 0.5)
|
||||||
|
fdir3 = vector.new(-bdir.x, -0.5, -bdir.z + 0.5)
|
||||||
|
fdir4 = vector.new(-bdir.x, -0.5, -bdir.z - 0.5)
|
||||||
|
else
|
||||||
|
fdir1 = vector.new(-bdir.x, 0.5, -bdir.z - 0.5)
|
||||||
|
fdir2 = vector.new(-bdir.x, 0.5, -bdir.z + 0.5)
|
||||||
|
fdir3 = vector.new(-bdir.x, -0.5, -bdir.z - 0.5)
|
||||||
|
fdir4 = vector.new(-bdir.x, -0.5, -bdir.z + 0.5)
|
||||||
|
end
|
||||||
|
|
||||||
|
objs = {}
|
||||||
|
|
||||||
|
drawers.last_visual_id = 1
|
||||||
|
drawers.last_texture = drawers.get_inv_image(core.get_meta(pos):get_string("name1"))
|
||||||
|
local pos1 = vector.add(pos, vector.multiply(fdir1, 0.438))
|
||||||
|
objs[1] = core.add_entity(pos1, "drawers:visual")
|
||||||
|
|
||||||
|
drawers.last_visual_id = 2
|
||||||
|
drawers.last_texture = drawers.get_inv_image(core.get_meta(pos):get_string("name2"))
|
||||||
|
local pos2 = vector.add(pos, vector.multiply(fdir2, 0.438))
|
||||||
|
objs[2] = core.add_entity(pos2, "drawers:visual")
|
||||||
|
|
||||||
|
drawers.last_visual_id = 3
|
||||||
|
drawers.last_texture = drawers.get_inv_image(core.get_meta(pos):get_string("name3"))
|
||||||
|
local pos3 = vector.add(pos, vector.multiply(fdir3, 0.438))
|
||||||
|
objs[3] = core.add_entity(pos3, "drawers:visual")
|
||||||
|
|
||||||
|
drawers.last_visual_id = 4
|
||||||
|
drawers.last_texture = drawers.get_inv_image(core.get_meta(pos):get_string("name4"))
|
||||||
|
local pos4 = vector.add(pos, vector.multiply(fdir4, 0.438))
|
||||||
|
objs[4] = core.add_entity(pos4, "drawers:visual")
|
||||||
|
|
||||||
|
|
||||||
|
for i,obj in pairs(objs) do
|
||||||
|
if bdir.x < 0 then obj:setyaw(0.5 * math.pi) end
|
||||||
|
if bdir.z < 0 then obj:setyaw(math.pi) end
|
||||||
|
if bdir.x > 0 then obj:setyaw(1.5 * math.pi) end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -43,7 +43,9 @@ core.register_entity("drawers:visual", {
|
|||||||
drawer_posx = self.drawer_pos.x,
|
drawer_posx = self.drawer_pos.x,
|
||||||
drawer_posy = self.drawer_pos.y,
|
drawer_posy = self.drawer_pos.y,
|
||||||
drawer_posz = self.drawer_pos.z,
|
drawer_posz = self.drawer_pos.z,
|
||||||
texture = self.texture
|
texture = self.texture,
|
||||||
|
drawerType = self.drawerType,
|
||||||
|
visualId = self.visualId
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
|
|
||||||
@ -57,9 +59,13 @@ core.register_entity("drawers:visual", {
|
|||||||
z = data.drawer_posz,
|
z = data.drawer_posz,
|
||||||
}
|
}
|
||||||
self.texture = data.texture
|
self.texture = data.texture
|
||||||
|
self.drawerType = data.drawerType or 1
|
||||||
|
self.visualId = data.visualId or ""
|
||||||
else
|
else
|
||||||
self.drawer_pos = drawers.last_drawer_pos
|
self.drawer_pos = drawers.last_drawer_pos
|
||||||
self.texture = drawers.last_texture or "drawers_empty.png"
|
self.texture = drawers.last_texture or "drawers_empty.png"
|
||||||
|
self.visualId = drawers.last_visual_id
|
||||||
|
self.drawerType = drawers.last_drawer_type
|
||||||
end
|
end
|
||||||
|
|
||||||
-- add self to public drawer visuals
|
-- add self to public drawer visuals
|
||||||
@ -68,7 +74,6 @@ core.register_entity("drawers:visual", {
|
|||||||
-- PLEASE contact me, if this is wrong
|
-- PLEASE contact me, if this is wrong
|
||||||
drawers.drawer_visuals[core.serialize(self.drawer_pos)] = self
|
drawers.drawer_visuals[core.serialize(self.drawer_pos)] = self
|
||||||
|
|
||||||
|
|
||||||
local node = core.get_node(self.drawer_pos)
|
local node = core.get_node(self.drawer_pos)
|
||||||
|
|
||||||
-- collisionbox
|
-- collisionbox
|
||||||
@ -76,23 +81,39 @@ core.register_entity("drawers:visual", {
|
|||||||
if node.param2 == 1 or node.param2 == 3 then
|
if node.param2 == 1 or node.param2 == 3 then
|
||||||
colbox = {0, -0.4374, -0.4374, 0, 0.4374, 0.4374}
|
colbox = {0, -0.4374, -0.4374, 0, 0.4374, 0.4374}
|
||||||
end
|
end
|
||||||
|
-- only half the size if it's a small drawer
|
||||||
|
if self.drawerType >= 2 then
|
||||||
|
for i,j in pairs(colbox) do
|
||||||
|
colbox[i] = j * 0.5
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- visual size
|
||||||
|
local visual_size = {x = 0.6, y = 0.6}
|
||||||
|
if self.drawerType >= 2 then
|
||||||
|
core.chat_send_all("small")
|
||||||
|
visual_size = {x = 0.3, y = 0.3}
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- drawer values
|
-- drawer values
|
||||||
local meta = core.get_meta(self.drawer_pos)
|
local meta = core.get_meta(self.drawer_pos)
|
||||||
self.count = meta:get_int("count")
|
local vid = self.visualId
|
||||||
self.itemName = meta:get_string("name")
|
self.count = meta:get_int("count"..vid)
|
||||||
self.maxCount = meta:get_int("max_count")
|
self.itemName = meta:get_string("name"..vid)
|
||||||
self.itemStackMax = meta:get_int("base_stack_max")
|
self.maxCount = meta:get_int("max_count"..vid)
|
||||||
self.stackMaxFactor = meta:get_int("stack_max_factor")
|
self.itemStackMax = meta:get_int("base_stack_max"..vid)
|
||||||
|
self.stackMaxFactor = meta:get_int("stack_max_factor"..vid)
|
||||||
|
|
||||||
|
|
||||||
-- infotext
|
-- infotext
|
||||||
local infotext = meta:get_string("entity_infotext") .. "\n\n\n\n\n"
|
local infotext = meta:get_string("entity_infotext"..vid) .. "\n\n\n\n\n"
|
||||||
|
|
||||||
self.object:set_properties({
|
self.object:set_properties({
|
||||||
collisionbox = colbox,
|
collisionbox = colbox,
|
||||||
infotext = infotext,
|
infotext = infotext,
|
||||||
textures = {self.texture}
|
textures = {self.texture},
|
||||||
|
visual_size = visual_size
|
||||||
})
|
})
|
||||||
|
|
||||||
-- make entity undestroyable
|
-- make entity undestroyable
|
||||||
@ -129,7 +150,7 @@ core.register_entity("drawers:visual", {
|
|||||||
|
|
||||||
inv:add_item("main", stack)
|
inv:add_item("main", stack)
|
||||||
self.count = self.count - removeCount
|
self.count = self.count - removeCount
|
||||||
meta:set_int("count", self.count)
|
meta:set_int("count"..self.visualId, self.count)
|
||||||
|
|
||||||
-- update infotext
|
-- update infotext
|
||||||
local itemDescription = ""
|
local itemDescription = ""
|
||||||
@ -139,14 +160,14 @@ core.register_entity("drawers:visual", {
|
|||||||
|
|
||||||
if self.count <= 0 then
|
if self.count <= 0 then
|
||||||
self.itemName = ""
|
self.itemName = ""
|
||||||
meta:set_string("name", self.itemName)
|
meta:set_string("name"..self.visualId, self.itemName)
|
||||||
self.texture = "drawers_empty.png"
|
self.texture = "drawers_empty.png"
|
||||||
itemDescription = "Empty"
|
itemDescription = "Empty"
|
||||||
end
|
end
|
||||||
|
|
||||||
local infotext = drawers.gen_info_text(itemDescription,
|
local infotext = drawers.gen_info_text(itemDescription,
|
||||||
self.count, self.stackMaxFactor, self.itemStackMax)
|
self.count, self.stackMaxFactor, self.itemStackMax)
|
||||||
meta:set_string("entity_infotext", infotext)
|
meta:set_string("entity_infotext"..self.visualId, infotext)
|
||||||
|
|
||||||
self.object:set_properties({
|
self.object:set_properties({
|
||||||
infotext = infotext .. "\n\n\n\n\n",
|
infotext = infotext .. "\n\n\n\n\n",
|
||||||
@ -209,7 +230,7 @@ core.register_entity("drawers:visual", {
|
|||||||
end
|
end
|
||||||
local infotext = drawers.gen_info_text(itemDescription,
|
local infotext = drawers.gen_info_text(itemDescription,
|
||||||
self.count, self.stackMaxFactor, self.itemStackMax)
|
self.count, self.stackMaxFactor, self.itemStackMax)
|
||||||
meta:set_string("entity_infotext", infotext)
|
meta:set_string("entity_infotext"..self.visualId, infotext)
|
||||||
|
|
||||||
-- texture
|
-- texture
|
||||||
self.texture = drawers.get_inv_image(self.itemName)
|
self.texture = drawers.get_inv_image(self.itemName)
|
||||||
@ -226,11 +247,11 @@ core.register_entity("drawers:visual", {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
saveMetaData = function(self, meta)
|
saveMetaData = function(self, meta)
|
||||||
meta:set_int("count", self.count)
|
meta:set_int("count"..self.visualId, self.count)
|
||||||
meta:set_string("name", self.itemName)
|
meta:set_string("name"..self.visualId, self.itemName)
|
||||||
meta:set_int("max_count", self.maxCount)
|
meta:set_int("max_count"..self.visualId, self.maxCount)
|
||||||
meta:set_int("base_stack_max", self.itemStackMax)
|
meta:set_int("base_stack_max"..self.visualId, self.itemStackMax)
|
||||||
meta:set_int("stack_max_factor", self.stackMaxFactor)
|
meta:set_int("stack_max_factor"..self.visualId, self.stackMaxFactor)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -239,7 +260,7 @@ core.register_lbm({
|
|||||||
nodenames = {"group:drawer"},
|
nodenames = {"group:drawer"},
|
||||||
run_at_every_load = true,
|
run_at_every_load = true,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
local objs = core.get_objects_inside_radius(pos, 0.5)
|
local objs = core.get_objects_inside_radius(pos, 0.537)
|
||||||
if objs then
|
if objs then
|
||||||
for _, obj in pairs(objs) do
|
for _, obj in pairs(objs) do
|
||||||
if obj and obj:get_luaentity() and
|
if obj and obj:get_luaentity() and
|
||||||
|
Before Width: | Height: | Size: 229 B After Width: | Height: | Size: 229 B |
BIN
textures/drawers_wood_front_4.png
Normal file
BIN
textures/drawers_wood_front_4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 587 B |
Loading…
Reference in New Issue
Block a user