From f3dafb5b6a82255a795972637377320f64c019b9 Mon Sep 17 00:00:00 2001 From: LNJ Date: Mon, 17 Apr 2017 16:04:16 +0200 Subject: [PATCH] Add Drawer Upgrades Yey, they're finally there! :) This will add steel, gold, obsidian and diamond upgrades for MTG and iron, gold, obsidian, diamond and emerald upgrades for MCL2. You can add them to a drawer by rightclicking it and adding them to the new drawer's upgrade inventory. --- LICENSE.txt | 1 + init.lua | 99 +++++++++++++++++- locale/be.po | 55 +++++++--- locale/de.po | 51 ++++++++-- locale/ms.po | 55 +++++++--- locale/template.pot | 46 +++++++-- locale/tr.po | 51 ++++++++-- lua/api.lua | 81 ++++++++++++++- lua/helpers.lua | 44 ++++++++ lua/visual.lua | 140 ++++++++++++++++---------- textures/drawers_upgrade_diamond.png | Bin 0 -> 219 bytes textures/drawers_upgrade_emerald.png | Bin 0 -> 217 bytes textures/drawers_upgrade_gold.png | Bin 0 -> 481 bytes textures/drawers_upgrade_iron.png | Bin 0 -> 217 bytes textures/drawers_upgrade_obsidian.png | Bin 0 -> 217 bytes textures/drawers_upgrade_slot_bg.png | Bin 0 -> 120 bytes textures/drawers_upgrade_steel.png | Bin 0 -> 217 bytes textures/drawers_upgrade_template.png | Bin 0 -> 204 bytes 18 files changed, 512 insertions(+), 111 deletions(-) create mode 100644 textures/drawers_upgrade_diamond.png create mode 100644 textures/drawers_upgrade_emerald.png create mode 100644 textures/drawers_upgrade_gold.png create mode 100644 textures/drawers_upgrade_iron.png create mode 100644 textures/drawers_upgrade_obsidian.png create mode 100644 textures/drawers_upgrade_slot_bg.png create mode 100644 textures/drawers_upgrade_steel.png create mode 100644 textures/drawers_upgrade_template.png 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 ) Everything not listed in here: Copyright (C) 2017 LNJ (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") + -- --- Load files +-- 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 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 \n" "Language-Team: Belarusian =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 \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 " -"\n" +"Last-Translator: Muhammad Nur Hidayat Yasuyoshi \n" "Language-Team: Malay \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 \n" "Language-Team: LANGUAGE \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 \n" "Language-Team: Turkish 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() - -- update infotext - local itemDescription + self:saveMetaData() + + 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 0000000000000000000000000000000000000000..13ecd60f36179cb3339f2ba8abe1ea1733843b46 GIT binary patch literal 219 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!N`Oy@E0AVbGoRt;9yQ9_gs43;k_=P=#evEgOM?7@862M7NCR?GJzX3_DsCkmV4rc} z=Nq4l8VAAT1~vnh)(4ebCI5e~r{OSj?Vow`>Q)?No)x^lXbZ@d Mp00i_>zopr00A;hqW}N^ literal 0 HcmV?d00001 diff --git a/textures/drawers_upgrade_emerald.png b/textures/drawers_upgrade_emerald.png new file mode 100644 index 0000000000000000000000000000000000000000..35fb6ffefd6f0b06257b187d8ecde8c9c0e741ad GIT binary patch literal 217 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!N`Oy@E0EUT>}_YDXn!;*>_vTM zh;eb8WyzaqHA!~!TYR@nh}ttFX>Vj{El?d}NswPKgTu2MX+Tc0r;B4q#jV;ij9ku& zJj@p|uh-nZ^M4-&$~yIB&V#h7jgs{A@9tKWdKxlWgs#(AVGC!ATls9G$1lDIy5pmGczD9Ff}kRJ3!xc00007bV*G` z2i^!90W%rGO6z9;000SaNLh0L01FZT01FZU(%pXi00004XF*Lt006O%3;baP0003v zNklkgWsopA&d37OsG}yrAS)sYR?swKKV0#@7wil#fwY)D z!bKp>|6aTYv%v;@`}T`Ll!uq$$B!Qj92^`Bbs3IeHVB-%!@yu7aUX0e$Q2+O1f+a! zFv1N0xd5aQ1|Gk8jS>bR+g^fMH{pC3V8Nyd<`tOu&I_tw_LW<27OMs^00000NkvXXu0mjf2}i0Z literal 0 HcmV?d00001 diff --git a/textures/drawers_upgrade_iron.png b/textures/drawers_upgrade_iron.png new file mode 100644 index 0000000000000000000000000000000000000000..25c74df5539360a4f32d9dab5ab33e270c91c76b GIT binary patch literal 217 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!N`Oy@E0DG`P|OT5E{?OTNwS;Y z;=6I<#w`<~_RL7yvuDqP_02&v&L{XE<-U-SW50Do<;qo&v37 N@O1TaS?83{1OVGuQ{eyr literal 0 HcmV?d00001 diff --git a/textures/drawers_upgrade_obsidian.png b/textures/drawers_upgrade_obsidian.png new file mode 100644 index 0000000000000000000000000000000000000000..8c241280f7cc4978eb2bc7e53838fe77a5b1c78a GIT binary patch literal 217 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!N`Oy@D@ag4LQX>4Skv3aAk5A{ zF*C%tIL@*r$!>m&@0JNsduAkEdvQM%sE)BD$S;_|;n|HeASc<=#WAGfR_z%^E@wp^ z<_kA#rElN)zmGeOPauLpv47U}{YUQJFZ_CZ66czhU&)RWi_Zx*Ni@At+x`1HtBSXz zprP4{8xKmCFgdJO>|PrbP0l+XkKtTRjg literal 0 HcmV?d00001 diff --git a/textures/drawers_upgrade_slot_bg.png b/textures/drawers_upgrade_slot_bg.png new file mode 100644 index 0000000000000000000000000000000000000000..97bad37d21ce36a9febb04d3ad13056fa2410654 GIT binary patch literal 120 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!D3?x-;bCrM;TYyi9Yj<~dMn*>K_j&`M2xCc* zUoeBivm0qZj)JF)V+eK7=-`; literal 0 HcmV?d00001 diff --git a/textures/drawers_upgrade_steel.png b/textures/drawers_upgrade_steel.png new file mode 100644 index 0000000000000000000000000000000000000000..25c74df5539360a4f32d9dab5ab33e270c91c76b GIT binary patch literal 217 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!N`Oy@E0DG`P|OT5E{?OTNwS;Y z;=6I<#w`<~_RL7yvuDqP_02&v&L{XE<-U-SW50Do<;qo&v37 N@O1TaS?83{1OVGuQ{eyr literal 0 HcmV?d00001 diff --git a/textures/drawers_upgrade_template.png b/textures/drawers_upgrade_template.png new file mode 100644 index 0000000000000000000000000000000000000000..d6cf9b3ec15a065e28b84123725e15b776abcca0 GIT binary patch literal 204 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbL!bbwEYE0DG`P|OT5E{?OTNwS;Y z;=5%+)SekhH*em&{&=SzP@1tM$S;_|;n|HeASd3_#WAGfR%tIIm$M;{Q+@K)JO7Wo z4r(+s