Skip to content

Commit

Permalink
Enable protection using for taking/putting items on shelves.
Browse files Browse the repository at this point in the history
Add crafting recipes.
Add shelves in all  wood varieties.
Update mod.conf for ContentDB.
Update README
  • Loading branch information
hkzorman committed Apr 17, 2022
1 parent f8776ff commit 66a41df
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 112 deletions.
33 changes: 23 additions & 10 deletions api.lua
Expand Up @@ -181,16 +181,29 @@ function itemshelf.register_shelf(name, def)
meta:set_float("itemshelf:depth_displacement", def.depth_offset)
end
end,
-- allow_metadata_inventory_put = function(pos, listname, index, stack, player)
-- if minetest.get_item_group(stack:get_name(), "music_disc") ~= 0 then
-- return stack:get_count()
-- end
-- return 0
-- end,
allow_metadata_inventory_move = function(pos, from_list, from_index,
to_list, to_index, count, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
return count
end,
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
return stack:get_count()
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if minetest.is_protected(pos, player:get_player_name()) then
return 0
end
return stack:get_count()
end,
on_metadata_inventory_put = update_shelf,
on_metadata_inventory_take = update_shelf,
on_dig = function(pos, node, digger)
-- Clear any object disc
-- Clear all object objects
local objs = minetest.get_objects_inside_radius(pos, 0.7)
for _,obj in pairs(objs) do
obj:remove()
Expand Down Expand Up @@ -236,7 +249,7 @@ function itemshelf.register_shelf(name, def)
})
end

