summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWeblate <noreply@weblate.org>2017-06-03 17:08:53 +0200
committerWeblate <noreply@weblate.org>2017-06-03 17:08:53 +0200
commit37e00f0489567e06a12f8a939bea9b221c08c871 (patch)
treea100f1888144f279092398ec91af41db21140af9
parente994889baae5458d14e8f8af232a90a3637463fd (diff)
parentf3dafb5b6a82255a795972637377320f64c019b9 (diff)
Merge remote-tracking branch 'origin/master'
-rw-r--r--LICENSE.txt1
-rwxr-xr-xinit.lua99
-rw-r--r--locale/be.po55
-rw-r--r--locale/de.po51
-rw-r--r--locale/ms.po55
-rw-r--r--locale/template.pot46
-rw-r--r--locale/tr.po51
-rwxr-xr-xlua/api.lua81
-rwxr-xr-xlua/helpers.lua44
-rwxr-xr-xlua/visual.lua140
-rw-r--r--textures/drawers_upgrade_diamond.pngbin0 -> 219 bytes
-rw-r--r--textures/drawers_upgrade_emerald.pngbin0 -> 217 bytes
-rw-r--r--textures/drawers_upgrade_gold.pngbin0 -> 481 bytes
-rw-r--r--textures/drawers_upgrade_iron.pngbin0 -> 217 bytes
-rw-r--r--textures/drawers_upgrade_obsidian.pngbin0 -> 217 bytes
-rw-r--r--textures/drawers_upgrade_slot_bg.pngbin0 -> 120 bytes
-rw-r--r--textures/drawers_upgrade_steel.pngbin0 -> 217 bytes
-rw-r--r--textures/drawers_upgrade_template.pngbin0 -> 204 bytes
18 files changed, 512 insertions, 111 deletions
diff --git a/LICENSE.txt b/LICENSE.txt
index 8f7c7fd..db86899 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -100,6 +100,7 @@ Copyright (C) 2014 Justin Aquadro (MIT):
textures/drawers_wood_front_2.png
textures/drawers_wood_front_4.png
textures/drawers_wood.png
+ textures/drawers_upgrade_slot_bg.png (extracted from gui/drawers_1.png by LNJ <git@lnj.li>)
Everything not listed in here:
Copyright (C) 2017 LNJ <git@lnj.li> (MIT)
diff --git a/init.lua b/init.lua
index 41da496..2df4b18 100755
--- a/init.lua
+++ b/init.lua
@@ -51,8 +51,17 @@ drawers.enable_1x1 = not core.setting_getbool("drawers_disable_1x1")
drawers.enable_1x2 = not core.setting_getbool("drawers_disable_1x2")
drawers.enable_2x2 = not core.setting_getbool("drawers_disable_2x2")
+
+--
+-- GUI
+--
+
+drawers.gui_bg = "bgcolor[#080808BB;true]"
+drawers.gui_bg_img = "background[5,5;1,1;gui_formbg.png;true]"
+drawers.gui_slots = "listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]"
+
--
--- Load files
+-- Load API
--
dofile(MP .. "/lua/helpers.lua")
@@ -230,3 +239,91 @@ else
})
end
+
+--
+-- Register drawer upgrades
+--
+
+if core.get_modpath("default") and default then
+ drawers.register_drawer_upgrade("drawers:upgrade_steel", {
+ description = S("Steel Drawer Upgrade (x2)"),
+ inventory_image = "drawers_upgrade_steel.png",
+ groups = {drawer_upgrade = 100},
+ recipe_item = "default:steel_ingot"
+ })
+
+ drawers.register_drawer_upgrade("drawers:upgrade_gold", {
+ description = S("Gold Drawer Upgrade (x3)"),
+ inventory_image = "drawers_upgrade_gold.png",
+ groups = {drawer_upgrade = 200},
+ recipe_item = "default:gold_ingot"
+ })
+
+ drawers.register_drawer_upgrade("drawers:upgrade_obsidian", {
+ description = S("Obsidian Drawer Upgrade (x5)"),
+ inventory_image = "drawers_upgrade_obsidian.png",
+ groups = {drawer_upgrade = 400},
+ recipe_item = "default:obsidian"
+ })
+
+ drawers.register_drawer_upgrade("drawers:upgrade_diamond", {
+ description = S("Diamond Drawer Upgrade (x8)"),
+ inventory_image = "drawers_upgrade_diamond.png",
+ groups = {drawer_upgrade = 700},
+ recipe_item = "default:diamond"
+ })
+elseif core.get_modpath("mcl_core") and mcl_core then
+ drawers.register_drawer_upgrade("drawers:upgrade_iron", {
+ description = S("Iron Drawer Upgrade (x2)"),
+ inventory_image = "drawers_upgrade_iron.png",
+ groups = {drawer_upgrade = 100},
+ recipe_item = "mcl_core:iron_ingot"
+ })
+
+ drawers.register_drawer_upgrade("drawers:upgrade_gold", {
+ description = S("Gold Drawer Upgrade (x3)"),
+ inventory_image = "drawers_upgrade_gold.png",
+ groups = {drawer_upgrade = 200},
+ recipe_item = "mcl_core:gold_ingot"
+ })
+
+ drawers.register_drawer_upgrade("drawers:upgrade_obsidian", {
+ description = S("Obsidian Drawer Upgrade (x5)"),
+ inventory_image = "drawers_upgrade_obsidian.png",
+ groups = {drawer_upgrade = 400},
+ recipe_item = "mcl_core:obsidian"
+ })
+
+ drawers.register_drawer_upgrade("drawers:upgrade_diamond", {
+ description = S("Diamond Drawer Upgrade (x8)"),
+ inventory_image = "drawers_upgrade_diamond.png",
+ groups = {drawer_upgrade = 700},
+ recipe_item = "mcl_core:diamond"
+ })
+
+ drawers.register_drawer_upgrade("drawers:upgrade_emerald", {
+ description = S("Emerald Drawer Upgrade (x13)"),
+ inventory_image = "drawers_upgrade_emerald.png",
+ groups = {drawer_upgrade = 1200},
+ recipe_item = "mcl_core:emerald"
+ })
+end
+
+
+--
+-- Register drawer upgrade template
+--
+
+core.register_craftitem("drawers:upgrade_template", {
+ description = S("Drawer Upgrade Template"),
+ inventory_image = "drawers_upgrade_template.png"
+})
+
+core.register_craft({
+ output = "drawers:upgrade_template 4",
+ recipe = {
+ {"group:stick", "group:stick", "group:stick"},
+ {"group:stick", "group:drawer", "group:stick"},
+ {"group:stick", "group:stick", "group:stick"}
+ }
+})
diff --git a/locale/be.po b/locale/be.po
index d7d2ef9..d2bf4c5 100644
--- a/locale/be.po
+++ b/locale/be.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2017-04-14 16:13+0200\n"
+"POT-Creation-Date: 2017-06-03 17:04+0200\n"
"PO-Revision-Date: 2017-05-16 05:35+0000\n"
"Last-Translator: Viktar Vauchkevich <victorenator@gmail.com>\n"
"Language-Team: Belarusian <https://hosted.weblate.org/projects/minetest/mod-"
@@ -16,17 +16,13 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
-"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<="
-"4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
+"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
+"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n"
"X-Generator: Weblate 2.14-dev\n"
-#: lua/helpers.lua
-msgid "@1 (@2% full)"
-msgstr "@1 (@2% поўны)"
-
-#: lua/helpers.lua
-msgid "@1 @2 (@3% full)"
-msgstr "@1 @2 (@3% поўны)"
+#: lua/visual.lua
+msgid "Empty"
+msgstr "Пустая"
#: lua/api.lua init.lua
msgid "Wooden"
@@ -44,9 +40,13 @@ msgstr "@1 шуфляды (1x2)"
msgid "@1 Drawers (2x2)"
msgstr "@1 шуфляды (2x2)"
-#: lua/visual.lua
-msgid "Empty"
-msgstr "Пустая"
+#: lua/helpers.lua
+msgid "@1 (@2% full)"
+msgstr "@1 (@2% поўны)"
+
+#: lua/helpers.lua
+msgid "@1 @2 (@3% full)"
+msgstr "@1 @2 (@3% поўны)"
#: init.lua
msgid "Acacia Wood"
@@ -79,3 +79,32 @@ msgstr "Цёмная драўніна дуба"
#: init.lua
msgid "Spruce Wood"
msgstr "Драўніна яліны"
+
+#: init.lua
+msgid "Steel Drawer Upgrade (x2)"
+msgstr ""
+
+#: init.lua
+msgid "Gold Drawer Upgrade (x3)"
+msgstr ""
+
+#: init.lua
+msgid "Obsidian Drawer Upgrade (x5)"
+msgstr ""
+
+#: init.lua
+msgid "Diamond Drawer Upgrade (x8)"
+msgstr ""
+
+#: init.lua
+#, fuzzy
+msgid "Iron Drawer Upgrade (x2)"
+msgstr "@1 шуфляды (1x2)"
+
+#: init.lua
+msgid "Emerald Drawer Upgrade (x13)"
+msgstr ""
+
+#: init.lua
+msgid "Drawer Upgrade Template"
+msgstr ""
diff --git a/locale/de.po b/locale/de.po
index 1ce2694..96bd5be 100644
--- a/locale/de.po
+++ b/locale/de.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2017-04-14 16:06+0200\n"
+"POT-Creation-Date: 2017-06-03 17:04+0200\n"
"PO-Revision-Date: 2017-04-11 13:04+0200\n"
"Last-Translator: LNJ <git@lnj.li>\n"
"Language-Team: German\n"
@@ -17,13 +17,9 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
-#: lua/helpers.lua
-msgid "@1 (@2% full)"
-msgstr "@1 (@2% voll)"
-
-#: lua/helpers.lua
-msgid "@1 @2 (@3% full)"
-msgstr "@1 @2 (@3% voll)"
+#: lua/visual.lua
+msgid "Empty"
+msgstr "Leer"
#: lua/api.lua init.lua
msgid "Wooden"
@@ -41,9 +37,13 @@ msgstr "@1schubfächer (1x2)"
msgid "@1 Drawers (2x2)"
msgstr "@1schubfächer (2x2)"
-#: lua/visual.lua
-msgid "Empty"
-msgstr "Leer"
+#: lua/helpers.lua
+msgid "@1 (@2% full)"
+msgstr "@1 (@2% voll)"
+
+#: lua/helpers.lua
+msgid "@1 @2 (@3% full)"
+msgstr "@1 @2 (@3% voll)"
#: init.lua
msgid "Acacia Wood"
@@ -76,3 +76,32 @@ msgstr "Dunkeleichenholz"
#: init.lua
msgid "Spruce Wood"
msgstr "Fichtenholz"
+
+#: init.lua
+msgid "Steel Drawer Upgrade (x2)"
+msgstr ""
+
+#: init.lua
+msgid "Gold Drawer Upgrade (x3)"
+msgstr ""
+
+#: init.lua
+msgid "Obsidian Drawer Upgrade (x5)"
+msgstr ""
+
+#: init.lua
+msgid "Diamond Drawer Upgrade (x8)"
+msgstr ""
+
+#: init.lua
+#, fuzzy
+msgid "Iron Drawer Upgrade (x2)"
+msgstr "@1schubfächer (1x2)"
+
+#: init.lua
+msgid "Emerald Drawer Upgrade (x13)"
+msgstr ""
+
+#: init.lua
+msgid "Drawer Upgrade Template"
+msgstr ""
diff --git a/locale/ms.po b/locale/ms.po
index 835daca..0f24094 100644
--- a/locale/ms.po
+++ b/locale/ms.po
@@ -7,10 +7,10 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2017-04-14 16:13+0200\n"
+"POT-Creation-Date: 2017-06-03 17:04+0200\n"
"PO-Revision-Date: 2017-05-19 07:17+0000\n"
-"Last-Translator: Muhammad Nur Hidayat Yasuyoshi <muhdnurhidayat96@yahoo.com>"
-"\n"
+"Last-Translator: Muhammad Nur Hidayat Yasuyoshi <muhdnurhidayat96@yahoo."
+"com>\n"
"Language-Team: Malay <https://hosted.weblate.org/projects/minetest/mod-"
"storage-drawers/ms/>\n"
"Language: ms\n"
@@ -20,13 +20,9 @@ msgstr ""
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Weblate 2.14\n"
-#: lua/helpers.lua
-msgid "@1 (@2% full)"
-msgstr "@1 (@2% penuh)"
-
-#: lua/helpers.lua
-msgid "@1 @2 (@3% full)"
-msgstr "@2 @1 (@3% penuh)"
+#: lua/visual.lua
+msgid "Empty"
+msgstr "Kosong"
#: lua/api.lua init.lua
msgid "Wooden"
@@ -44,9 +40,13 @@ msgstr "Laci @1 (1x2)"
msgid "@1 Drawers (2x2)"
msgstr "Laci @1 (2x2)"
-#: lua/visual.lua
-msgid "Empty"
-msgstr "Kosong"
+#: lua/helpers.lua
+msgid "@1 (@2% full)"
+msgstr "@1 (@2% penuh)"
+
+#: lua/helpers.lua
+msgid "@1 @2 (@3% full)"
+msgstr "@2 @1 (@3% penuh)"
#: init.lua
msgid "Acacia Wood"
@@ -79,3 +79,32 @@ msgstr "Papan Kayu Oak Gelap"
#: init.lua
msgid "Spruce Wood"
msgstr "Papan Kayu Fir"
+
+#: init.lua
+msgid "Steel Drawer Upgrade (x2)"
+msgstr ""
+
+#: init.lua
+msgid "Gold Drawer Upgrade (x3)"
+msgstr ""
+
+#: init.lua
+msgid "Obsidian Drawer Upgrade (x5)"
+msgstr ""
+
+#: init.lua
+msgid "Diamond Drawer Upgrade (x8)"
+msgstr ""
+
+#: init.lua
+#, fuzzy
+msgid "Iron Drawer Upgrade (x2)"
+msgstr "Laci @1 (1x2)"
+
+#: init.lua
+msgid "Emerald Drawer Upgrade (x13)"
+msgstr ""
+
+#: init.lua
+msgid "Drawer Upgrade Template"
+msgstr ""
diff --git a/locale/template.pot b/locale/template.pot
index 1832c9c..05bb0ef 100644
--- a/locale/template.pot
+++ b/locale/template.pot
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2017-04-14 16:13+0200\n"
+"POT-Creation-Date: 2017-06-03 17:04+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -17,12 +17,8 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
-#: lua/helpers.lua
-msgid "@1 (@2% full)"
-msgstr ""
-
-#: lua/helpers.lua
-msgid "@1 @2 (@3% full)"
+#: lua/visual.lua
+msgid "Empty"
msgstr ""
#: lua/api.lua init.lua
@@ -41,8 +37,12 @@ msgstr ""
msgid "@1 Drawers (2x2)"
msgstr ""
-#: lua/visual.lua
-msgid "Empty"
+#: lua/helpers.lua
+msgid "@1 (@2% full)"
+msgstr ""
+
+#: lua/helpers.lua
+msgid "@1 @2 (@3% full)"
msgstr ""
#: init.lua
@@ -76,3 +76,31 @@ msgstr ""
#: init.lua
msgid "Spruce Wood"
msgstr ""
+
+#: init.lua
+msgid "Steel Drawer Upgrade (x2)"
+msgstr ""
+
+#: init.lua
+msgid "Gold Drawer Upgrade (x3)"
+msgstr ""
+
+#: init.lua
+msgid "Obsidian Drawer Upgrade (x5)"
+msgstr ""
+
+#: init.lua
+msgid "Diamond Drawer Upgrade (x8)"
+msgstr ""
+
+#: init.lua
+msgid "Iron Drawer Upgrade (x2)"
+msgstr ""
+
+#: init.lua
+msgid "Emerald Drawer Upgrade (x13)"
+msgstr ""
+
+#: init.lua
+msgid "Drawer Upgrade Template"
+msgstr ""
diff --git a/locale/tr.po b/locale/tr.po
index 71c969f..e095a6e 100644
--- a/locale/tr.po
+++ b/locale/tr.po
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2017-04-14 16:13+0200\n"
+"POT-Creation-Date: 2017-06-03 17:04+0200\n"
"PO-Revision-Date: 2017-05-16 22:41+0000\n"
"Last-Translator: monolifed <monolifed@gmail.com>\n"
"Language-Team: Turkish <https://hosted.weblate.org/projects/minetest/mod-"
@@ -19,13 +19,9 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=n > 1;\n"
"X-Generator: Weblate 2.14-dev\n"
-#: lua/helpers.lua
-msgid "@1 (@2% full)"
-msgstr "@1 (%@2 dolu)"
-
-#: lua/helpers.lua
-msgid "@1 @2 (@3% full)"
-msgstr "@1 @2 (%@3 dolu)"
+#: lua/visual.lua
+msgid "Empty"
+msgstr "Boş"
#: lua/api.lua init.lua
msgid "Wooden"
@@ -43,9 +39,13 @@ msgstr "@1 Çekmece (1x2)"
msgid "@1 Drawers (2x2)"
msgstr "@1 Çekmece (2x2)"
-#: lua/visual.lua
-msgid "Empty"
-msgstr "Boş"
+#: lua/helpers.lua
+msgid "@1 (@2% full)"
+msgstr "@1 (%@2 dolu)"
+
+#: lua/helpers.lua
+msgid "@1 @2 (@3% full)"
+msgstr "@1 @2 (%@3 dolu)"
#: init.lua
msgid "Acacia Wood"
@@ -78,3 +78,32 @@ msgstr "Koyu Meşe Ahşap"
#: init.lua
msgid "Spruce Wood"
msgstr "Ladin Ahşap"
+
+#: init.lua
+msgid "Steel Drawer Upgrade (x2)"
+msgstr ""
+
+#: init.lua
+msgid "Gold Drawer Upgrade (x3)"
+msgstr ""
+
+#: init.lua
+msgid "Obsidian Drawer Upgrade (x5)"
+msgstr ""
+
+#: init.lua
+msgid "Diamond Drawer Upgrade (x8)"
+msgstr ""
+
+#: init.lua
+#, fuzzy
+msgid "Iron Drawer Upgrade (x2)"
+msgstr "@1 Çekmece (1x2)"
+
+#: init.lua
+msgid "Emerald Drawer Upgrade (x13)"
+msgstr ""
+
+#: init.lua
+msgid "Drawer Upgrade Template"
+msgstr ""
diff --git a/lua/api.lua b/lua/api.lua
index 9d54f53..736a8fb 100755
--- a/lua/api.lua
+++ b/lua/api.lua
@@ -37,6 +37,14 @@ drawers.node_box_simple = {
{-0.4375, -0.5, -0.5, 0.4375, -0.4375, -0.4375},
}
+drawers.drawer_formspec = "size[9,7]" ..
+ "list[context;upgrades;2,0.5;5,1;]" ..
+ "list[current_player;main;0,3;9,4;]" ..
+ drawers.gui_bg ..
+ drawers.gui_bg_img ..
+ drawers.gui_slots ..
+ drawers.get_upgrade_slots_bg(2, 0.5)
+
-- construct drawer
function drawers.drawer_on_construct(pos)
local node = core.get_node(pos)
@@ -66,7 +74,14 @@ function drawers.drawer_on_construct(pos)
i = i + 1
end
+ -- spawn all visuals
drawers.spawn_visuals(pos)
+
+ -- create drawer upgrade inventory
+ meta:get_inventory():set_size("upgrades", 5)
+
+ -- set the formspec
+ meta:set_string("formspec", drawers.drawer_formspec)
end
-- destruct drawer
@@ -113,17 +128,55 @@ function drawers.drawer_on_dig(pos, node, player)
k = k + 1
end
+ -- drop all drawer upgrades
+ local upgrades = meta:get_inventory():get_list("upgrades")
+ if upgrades then
+ for _,itemStack in pairs(upgrades) do
+ if itemStack:get_count() > 0 then
+ local rndpos = drawers.randomize_pos(pos)
+ core.add_item(rndpos, itemStack:get_name())
+ end
+ end
+ end
+
-- remove node
core.node_dig(pos, node, player)
end
+function drawers.drawer_allow_metadata_inventory_put(pos, listname, index, stack, player)
+ if listname ~= "upgrades" then
+ return 0
+ end
+ if stack:get_count() > 1 then
+ return 0
+ end
+ if core.get_item_group(stack:get_name(), "drawer_upgrade") < 1 then
+ return 0
+ end
+ return 1
+end
+
+function drawers.add_drawer_upgrade(pos, listname, index, stack, player)
+ -- only do anything if adding to upgrades
+ if listname ~= "upgrades" then return end
+
+ drawers.update_drawer_upgrades(pos)
+end
+
+function drawers.remove_drawer_upgrade(pos, listname, index, stack, player)
+ -- only do anything if adding to upgrades
+ if listname ~= "upgrades" then return end
+
+ drawers.update_drawer_upgrades(pos)
+end
+
function drawers.drawer_insert_object(pos, node, stack, direction)
local drawer_visuals = drawers.drawer_visuals[core.serialize(pos)]
if not drawer_visuals then return stack end
local leftover = stack
for _, visual in pairs(drawer_visuals) do
- leftover = visual.try_insert_stack(visual, leftover, true)
+ leftover = visual:try_insert_stack(leftover, true)
end
return leftover
end
@@ -144,6 +197,9 @@ function drawers.register_drawer(name, def)
def.on_construct = drawers.drawer_on_construct
def.on_destruct = drawers.drawer_on_destruct
def.on_dig = drawers.drawer_on_dig
+ def.allow_metadata_inventory_put = drawers.drawer_allow_metadata_inventory_put
+ def.on_metadata_inventory_put = drawers.add_drawer_upgrade
+ def.on_metadata_inventory_take = drawers.remove_drawer_upgrade
if minetest.get_modpath("screwdriver") and screwdriver then
def.on_rotate = def.on_rotate or screwdriver.disallow
@@ -231,3 +287,26 @@ function drawers.register_drawer(name, def)
end
end
end
+
+function drawers.register_drawer_upgrade(name, def)
+ def.groups = def.groups or {}
+ def.groups.drawer_upgrade = def.groups.drawer_upgrade or 100
+ def.inventory_image = def.inventory_image or "drawers_upgrade_template.png"
+ def.stack_max = 1
+
+ local recipe_item = def.recipe_item or "air"
+ def.recipe_item = nil
+
+ core.register_craftitem(name, def)
+
+ if not def.no_craft then
+ core.register_craft({
+ output = name,
+ recipe = {
+ {recipe_item, "group:stick", recipe_item},
+ {"group:stick", "drawers:upgrade_template", "group:stick"},
+ {recipe_item, "group:stick", recipe_item}
+ }
+ })
+ end
+end
diff --git a/lua/helpers.lua b/lua/helpers.lua
index 89785a8..04ea38d 100755
--- a/lua/helpers.lua
+++ b/lua/helpers.lua
@@ -29,6 +29,15 @@ SOFTWARE.
local MP = core.get_modpath(core.get_current_modname())
local S, NS = dofile(MP.."/intllib.lua")
+-- GUI
+function drawers.get_upgrade_slots_bg(x,y)
+ local out = ""
+ for i = 0, 4, 1 do
+ out = out .."image["..x+i..","..y..";1,1;drawers_upgrade_slot_bg.png]"
+ end
+ return out
+end
+
function drawers.gen_info_text(basename, count, factor, stack_max)
local maxCount = stack_max * factor
local percent = count / maxCount * 100
@@ -199,6 +208,41 @@ function drawers.remove_visuals(pos)
end
end
+function drawers.update_drawer_upgrades(pos)
+ local node = core.get_node(pos)
+ local ndef = core.registered_nodes[node.name]
+ local drawerType = ndef.groups.drawer
+
+ -- default number of slots/stacks
+ local stackMaxFactor = ndef.drawer_stack_max_factor
+
+ -- storage percent with all upgrades
+ local storagePercent = 100
+
+ -- get info of all upgrades
+ local inventory = core.get_meta(pos):get_inventory():get_list("upgrades")
+ for _,itemStack in pairs(inventory) do
+ local iname = itemStack:get_name()
+ local idef = core.registered_items[iname]
+ local addPercent = idef.groups.drawer_upgrade or 0
+
+ storagePercent = storagePercent + addPercent
+ end
+
+ -- i.e.: 150% / 100 => 1.50
+ stackMaxFactor = math.floor(stackMaxFactor * (storagePercent / 100))
+ -- calculate stack_max factor for a single drawer
+ stackMaxFactor = stackMaxFactor / drawerType
+
+ -- set the new stack max factor in all visuals
+ local drawer_visuals = drawers.drawer_visuals[core.serialize(pos)]
+ if not drawer_visuals then return end
+
+ for _,visual in pairs(drawer_visuals) do
+ visual:setStackMaxFactor(stackMaxFactor)
+ end
+end
+
function drawers.randomize_pos(pos)
local rndpos = table.copy(pos)
local x = math.random(-50, 50) * 0.01
diff --git a/lua/visual.lua b/lua/visual.lua
index 5098a63..3287f65 100755
--- a/lua/visual.lua
+++ b/lua/visual.lua
@@ -90,10 +90,11 @@ core.register_entity("drawers:visual", {
drawers.drawer_visuals[posstr][vId] = self
end
-
- local node = core.get_node(self.drawer_pos)
+ -- get meta
+ self.meta = core.get_meta(self.drawer_pos)
-- collisionbox
+ local node = core.get_node(self.drawer_pos)
local colbox
if self.drawerType ~= 2 then
if node.param2 == 1 or node.param2 == 3 then
@@ -123,17 +124,16 @@ core.register_entity("drawers:visual", {
-- drawer values
- local meta = core.get_meta(self.drawer_pos)
local vid = self.visualId
- self.count = meta:get_int("count"..vid)
- self.itemName = meta:get_string("name"..vid)
- self.maxCount = meta:get_int("max_count"..vid)
- self.itemStackMax = meta:get_int("base_stack_max"..vid)
- self.stackMaxFactor = meta:get_int("stack_max_factor"..vid)
+ 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)
-- infotext
- local infotext = meta:get_string("entity_infotext"..vid) .. "\n\n\n\n\n"
+ local infotext = self.meta:get_string("entity_infotext"..vid) .. "\n\n\n\n\n"
self.object:set_properties({
collisionbox = colbox,
@@ -200,35 +200,10 @@ core.register_entity("drawers:visual", {
-- update the drawer count
self.count = self.count - removeCount
- -- clean up drawer, if empty
- if self.count <= 0 then
- self.itemName = ""
- meta:set_string("name"..self.visualId, self.itemName)
- self.texture = "blank.png"
- end
-
-
- -- build info
- local itemDescription = ""
- if self.count <= 0 then
- itemDescription = S("Empty")
- elseif core.registered_items[self.itemName] then
- itemDescription = core.registered_items[self.itemName].description
- end
-
- local infotext = drawers.gen_info_text(itemDescription,
- self.count, self.stackMaxFactor, self.itemStackMax)
-
- -- set new infotext and texture
- self.object:set_properties({
- infotext = infotext .. "\n\n\n\n\n",
- textures = {self.texture}
- })
-
- -- save everything to meta
- meta:set_string("entity_infotext"..self.visualId, infotext)
- meta:set_int("count"..self.visualId, self.count)
+ self:updateInfotext()
+ self:updateTexture()
+ self:saveMetaData()
-- return the stack that was removed from the drawer
return stack
@@ -277,32 +252,93 @@ core.register_entity("drawers:visual", {
itemstack:set_count(itemstack:get_count() - stackCount)
end
- -- get meta
- local meta = core.get_meta(self.drawer_pos)
+ -- update infotext, texture
+ self:updateInfotext()
+ self:updateTexture()
+
+ self:saveMetaData()
- -- update infotext
- local itemDescription
+ if itemstack:get_count() == 0 then itemstack = ItemStack("") end
+ return itemstack
+ end,
+
+ updateInfotext = function(self)
+ local itemDescription = ""
if core.registered_items[self.itemName] then
itemDescription = core.registered_items[self.itemName].description
- else
+ end
+
+ if self.count <= 0 then
+ self.itemName = ""
+ self.meta:set_string("name"..self.visualId, self.itemName)
+ self.texture = "blank.png"
itemDescription = S("Empty")
end
+
local infotext = drawers.gen_info_text(itemDescription,
self.count, self.stackMaxFactor, self.itemStackMax)
- meta:set_string("entity_infotext"..self.visualId, infotext)
+ self.meta:set_string("entity_infotext"..self.visualId, infotext)
+ self.object:set_properties({
+ infotext = infotext .. "\n\n\n\n\n"
+ })
+ end,
+
+ updateTexture = function(self)
-- texture
self.texture = drawers.get_inv_image(self.itemName)
self.object:set_properties({
- infotext = infotext .. "\n\n\n\n\n",
textures = {self.texture}
})
+ end,
- self.saveMetaData(self, meta)
+ 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
+ dropPos = self.pos
+ dropPos.y = dropPos.y + 1
+ end
+ -- drop the item stack
+ core.item_drop(itemStack, nil, dropPos)
+ end,
- if itemstack:get_count() == 0 then itemstack = ItemStack("") end
- return itemstack
+ 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()
end,
play_interact_sound = function(self)
@@ -314,11 +350,11 @@ core.register_entity("drawers:visual", {
end,
saveMetaData = function(self, meta)
- meta:set_int("count"..self.visualId, self.count)
- meta:set_string("name"..self.visualId, self.itemName)
- meta:set_int("max_count"..self.visualId, self.maxCount)
- meta:set_int("base_stack_max"..self.visualId, self.itemStackMax)
- meta:set_int("stack_max_factor"..self.visualId, self.stackMaxFactor)
+ 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)
end
})
diff --git a/textures/drawers_upgrade_diamond.png b/textures/drawers_upgrade_diamond.png
new file mode 100644
index 0000000..13ecd60
--- /dev/null
+++ b/textures/drawers_upgrade_diamond.png
Binary files differ
diff --git a/textures/drawers_upgrade_emerald.png b/textures/drawers_upgrade_emerald.png
new file mode 100644
index 0000000..35fb6ff
--- /dev/null
+++ b/textures/drawers_upgrade_emerald.png
Binary files differ
diff --git a/textures/drawers_upgrade_gold.png b/textures/drawers_upgrade_gold.png
new file mode 100644
index 0000000..be74af0
--- /dev/null
+++ b/textures/drawers_upgrade_gold.png
Binary files differ
diff --git a/textures/drawers_upgrade_iron.png b/textures/drawers_upgrade_iron.png
new file mode 100644
index 0000000..25c74df
--- /dev/null
+++ b/textures/drawers_upgrade_iron.png
Binary files differ
diff --git a/textures/drawers_upgrade_obsidian.png b/textures/drawers_upgrade_obsidian.png
new file mode 100644
index 0000000..8c24128
--- /dev/null
+++ b/textures/drawers_upgrade_obsidian.png
Binary files differ
diff --git a/textures/drawers_upgrade_slot_bg.png b/textures/drawers_upgrade_slot_bg.png
new file mode 100644
index 0000000..97bad37
--- /dev/null
+++ b/textures/drawers_upgrade_slot_bg.png
Binary files differ
diff --git a/textures/drawers_upgrade_steel.png b/textures/drawers_upgrade_steel.png
new file mode 100644
index 0000000..25c74df
--- /dev/null
+++ b/textures/drawers_upgrade_steel.png
Binary files differ
diff --git a/textures/drawers_upgrade_template.png b/textures/drawers_upgrade_template.png
new file mode 100644
index 0000000..d6cf9b3
--- /dev/null
+++ b/textures/drawers_upgrade_template.png
Binary files differ