From f3dafb5b6a82255a795972637377320f64c019b9 Mon Sep 17 00:00:00 2001 From: LNJ Date: Mon, 17 Apr 2017 16:04:16 +0200 Subject: 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. --- lua/helpers.lua | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'lua/helpers.lua') 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 -- cgit v1.2.3