diff --git a/api/fluid.lua b/api/fluid.lua index c07d9de..be6b53d 100644 --- a/api/fluid.lua +++ b/api/fluid.lua @@ -16,19 +16,13 @@ local S=minetest.get_translator("industrialtest") --- \brief Prepares itemstack containing fluid storage --- \param itemstack ItemStack --- \returns bool -function industrialtest.api.prepareFluidStorageItem(itemstack) +local function createItemFluidStorageText(itemstack) local meta=itemstack:get_meta() - local def=itemstack:get_definition() - if industrialtest.api.itemHasFluidStorage(itemstack) or not def.groups or not def.groups._industrialtest_fluidStorage or not def._industrialtest_fluidCapacity then - return false - end - meta:set_int("industrialtest.fluidAmount",0) - meta:set_int("industrialtest.fluidCapacity",def._industrialtest_fluidCapacity) - industrialtest.api.updateItemFluidText(itemstack) - return true + local fluidCapacity=meta:get_int("industrialtest.fluidCapacity") + local fluidAmount=meta:get_int("industrialtest.fluidAmount") + local lowerLimit=math.floor(fluidCapacity*0.25) + local color=(fluidAmount>lowerLimit and "#0000FF" or "#FF0000") + return minetest.colorize(color,S("@1 / @2 mB",fluidAmount,fluidCapacity)) end -- \brief Check if itemstack contains fluid storage @@ -80,8 +74,13 @@ end -- \returns nil function industrialtest.api.updateItemFluidText(itemstack) local meta=itemstack:get_meta() - local def=itemstack:get_definition() - meta:set_string("description",S("@1\n@2 / @3 mB",def.description,meta:get_int("industrialtest.fluidAmount"),meta:get_int("industrialtest.fluidCapacity"))) + if industrialtest.mtgAvailable then + local def=itemstack:get_definition() + local fluidStorageText=createItemFluidStorageText(itemstack) + meta:set_string("description",string.format("%s\n%s",def.description,fluidStorageText)) + elseif industrialtest.mclAvailable then + tt.reload_itemstack_description(itemstack) + end itemstack:set_wear(65535-meta:get_int("industrialtest.fluidAmount")/meta:get_int("industrialtest.fluidCapacity")*65534) end @@ -119,3 +118,15 @@ function industrialtest.api.transferFluidToItem(srcItemstack,itemstack,amount) industrialtest.api.updateItemFluidText(srcItemstack) return actualFlow end + +if industrialtest.mclAvailable then + tt.register_snippet(function(itemstring,toolCapabilities,itemstack) + if not itemstack then + return nil + end + if not industrialtest.api.itemHasFluidStorage(itemstack) then + return nil + end + return createItemFluidStorageText(itemstack),false + end) +end diff --git a/api/power.lua b/api/power.lua index 317159c..fea111c 100644 --- a/api/power.lua +++ b/api/power.lua @@ -16,6 +16,15 @@ local S=minetest.get_translator("industrialtest") +local function createItemPowerText(itemstack) + local meta=itemstack:get_meta() + local powerCapacity=meta:get_int("industrialtest.powerCapacity") + local powerAmount=meta:get_int("industrialtest.powerAmount") + local lowerLimit=math.floor(powerCapacity*0.25) + local color=(powerAmount>lowerLimit and "#00FFFF" or "#FF0000") + return minetest.colorize(color,S("@1 / @2 EU",powerAmount,powerCapacity)) +end + -- \brief Adds power storage to metadata -- \param capacity How much EU item/node can store -- \param flow How much EU can flow in or out item/node per industrialtest.updateDelay @@ -158,9 +167,14 @@ end -- \returns nil function industrialtest.api.updateItemPowerText(itemstack) local meta=itemstack:get_meta() - local def=minetest.registered_tools[itemstack:get_name()] - local desc=meta:contains("industrialtest.descriptionOverride") and meta:get_string("industrialtest.descriptionOverride") or def.description - meta:set_string("description",S("@1\n@2 / @3 EU",desc,meta:get_int("industrialtest.powerAmount"),meta:get_int("industrialtest.powerCapacity"))) + if industrialtest.mtgAvailable then + local def=minetest.registered_tools[itemstack:get_name()] + local desc=meta:contains("industrialtest.descriptionOverride") and meta:get_string("industrialtest.descriptionOverride") or def.description + local powerText=createItemPowerText(itemstack) + meta:set_string("description",string.format("%s\n%s",desc,powerText)) + elseif industrialtest.mclAvailable then + tt.reload_itemstack_description(itemstack) + end itemstack:set_wear(65535-meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*65534) end @@ -209,3 +223,15 @@ function industrialtest.api.transferPowerFromItem(srcItemstack,meta,amount) return actualFlow end +if industrialtest.mclAvailable then + tt.register_snippet(function(itemstring,toolCapabilities,itemstack) + if not itemstack then + return nil + end + local meta=itemstack:get_meta() + if not industrialtest.api.hasPowerStorage(meta) then + return nil + end + return createItemPowerText(itemstack),false + end) +end