generated from Crystal-Nest/cobweb-mod-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Common API
Crystal Spider edited this page Jun 2, 2024
·
12 revisions
WIP
Forge and NeoForge offer a tool tier API, but it lacks some utility methods. Fabric, on the other hand, doesn't have an API at all.
To address these gaps, Cobweb introduces the TierUtils
utility class, which provides the lacking utility methods and allows handling tool tiers within the common module.
-
NO_TIER
SpecialTier
to represent no tier. -
NO_TIER_REFERENCE
Special string reference forNO_TIER
. -
getAllTiers()
Returns aCollection<Tier>
of all the tiers in the game. -
getTier(ResourceLocation)
/getTier(String)
Returns the tool tier from the given reference.
Returnsnull
if not tier could be found.
The string must be parsable into a validResourceLocation
. -
compare(Item, Item)
/compare(TieredItem, TieredItem)
/compare(Tier, Tier)
/compare(ResourceLocation, ResourceLocation)
/compare(String, String)
Compares the two tiers, abiding to the usual compare semantics:0
if the tiers are equal,< 0
if the first tier is lower than the second one,> 0
vice versa. -
isIn(Collection<Tier>, Tier)
/isIn(Collection<Tier>, ResourceLocation)
/isIn(Collection<Tier>, String)
Checks whether the given tier is in the given tier list. -
getLevel(Item)
/getLevel(TieredItem)
/getLevel(Tier)
/getLevel(ResourceLocation)
/getLevel(String)
Returns the numeric level of the given tool tier.
The level can be the special value-1
if the reference is forNO_TIER
or if theItem
is not an instance ofTieredItem
. -
matches(Tier, String)
Checks whether the given reference represents the given tier.
For both blocks and items, Cobweb provides a shorthand to retrieve their in-game IDs (e.g. Blocks.DIRT
-> minecraft:dirt
).
Blocks:
-
BlockUtils#getKey(Block)
Returns the in-game ID of the given block as aResourceLocation
. -
BlockUtils#getStringKey(Block)
Returns the in-game ID of the given block as a string.
Items:
-
ItemUtils#getKey(Item)
Returns the in-game ID of the given item as aResourceLocation
. -
ItemUtils#getStringKey(Item)
Returns the in-game ID of the given item as a string.
To prevent code duplication across various projects, Cobweb also provides enums for the Environment and the Platform.
If you have any suggestions or questions about this wiki, please open an issue following the Documentation enhancement template.