summaryrefslogtreecommitdiff
path: root/lua/helpers.lua
diff options
context:
space:
mode:
authorLNJ <git@lnj.li>2017-04-17 16:04:16 +0200
committerLNJ <git@lnj.li>2017-06-03 17:06:12 +0200
commitf3dafb5b6a82255a795972637377320f64c019b9 (patch)
treecb47078e207b244f8427a4dd54f429417c45ee12 /lua/helpers.lua
parent1f0fdf832b5a24ee80df01b0f08a0902bad8e978 (diff)
Add Drawer Upgradesorigin/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.
Diffstat (limited to 'lua/helpers.lua')
-rwxr-xr-xlua/helpers.lua44
1 files changed, 44 insertions, 0 deletions
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