Use mcl_tooltips for handling additional information for items if necessary
This commit is contained in:
parent
c58aeb308b
commit
969744f242
@ -16,19 +16,13 @@
|
|||||||
|
|
||||||
local S=minetest.get_translator("industrialtest")
|
local S=minetest.get_translator("industrialtest")
|
||||||
|
|
||||||
-- \brief Prepares itemstack containing fluid storage
|
local function createItemFluidStorageText(itemstack)
|
||||||
-- \param itemstack ItemStack
|
|
||||||
-- \returns bool
|
|
||||||
function industrialtest.api.prepareFluidStorageItem(itemstack)
|
|
||||||
local meta=itemstack:get_meta()
|
local meta=itemstack:get_meta()
|
||||||
local def=itemstack:get_definition()
|
local fluidCapacity=meta:get_int("industrialtest.fluidCapacity")
|
||||||
if industrialtest.api.itemHasFluidStorage(itemstack) or not def.groups or not def.groups._industrialtest_fluidStorage or not def._industrialtest_fluidCapacity then
|
local fluidAmount=meta:get_int("industrialtest.fluidAmount")
|
||||||
return false
|
local lowerLimit=math.floor(fluidCapacity*0.25)
|
||||||
end
|
local color=(fluidAmount>lowerLimit and "#0000FF" or "#FF0000")
|
||||||
meta:set_int("industrialtest.fluidAmount",0)
|
return minetest.colorize(color,S("@1 / @2 mB",fluidAmount,fluidCapacity))
|
||||||
meta:set_int("industrialtest.fluidCapacity",def._industrialtest_fluidCapacity)
|
|
||||||
industrialtest.api.updateItemFluidText(itemstack)
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- \brief Check if itemstack contains fluid storage
|
-- \brief Check if itemstack contains fluid storage
|
||||||
@ -80,8 +74,13 @@ end
|
|||||||
-- \returns nil
|
-- \returns nil
|
||||||
function industrialtest.api.updateItemFluidText(itemstack)
|
function industrialtest.api.updateItemFluidText(itemstack)
|
||||||
local meta=itemstack:get_meta()
|
local meta=itemstack:get_meta()
|
||||||
local def=itemstack:get_definition()
|
if industrialtest.mtgAvailable then
|
||||||
meta:set_string("description",S("@1\n@2 / @3 mB",def.description,meta:get_int("industrialtest.fluidAmount"),meta:get_int("industrialtest.fluidCapacity")))
|
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)
|
itemstack:set_wear(65535-meta:get_int("industrialtest.fluidAmount")/meta:get_int("industrialtest.fluidCapacity")*65534)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -119,3 +118,15 @@ function industrialtest.api.transferFluidToItem(srcItemstack,itemstack,amount)
|
|||||||
industrialtest.api.updateItemFluidText(srcItemstack)
|
industrialtest.api.updateItemFluidText(srcItemstack)
|
||||||
return actualFlow
|
return actualFlow
|
||||||
end
|
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
|
||||||
|
@ -16,6 +16,15 @@
|
|||||||
|
|
||||||
local S=minetest.get_translator("industrialtest")
|
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
|
-- \brief Adds power storage to metadata
|
||||||
-- \param capacity How much EU item/node can store
|
-- \param capacity How much EU item/node can store
|
||||||
-- \param flow How much EU can flow in or out item/node per industrialtest.updateDelay
|
-- \param flow How much EU can flow in or out item/node per industrialtest.updateDelay
|
||||||
@ -158,9 +167,14 @@ end
|
|||||||
-- \returns nil
|
-- \returns nil
|
||||||
function industrialtest.api.updateItemPowerText(itemstack)
|
function industrialtest.api.updateItemPowerText(itemstack)
|
||||||
local meta=itemstack:get_meta()
|
local meta=itemstack:get_meta()
|
||||||
local def=minetest.registered_tools[itemstack:get_name()]
|
if industrialtest.mtgAvailable then
|
||||||
local desc=meta:contains("industrialtest.descriptionOverride") and meta:get_string("industrialtest.descriptionOverride") or def.description
|
local def=minetest.registered_tools[itemstack:get_name()]
|
||||||
meta:set_string("description",S("@1\n@2 / @3 EU",desc,meta:get_int("industrialtest.powerAmount"),meta:get_int("industrialtest.powerCapacity")))
|
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)
|
itemstack:set_wear(65535-meta:get_int("industrialtest.powerAmount")/meta:get_int("industrialtest.powerCapacity")*65534)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -209,3 +223,15 @@ function industrialtest.api.transferPowerFromItem(srcItemstack,meta,amount)
|
|||||||
return actualFlow
|
return actualFlow
|
||||||
end
|
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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user