Skip to content

Common API

Crystal Spider edited this page Jun 2, 2024 · 12 revisions

Unified Configuration System

WIP

Tool tiers

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
    Special Tier to represent no tier.
  • NO_TIER_REFERENCE
    Special string reference for NO_TIER.
  • getAllTiers()
    Returns a Collection<Tier> of all the tiers in the game.
  • getTier(ResourceLocation) / getTier(String)
    Returns the tool tier from the given reference.
    Returns null if not tier could be found.
    The string must be parsable into a valid ResourceLocation.
  • 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 for NO_TIER or if the Item is not an instance of TieredItem.
  • matches(Tier, String)
    Checks whether the given reference represents the given tier.

In-game ID retrival

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 a ResourceLocation.
  • 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 a ResourceLocation.
  • ItemUtils#getStringKey(Item)
    Returns the in-game ID of the given item as a string.

Platform model

To prevent code duplication across various projects, Cobweb also provides enums for the Environment and the Platform.