summaryrefslogtreecommitdiff
path: root/unified_inventory/api.lua
diff options
context:
space:
mode:
authorVanessa Ezekowitz <vanessaezekowitz@gmail.com>2016-08-11 18:39:55 -0400
committerVanessa Ezekowitz <vanessaezekowitz@gmail.com>2016-08-11 18:39:55 -0400
commit92f49e3096dc37b9b802994d287c47dc7f583c24 (patch)
tree9480515a27630d8009dffb87de93124966fb1015 /unified_inventory/api.lua
parentf9cae7314e08fbeeef509c5c6ca095822fec1747 (diff)
downloaddreambuilder_modpack-92f49e3096dc37b9b802994d287c47dc7f583c24.tar
dreambuilder_modpack-92f49e3096dc37b9b802994d287c47dc7f583c24.tar.gz
dreambuilder_modpack-92f49e3096dc37b9b802994d287c47dc7f583c24.tar.bz2
dreambuilder_modpack-92f49e3096dc37b9b802994d287c47dc7f583c24.tar.xz
dreambuilder_modpack-92f49e3096dc37b9b802994d287c47dc7f583c24.zip
updated boost_cart, plantlife, castle, homedecor, fake_fire,
glooptest, quartz, unified_inventory, inbox, mesecons, and worldedit mods
Diffstat (limited to 'unified_inventory/api.lua')
-rw-r--r--unified_inventory/api.lua87
1 files changed, 83 insertions, 4 deletions
diff --git a/unified_inventory/api.lua b/unified_inventory/api.lua
index 872ce32..936ee72 100644
--- a/unified_inventory/api.lua
+++ b/unified_inventory/api.lua
@@ -1,4 +1,5 @@
local S = unified_inventory.gettext
+local F = unified_inventory.fgettext
-- Create detached creative inventory after loading all mods
minetest.after(0.01, function()
@@ -44,6 +45,7 @@ minetest.after(0.01, function()
print("Unified Inventory. inventory size: "..unified_inventory.items_list_size)
for _, name in ipairs(unified_inventory.items_list) do
local def = minetest.registered_items[name]
+ -- Simple drops
if type(def.drop) == "string" then
local dstack = ItemStack(def.drop)
if not dstack:is_empty() and dstack:get_name() ~= name then
@@ -55,6 +57,77 @@ minetest.after(0.01, function()
})
end
+ -- Complex drops. Yes, it's really complex!
+ elseif type(def.drop) == "table" then
+ --[[ Extract single items from the table and save them into dedicated tables
+ to register them later, in order to avoid duplicates. These tables counts
+ the total number of guaranteed drops and drops by chance (“maybes”) for each item.
+ For “maybes”, the final count is the theoretical maximum number of items, not
+ neccessarily the actual drop count. ]]
+ local drop_guaranteed = {}
+ local drop_maybe = {}
+ -- This is for catching an obscure corner case: If the top items table has
+ -- only items with rarity = 1, but max_items is set, then only the first
+ -- max_items will be part of the drop, any later entries are logically
+ -- impossible, so this variable is for keeping track of this
+ local max_items_left = def.drop.max_items
+ -- For checking whether we still encountered only guaranteed only so far;
+ -- for the first “maybe” item it will become false which will cause ALL
+ -- later items to be considered “maybes”.
+ -- A common idiom is:
+ -- { max_items 1, { items = {
+ -- { items={"example:1"}, rarity = 5 },
+ -- { items={"example:2"}, rarity = 1 }, }}}
+ -- example:2 must be considered a “maybe” because max_items is set and it
+ -- appears after a “maybe”
+ local max_start = true
+ -- Let's iterate through the items madness!
+ for i=1,#def.drop.items do
+ if max_items_left ~= nil and max_items_left <= 0 then break end
+ local itit = def.drop.items[i]
+ for j=1,#itit.items do
+ local dstack = ItemStack(itit.items[j])
+ if not dstack:is_empty() and dstack:get_name() ~= name then
+ local dname = dstack:get_name()
+ local dcount = dstack:get_count()
+ -- Guaranteed drops AND we are not yet in “maybe mode”
+ if #itit.items == 1 and itit.rarity == 1 and max_start then
+ if drop_guaranteed[dname] == nil then
+ drop_guaranteed[dname] = 0
+ end
+ drop_guaranteed[dname] = drop_guaranteed[dname] + dcount
+
+ if max_items_left ~= nil then
+ max_items_left = max_items_left - 1
+ if max_items_left <= 0 then break end
+ end
+ -- Drop was a “maybe”
+ else
+ if max_items_left ~= nil then max_start = false end
+ if drop_maybe[dname] == nil then
+ drop_maybe[dname] = 0
+ end
+ drop_maybe[dname] = drop_maybe[dname] + dcount
+ end
+ end
+ end
+ end
+ for itemstring, count in pairs(drop_guaranteed) do
+ unified_inventory.register_craft({
+ type = "digging",
+ items = {name},
+ output = itemstring .. " " .. count,
+ width = 0,
+ })
+ end
+ for itemstring, count in pairs(drop_maybe) do
+ unified_inventory.register_craft({
+ type = "digging_chance",
+ items = {name},
+ output = itemstring .. " " .. count,
+ width = 0,
+ })
+ end
end
end
for _, recipes in pairs(unified_inventory.crafts_for.recipe) do
@@ -158,7 +231,7 @@ end
unified_inventory.register_craft_type("normal", {
- description = "Crafting",
+ description = F("Crafting"),
icon = "ui_craftgrid_icon.png",
width = 3,
height = 3,
@@ -174,7 +247,7 @@ unified_inventory.register_craft_type("normal", {
unified_inventory.register_craft_type("shapeless", {
- description = "Mixing",
+ description = F("Mixing"),
icon = "ui_craftgrid_icon.png",
width = 3,
height = 3,
@@ -189,7 +262,7 @@ unified_inventory.register_craft_type("shapeless", {
unified_inventory.register_craft_type("cooking", {
- description = "Cooking",
+ description = F("Cooking"),
icon = "default_furnace_front.png",
width = 1,
height = 1,
@@ -197,12 +270,18 @@ unified_inventory.register_craft_type("cooking", {
unified_inventory.register_craft_type("digging", {
- description = "Digging",
+ description = F("Digging"),
icon = "default_tool_steelpick.png",
width = 1,
height = 1,
})
+unified_inventory.register_craft_type("digging_chance", {
+ description = "Digging (by chance)",
+ icon = "default_tool_steelpick.png^[transformFY.png",
+ width = 1,
+ height = 1,
+})
function unified_inventory.register_page(name, def)
unified_inventory.pages[name] = def