-- Entity for shelf
-- Entity for item displayed on shelf
minetest.register_entity("itemshelf:item", {
hp_max = 1,
visual = "wielditem",
Expand Down Expand Up @@ -265,7 +278,7 @@ minetest.register_entity("itemshelf:item", {
if self.itemstring ~= nil then
self.wield_item = self.itemstring
end

-- Visual size
if temp_size ~= nil then
self.visualsize = temp_size
Expand All @@ -280,7 +293,7 @@ minetest.register_entity("itemshelf:item", {

-- Set object properties
self.object:set_properties(self)

end,
get_staticdata = function(self)
local result = ""
Expand Down
5 changes: 4 additions & 1 deletion mod.conf
@@ -1,3 +1,6 @@
autor = zorman2000
name = itemshelf
depends = default
description = The item shelf mod is a simple mod that adds to shelves that can hold up to 4 or 6 items.
depends = default
release = 1
title = Item Shelves
254 changes: 161 additions & 93 deletions nodes.lua
Expand Up @@ -36,96 +36,164 @@ local default_half_shelf_open = {
}
}

itemshelf.register_shelf("small_shelf", {
description = "Shelf (4)",
textures = {
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png"
},
nodebox = default_shelf,
capacity = 4,
shown_items = 4
})

itemshelf.register_shelf("large_shelf", {
description = "Shelf (6)",
textures = {
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png"
},
nodebox = default_shelf,
capacity = 6,
shown_items = 6
})

itemshelf.register_shelf("half_depth_shelf_small", {
description = "Half Shelf (4)",
textures = {
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png"
},
nodebox = default_half_shelf,
capacity = 4,
shown_items = 4,
half_depth = true,
})

itemshelf.register_shelf("half_depth_shelf_large", {
description = "Half Shelf (6)",
textures = {
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png"
},
nodebox = default_half_shelf,
capacity = 6,
shown_items = 6,
half_depth = true,
})

itemshelf.register_shelf("half_depth_open_shelf", {
description = "Half Open-Back Shelf (4)",
textures = {
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png"
},
nodebox = default_half_shelf_open,
capacity = 4,
shown_items = 4,
half_depth = true,
})

itemshelf.register_shelf("half_depth_open_shelf", {
description = "Half Open-Back Shelf (6)",
textures = {
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png",
"default_wood.png"
},
nodebox = default_half_shelf_open,
capacity = 6,
shown_items = 6,
half_depth = true,
})
local function register_node_and_recipe(item_name, material_name, display_prefix, texture)
-- Backwards compatibility to keep existing node names same
if material_name ~= "" then material_name = material_name.."_" end

itemshelf.register_shelf(material_name.."small_shelf", {
description = display_prefix.." Shelf (4)",
textures = {
texture,
texture,
texture,
texture,
texture,
texture
},
nodebox = default_shelf,
capacity = 4,
shown_items = 4
})

minetest.register_craft({
output = "itemshelf:"..material_name.."small_shelf",
recipe = {
{item_name, item_name, item_name},
{"", "", ""},
{item_name, item_name, item_name},
}
})

itemshelf.register_shelf(material_name.."large_shelf", {
description = display_prefix.." Shelf (6)",
textures = {
texture,
texture,
texture,
texture,
texture,
texture
},
nodebox = default_shelf,
capacity = 6,
shown_items = 6
})

minetest.register_craft({
output = "itemshelf:"..material_name.."large_shelf",
recipe = {
{item_name, item_name, item_name},
{item_name, "", item_name},
{item_name, item_name, item_name},
}
})

itemshelf.register_shelf(material_name.."half_depth_shelf_small", {
description = display_prefix.." Half Shelf (4)",
textures = {
texture,
texture,
texture,
texture,
texture,
texture
},
nodebox = default_half_shelf,
capacity = 4,
shown_items = 4,
half_depth = true,
})

minetest.register_craft({
output = "itemshelf:"..material_name.."half_depth_shelf_small",
recipe = {
{item_name, item_name, ""},
{"", "", ""},
{item_name, item_name, ""},
}
})

itemshelf.register_shelf(material_name.."half_depth_shelf_large", {
description = display_prefix.." Half Shelf (6)",
textures = {
texture,
texture,
texture,
texture,
texture,
texture
},
nodebox = default_half_shelf,
capacity = 6,
shown_items = 6,
half_depth = true,
})

minetest.register_craft({
output = "itemshelf:"..material_name.."half_depth_shelf_large",
recipe = {
{item_name, item_name, ""},
{item_name, "", ""},
{item_name, item_name, ""},
}
})

-- Half-depth open-back shelf, 4 items
itemshelf.register_shelf(material_name.."half_depth_open_shelf", {
description = display_prefix.." Half Open-Back Shelf (4)",
textures = {
texture,
texture,
texture,
texture,
texture,
texture
},
nodebox = default_half_shelf_open,
capacity = 4,
shown_items = 4,
half_depth = true,
})

minetest.register_craft({
output = "itemshelf:"..material_name.."half_depth_open_shelf",
recipe = {
{item_name, "", item_name},
{"", "", ""},
{item_name, "", item_name},
}
})

-- Half-depth open-back shelf, 6 items
itemshelf.register_shelf(material_name.."half_depth_open_shelf_large", {
description = display_prefix.." Half Open-Back Shelf (6)",
textures = {
texture,
texture,
texture,
texture,
texture,
texture
},
nodebox = default_half_shelf_open,
capacity = 6,
shown_items = 6,
half_depth = true,
})

minetest.register_craft({
output = "itemshelf:"..material_name.."half_depth_open_shelf_large",
recipe = {
{item_name, "", item_name},
{"", item_name, ""},
{item_name, "", item_name},
}
})
end

-- Register nodes and recipes on all minetest_game wood types
register_node_and_recipe("default:wood", "", "Apple Wood", "default_wood.png")
register_node_and_recipe("default:pine_wood", "pine", "Pine Wood", "default_pine_wood.png")
register_node_and_recipe("default:aspen_wood", "aspen", "Aspen Wood", "default_aspen_wood.png")
register_node_and_recipe("default:acacia_wood", "acacia", "Acacia Wood", "default_acacia_wood.png")
register_node_and_recipe("default:junglewood", "jungle", "Jungle Wood", "default_junglewood.png")
23 changes: 15 additions & 8 deletions readme.md
@@ -1,13 +1,17 @@
Itemshelf
=========


[![ContentDB](https://content.minetest.net/packages/zorman2000/itemshelf/downloads/)](https://content.minetest.net/packages/zorman2000/itemshelf/)
[![ContentDB](https://content.minetest.net/packages/zorman2000/itemshelf/shields/downloads/)](https://content.minetest.net/packages/zorman2000/itemshelf/)

The item shelf mod is a simple mod that adds to shelves that can hold up to 4 or 6 items. This small limitation is due to the fact that shelves show the items they are holding using entities. The entities are purely static and consume 0 CPU (like the ones in itemframes for example), but still the limitation is to avoid lag.

There are no crafting recipes at the moment. To get an item shelf, play on `creative` or use:
`/giveme itemshelf:small_shelf` or `/giveme itemshelf:large_shelf`. Both shelves are of the same size, however they can hold 4 or 6 items respectively.
Shelves should work with protection mods (currently only tested with `areas` mod). Without any protection they are public, otherwise they obey the proection of the area

There are three different types of shelves, and all three come in two different flavors: holding 4 or 6 items.
- Shelf: like a bookshelf, one cube wide
- Half shelf: while not exactly half a cube, it is less deep
- Half open shelf: like the above, but with no back


Developers
----------
Expand All @@ -29,8 +33,11 @@ All code is copyright (C) 2018 Hector Franqui (zorman2000), licensed under the M

Roadmap
-------
- Add shelves in all varieties of woods
- Add crafting recipe
- Add sounds when placing items
- ~~Add shelves in all varieties of woods~~
- ~~Add crafting recipe~~
- Add sounds
- Allow shelves to contain only specific items
- Allow overlays if shelf holds specific items
- Allow overlays if shelf holds specific items


![Preview](https://github.com/hkzorman/itemshelf/screenshot.png)
Binary file added screenshot.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 66a41df

Please sign in to comment.