[Mod] Shelf Protector [shelf_protect]

User avatar
everamzah
Member
 
Posts: 490
Joined: Thu Jan 29, 2015 00:47
GitHub: everamzah
IRC: everamzah
In-game: everamzah

[Mod] Shelf Protector [shelf_protect]

by everamzah » Fri Jul 22, 2016 05:57

Depends: default, vessels, protector
Description: Place a Protection Logo in the lock slot of either Vessel or Book Shelf to protect their contents. This will only be effective if the shelf is within an already protected area!
License: WTFPL
Git Repo: https://github.com/everamzah/shelf_protect
Download: shelf_protect.zip
+ Screenshot

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
local bookshelf_formspec =
   "size[8,8]" ..
   default.gui_bg ..
   default.gui_bg_img ..
   default.gui_slots ..
   "list[current_name;books;0,0.3;8,2]" ..
   "list[current_name;protection;3.5,2.5;1,1]" ..
   "list[current_player;main;0,3.85;8,1]" ..
   "list[current_player;main;0,5.08;8,3;8]" ..
   "listring[current_name;books]" ..
   "listring[current_player;main]" ..
   default.get_hotbar_bg(0, 3.85)

minetest.override_item("default:bookshelf", {
   on_construct = function(pos)
      local meta = minetest.get_meta(pos)
      meta:set_string("formspec", bookshelf_formspec)
      local inv = meta:get_inventory()
      inv:set_size("books", 8*2)
      inv:set_size("protection", 1)
   end,
   can_dig = function(pos, player)
      local inv = minetest.get_meta(pos):get_inventory()
      return (inv:is_empty("books") and inv:is_empty("protection"))
   end,
   allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
      local inv = minetest.get_meta(pos):get_inventory()
      if inv:get_stack("protection", 1):get_name() == "protector:protect2" and
            minetest.is_protected(pos, player:get_player_name()) then
         return 0
      end

      if from_list == "books" and to_list == "books" then
         return count
      else
         return 0
      end
   end,
   allow_metadata_inventory_put = function(pos, listname, index, stack, player)
      local inv = minetest.get_meta(pos):get_inventory()
      if listname == "protection" and
            stack:get_name() == "protector:protect2" and
            inv:get_stack("protection", 1):is_empty() and
            not minetest.is_protected(pos, player:get_player_name()) then
         return 1
      end

      if inv:get_stack("protection", 1):get_name() == "protector:protect2" and
            minetest.is_protected(pos, player:get_player_name()) then
         return 0
      end

      if listname == "books" and
            minetest.get_item_group(stack:get_name(), "book") ~= 0 then
         return stack:get_count()
      else
         return 0
      end
   end,
   allow_metadata_inventory_take = function(pos, listname, index, stack, player)
      local inv = minetest.get_meta(pos):get_inventory()
      if inv:get_stack("protection", 1):get_name() == "protector:protect2" and
            minetest.is_protected(pos, player:get_player_name()) then
         return 0
      else
         return stack:get_count()
      end
   end,
})

local vessels_shelf_formspec =
   "size[8,8]" ..
   default.gui_bg ..
   default.gui_bg_img ..
   default.gui_slots ..
   "list[current_name;vessels;0,0.3;8,2]" ..
   "list[current_name;protection;3.5,2.5;1,1]" ..
   "list[current_player;main;0,3.85;8,1]" ..
   "list[current_player;main;0,5.08;8,3;8]" ..
   "listring[current_name;vessels]" ..
   "listring[current_player;main]" ..
   default.get_hotbar_bg(0, 3.85)

minetest.override_item("vessels:shelf", {
   on_construct = function(pos)
      local meta = minetest.get_meta(pos)
      meta:set_string("formspec", vessels_shelf_formspec)
      local inv = meta:get_inventory()
      inv:set_size("vessels", 8*2)
      inv:set_size("protection", 1)
   end,
   can_dig = function(pos,player)
      local inv = minetest.get_meta(pos):get_inventory()
      return (inv:is_empty("vessels") and inv:is_empty("protection"))
   end,
   allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
      local inv = minetest.get_meta(pos):get_inventory()
      if inv:get_stack("protection", 1):get_name() == "protector:protect2" and
            minetest.is_protected(pos, player:get_player_name()) then
         return 0
      end

      if from_list == "vessels" and to_list == "vessels" then
         return count
      else
         return 0
      end
   end,
   allow_metadata_inventory_put = function(pos, listname, index, stack, player)
      local inv = minetest.get_meta(pos):get_inventory()
      if listname == "protection" and
            stack:get_name() == "protector:protect2" and
            inv:get_stack("protection", 1):is_empty() and
            not minetest.is_protected(pos, player:get_player_name()) then
         return 1
      end

      if inv:get_stack("protection", 1):get_name() == "protector:protect2" and
            minetest.is_protected(pos, player:get_player_name()) then
         return 0
      end

      if listname == "vessels" and
            minetest.get_item_group(stack:get_name(), "vessel") ~= 0 then
         return stack:get_count()
      else
         return 0
      end
   end,
   allow_metadata_inventory_take = function(pos, listname, index, stack, player)
      local inv = minetest.get_meta(pos):get_inventory()
      if inv:get_stack("protection", 1):get_name() == "protector:protect2" and
            minetest.is_protected(pos, player:get_player_name()) then
         return 0
      else
         return stack:get_count()
      end
   end,
})
Attachments
shelf_protect.zip
(19.32 KiB) Downloaded 48 times
screenshot_20160722_014937.png
screenshot_20160722_014937.png (69.61 KiB) Viewed 313 times
 

User avatar
DS-minetest
Member
 
Posts: 707
Joined: Thu Jun 19, 2014 19:49
GitHub: DS-Minetest
In-game: DS

Re: [Mod] Shelf Protector [shelf_protect]

by DS-minetest » Fri Jul 22, 2016 11:47

nice idea
Do not call me -minetest.
Call me DS or DS-minetest.
I am German, so you don't have to pm me English if you are also German.
The background is a lie.
 

KCoombes
Member
 
Posts: 278
Joined: Thu Jun 11, 2015 23:19
In-game: Knatt or Rudilyn

Re: [Mod] Shelf Protector [shelf_protect]

by KCoombes » Fri Jul 22, 2016 11:54

+10
 

User avatar
azekill_DIABLO
Member
 
Posts: 3458
Joined: Wed Oct 29, 2014 20:05
GitHub: azekillDIABLO
In-game: azekill_DIABLO

Re: [Mod] Shelf Protector [shelf_protect]

by azekill_DIABLO » Fri Jul 22, 2016 16:46

yes! very nice!
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
Hi, my username is azekill_DIABLO and i'm an exelent bug-maker(yeah...i know...i have a bad reputation)

azekill_DIABLO said: Mineyoshi+ABJ+Baggins= TOPIC HIJACKED.
My Mods and Stuff | Voxellar | VoxBox on GITHUB | M.I.L.A Monster engine
WEIRD MODDING CONTEST !!!
 

Fixerol
Member
 
Posts: 633
Joined: Sun Jul 31, 2011 11:23
IRC: Fixer
In-game: Fixer

Re: [Mod] Shelf Protector [shelf_protect]

by Fixerol » Wed Nov 09, 2016 16:27

 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 16 guests

cron