Fabric-language Kotlin Guide

object ModItems val EXAMPLE_ITEM: Item = Item(Item.Settings().maxCount(64)) fun register() Registry.register(Registries.ITEM, Identifier(MOD_ID, "example_item"), EXAMPLE_ITEM)

override fun onInitialize() ModBlocks.register() ModItems.register() fabric-language kotlin

// Kotlin modImplementation "net.fabricmc:fabric-language-kotlin:$project.fabric_kotlin_version" include "net.fabricmc:fabric-language-kotlin:$project.fabric_kotlin_version" object ModItems val EXAMPLE_ITEM: Item = Item(Item

@Mixin(PlayerEntity::class) abstract class PlayerMixin @ModifyVariable(method = "attack", at = @At("HEAD")) fun modifyAttackDamage(damage: Float): Float return damage * 1.5f count: Int = 1) inventory.offerOrDrop(ItemStack(item

Extension Functions fun PlayerEntity.giveItem(item: Item, count: Int = 1) inventory.offerOrDrop(ItemStack(item, count))

Note: The fabric-language-kotlin module registers the kotlin language adapter automatically. Block with simple properties object ModBlocks val EXAMPLE_BLOCK: Block = Block(FabricBlockSettings.create() .strength(4.0f) .requiresTool() .mapColor(MapColor.STONE_GRAY)) fun register() Registry.register(Registries.BLOCK, Identifier(MOD_ID, "example_block"), EXAMPLE_BLOCK)

package com.example.mymod import net.fabricmc.api.ModInitializer import org.slf4j.LoggerFactory