![Kotlin Extensions [Fabric]](https://cdn.modstock.ru/resources/mods/kotlin-extensions-fabric/logo.png)
This mod is an API that provides useful extensions to existing vanilla classes. They are grouped based on the class that is primarily dealt with or returned by the function.
Block Extensions
Block.makeItem()
- creates a newBlockItem
based on the block. Optionally takes anItem.Settings
.Block.matches(Identifier)
- checks whether the block is contained in the tag with the given idBlock.matches(String)
- converts the String to anIdentifier
then callsmatches(Identifier)
Identifier Extensions
String.id
- converts the String to anIdentifier
Pair.id
- converts the Pair to anIdentifier
Identifier.component1() and .component2()
- allows for destructuring ofIdentifier
sString.validId()
- checks if the String is a validIdentifier
Pair.validId()
checks if the Pair is a validIdentifier
Item Extensions
Item.stack()
- creates a new ItemStack with the Item. Optionally takes an Int for the count.Item.matches(Tag or Identifier or String)
- checks if the Item is in the Tag. Same idea asBlock::matches
NBT Tag Extensions
compooundTag(vararg Pair)
- creates a newCompoundTag
with the given elementsCompoundTag.set(String, Tag)
- operator forCompoundTag::put
Map.toCompoundTag()
- creates a newCompoundTag
from the map's elementsAny?.toTag()
- Creates a newTag
from the object. Note: if the object cannot be converted into a tag, this will crash the game.interface NBTSerializable
- Allows you to create the NBT representation for your classes. Not needed forEntity
andBlockEntity
subclasses.
Registry Extensions
Registry.get(String)
- converts to anIdentifier
and gets the value in the RegistryRegistry.set(Identifier or String, T)
- Registers the value in the Registry usingRegistry.register
Identifier.item() and .block() and .entityType() and .blockEntityType() and .registry()
- gets the value at theIdentifier
in the appropriate Registry
Tag Extensions
Identifier.tag()
- gets aTag
at theIdentifier
. Only valid for Item, Block, EntityType, and Fluid. Any other type will crash the game.String.tag()
- converts to anIdentifier
and gets theTag
at itTag.isEqual(Tag)
-Tag.equals
is not properly overridden. Use this to compare equality with tags.
World Extensions
World.runOnClient(()-Unit)
- Runs the passed function only on the clientWorld.runOnServer(()-Unit)
- Runs the passed function only on the server