Skip to content

server.item #

Non-block items of the combat and progression family; the block items live in server/block/combat_progression_item.v. Non-block items of the farming family; the block items live in server/block/farming_components_item.v.

Constants #

const max_book_pages = 50

max_book_pages and max_book_page_bytes bound what a client can push into a book's NBT.

const max_book_page_bytes = 256
const custom_item_runtime_id_start = 10000

Runtime ids for custom items start well above the vanilla palette so they never collide with it.

fn all_recipes #

fn all_recipes() []Recipe

fn apply_palette_fallbacks #

fn apply_palette_fallbacks(entries []FallbackEntry)

apply_palette_fallbacks fills in every wire-palette item that has no hand written class yet, so it's still holdable. Safe to call more than once - an already-registered id is left untouched. Each Hub calls this with its own loaded palette, since the palette itself comes from disk per Hub.

fn book_pages_from_nbt #

fn book_pages_from_nbt(raw []u8) []string

fn combat_progression_items #

fn combat_progression_items() []Item

fn consume_result #

fn consume_result(id string, meta int) ?ConsumeResult

fn cooldown_ticks #

fn cooldown_ticks(id string) ?int

fn damage_item #

fn damage_item(it Item, current_meta int, amount int) DamageResult

damage_item computes the result of applying amount points of durability damage to an item currently at current_meta.

fn farming_items #

fn farming_items() []Item

fn get #

fn get(id string) ?Item

get returns the registered class for id, or none if unregistered.

fn max_stack_size #

fn max_stack_size(id string) int

max_stack_size returns the stack size for id, falling back to 64 for unregistered items.

fn new_apple #

fn new_apple() AppleItem

fn new_armor_item #

fn new_armor_item(tier ArmorTier, slot ArmorSlot) ArmorItem

new_armor_item builds the class for a tier x slot combination.

fn new_baked_potato #

fn new_baked_potato() BakedPotatoItem

fn new_beef #

fn new_beef() BeefItem

fn new_beetroot #

fn new_beetroot() BeetrootItem

fn new_beetroot_soup #

fn new_beetroot_soup() BeetrootSoupItem

fn new_bone_meal_item #

fn new_bone_meal_item() BoneMealItem

fn new_bread #

fn new_bread() BreadItem

fn new_bucket_item #

fn new_bucket_item() BucketItem

fn new_cake #

fn new_cake() CakeItem

fn new_carrot #

fn new_carrot() CarrotItem

fn new_chicken #

fn new_chicken() ChickenItem

fn new_coal #

fn new_coal() CoalItem

fn new_cod #

fn new_cod() CodItem

fn new_compass_item #

fn new_compass_item() CompassItem

fn new_cooked_beef #

fn new_cooked_beef() CookedBeefItem

fn new_cooked_chicken #

fn new_cooked_chicken() CookedChickenItem

fn new_cooked_cod #

fn new_cooked_cod() CookedCodItem

fn new_cooked_mutton #

fn new_cooked_mutton() CookedMuttonItem

fn new_cooked_porkchop #

fn new_cooked_porkchop() CookedPorkchopItem

fn new_cooked_salmon #

fn new_cooked_salmon() CookedSalmonItem

fn new_copper_ingot #

fn new_copper_ingot() CopperIngotItem

fn new_custom_registry #

fn new_custom_registry() CustomRegistry

fn new_diamond #

fn new_diamond() DiamondItem

fn new_dried_kelp #

fn new_dried_kelp() DriedKelpItem

fn new_emerald #

fn new_emerald() EmeraldItem

fn new_glow_berries #

fn new_glow_berries() GlowBerriesItem

fn new_goat_horn_item #

fn new_goat_horn_item() GoatHornItem

fn new_gold_ingot #

fn new_gold_ingot() GoldIngotItem

fn new_golden_apple #

fn new_golden_apple() GoldenAppleItem

fn new_golden_carrot #

fn new_golden_carrot() GoldenCarrotItem

fn new_honey_bottle #

fn new_honey_bottle() HoneyBottleItem

fn new_iron_ingot #

fn new_iron_ingot() IronIngotItem

fn new_lapis_lazuli #

fn new_lapis_lazuli() LapisLazuliItem

fn new_lodestone_compass_item #

fn new_lodestone_compass_item() LodestoneCompassItem

fn new_melon_slice #

fn new_melon_slice() MelonSliceItem

fn new_mushroom_stew #

fn new_mushroom_stew() MushroomStewItem

fn new_mutton #

fn new_mutton() MuttonItem

fn new_poisonous_potato #

fn new_poisonous_potato() PoisonousPotatoItem

fn new_porkchop #

fn new_porkchop() PorkchopItem

fn new_potato #

fn new_potato() PotatoItem

fn new_pumpkin_pie #

fn new_pumpkin_pie() PumpkinPieItem

fn new_rabbit_stew #

fn new_rabbit_stew() RabbitStewItem

fn new_raw_copper #

fn new_raw_copper() RawCopperItem

fn new_raw_gold #

fn new_raw_gold() RawGoldItem

fn new_raw_iron #

fn new_raw_iron() RawIronItem

fn new_recovery_compass_item #

fn new_recovery_compass_item() RecoveryCompassItem

fn new_registry #

fn new_registry() Registry

new_registry builds a Registry pre-populated with the built-in item classes.

fn new_salmon #

fn new_salmon() SalmonItem

fn new_stick #

fn new_stick() StickItem

fn new_sweet_berries #

fn new_sweet_berries() SweetBerriesItem

fn new_tool_item #

fn new_tool_item(tier ToolTier, typ ToolType) ToolItem

new_tool_item builds the class for a tier x tool-type combination.

fn new_wheat #

fn new_wheat() WheatItem

fn potion_from_meta #

fn potion_from_meta(meta int) PotionType

fn recipe_by_network_id #

fn recipe_by_network_id(id u32) ?Recipe

fn register #

fn register(it Item)

register adds or overrides the class for an item id. Use this for a hand-written Item; register_custom (custom.v) is the data-driven form.

fn register_custom #

fn register_custom(def CustomItemDefinition) int

register_custom registers a data-driven item: allocates its runtime id and makes it resolvable everywhere immediately (get, max_stack_size, ...). Call it from your own main(), before server.new(). Registering the same id twice just returns the id already allocated to it.

fn registered_custom #

fn registered_custom() []CustomItemDefinition

registered_custom returns every item registered via register_custom so far, each with its runtime id filled in.

fn use_on_block_result #

fn use_on_block_result(id string, block_name string, meta int) ?UseOnBlockResult

fn use_on_entity_result #

fn use_on_entity_result(id string, entity_name string, meta int) ?UseOnEntityResult

fn use_result #

fn use_result(id string, meta int) ?UseResult

fn writable_book_nbt #

fn writable_book_nbt(pages []string) []u8

fn written_book_nbt #

fn written_book_nbt(title string, author string, generation int, pages []string) []u8

fn ArmorSlot.from #

fn ArmorSlot.from[W](input W) !ArmorSlot

fn ArmorTier.from #

fn ArmorTier.from[W](input W) !ArmorTier

fn ToolTier.from #

fn ToolTier.from[W](input W) !ToolTier

fn ToolType.from #

fn ToolType.from[W](input W) !ToolType

interface ConsumableItem #

interface ConsumableItem {
	consume_result(meta int) ConsumeResult
}

interface CooldownItem #

interface CooldownItem {
	cooldown_ticks() int
}

CooldownItem is implemented by items that can't be used again for a period after use (e.g. the goat horn).

interface Item #

interface Item {
	// identifier returns the namespaced item id used on the wire.
	identifier() string
	// max_stack_size is how many of this item fit in a single slot.
	max_stack_size() int
	// attack_damage is the melee damage dealt on hit, 0 for non-weapons.
	attack_damage() f32
	// nutrition is the hunger points restored on eat, 0 for non-food.
	nutrition() int
	// saturation is the saturation modifier applied on eat, 0 for non-food.
	saturation() f32
	// block_runtime_id is the block placed on use, 0 for non-block items.
	block_runtime_id() int
	// durability is the max number of uses before the item breaks, 0 for
	// items that don't take durability damage.
	durability() int
	// mining_speed is the block breaking speed multiplier this item grants
	// as a tool, 1.0 (no bonus) for non-tools.
	mining_speed() f32
	// armor_points is the defense value this item grants when worn, 0 for
	// non-armor.
	armor_points() int
}

Item is the behaviour contract every item class implements. Every item is its own class built on a family base struct (ToolItem, ArmorItem, FoodItem, SimpleItem, or block.BlockItem for the items that place a block) and registered in the Registry so the session layer can look it up by its string identifier (e.g. 'minecraft:diamond_sword').

interface MiningTool #

interface MiningTool {
	// block_tool_type is the block tool family bitflag this item belongs to.
	block_tool_type() int
	// harvest_level is the tier this item harvests up to.
	harvest_level() int
}

MiningTool is implemented by items that mine a matching block family faster than a bare hand. Items that don't implement it break every block at hand speed.

interface UsableOnBlockItem #

interface UsableOnBlockItem {
	use_on_block_result(block_name string, meta int) ?UseOnBlockResult
}

UsableOnBlockItem is implemented by items with a behaviour when used on a specific kind of block (e.g. bone meal on crops). Returns none if this item does nothing to a block named block_name.

interface UsableOnEntityItem #

interface UsableOnEntityItem {
	use_on_entity_result(entity_name string, meta int) ?UseOnEntityResult
}

UsableOnEntityItem is implemented by items with a behaviour when used on a specific kind of entity (e.g. milk bucket on a cow). Returns none if this item does nothing to an entity named entity_name.

interface UseableItem #

interface UseableItem {
	use_result(meta int) UseResult
}

UseableItem is implemented by items with a behaviour on right-click in air (item_use_action_click_air), separate from ConsumableItem's eat on use flow.

enum ArmorSlot #

enum ArmorSlot {
	helmet
	chestplate
	leggings
	boots
}

ArmorSlot is the equipment slot an armor piece occupies.

enum ArmorTier #

enum ArmorTier {
	leather
	gold
	copper
	iron
	diamond
	netherite
}

ArmorTier is the material tier shared by every armor piece.

enum ToolTier #

enum ToolTier {
	wood
	stone
	copper
	iron
	gold
	diamond
	netherite
}

ToolTier is the material tier shared by every tool and weapon.

enum ToolType #

enum ToolType {
	sword
	pickaxe
	axe
	shovel
	hoe
}

ToolType is the tool/weapon shape. Attack damage differs by type; mining speed and durability are tier-only (same across all five shapes).

struct AppleItem #

struct AppleItem {
	FoodItem
}

AppleItem is the class for 'minecraft:apple'.

struct ArmorItem #

struct ArmorItem {
pub:
	id             string
	tier           ArmorTier
	slot           ArmorSlot
	defense        int
	max_durability int
}

fn (ArmorItem) identifier #

fn (i ArmorItem) identifier() string

fn (ArmorItem) max_stack_size #

fn (i ArmorItem) max_stack_size() int

fn (ArmorItem) attack_damage #

fn (i ArmorItem) attack_damage() f32

fn (ArmorItem) nutrition #

fn (i ArmorItem) nutrition() int

fn (ArmorItem) saturation #

fn (i ArmorItem) saturation() f32

fn (ArmorItem) block_runtime_id #

fn (i ArmorItem) block_runtime_id() int

fn (ArmorItem) durability #

fn (i ArmorItem) durability() int

fn (ArmorItem) mining_speed #

fn (i ArmorItem) mining_speed() f32

fn (ArmorItem) armor_points #

fn (i ArmorItem) armor_points() int

struct BakedPotatoItem #

struct BakedPotatoItem {
	FoodItem
}

BakedPotatoItem is the class for 'minecraft:baked_potato'.

struct BeefItem #

struct BeefItem {
	FoodItem
}

BeefItem is the class for 'minecraft:beef'.

struct BeetrootItem #

struct BeetrootItem {
	FoodItem
}

BeetrootItem is the class for 'minecraft:beetroot'.

fn (BeetrootItem) use_on_block_result #

fn (i BeetrootItem) use_on_block_result(block_name string, meta int) ?UseOnBlockResult

struct BeetrootSoupItem #

struct BeetrootSoupItem {
	FoodItem
}

BeetrootSoupItem is the class for 'minecraft:beetroot_soup'.

struct BoneMealItem #

struct BoneMealItem {
	SimpleItem
}

BoneMealItem is the class for 'minecraft:bone_meal'.

fn (BoneMealItem) use_on_block_result #

fn (i BoneMealItem) use_on_block_result(block_name string, meta int) ?UseOnBlockResult

struct BreadItem #

struct BreadItem {
	FoodItem
}

BreadItem is the class for 'minecraft:bread'.

struct BucketItem #

struct BucketItem {
	SimpleItem
}

BucketItem is the class for 'minecraft:bucket' (the empty bucket). Filled buckets (milk_bucket, water_bucket, lava_bucket) stay on the fallback path, only the empty bucket has a UsableOnEntityItem behaviour.

fn (BucketItem) use_on_entity_result #

fn (i BucketItem) use_on_entity_result(entity_name string, meta int) ?UseOnEntityResult

struct CakeItem #

struct CakeItem {
	FoodItem
}

CakeItem is the class for 'minecraft:cake'.

struct CarrotItem #

struct CarrotItem {
	FoodItem
pub:
	block_runtime int
}

CarrotItem is the class for 'minecraft:carrot'. No separate seed item exists (unlike wheat/beetroot).

fn (CarrotItem) block_runtime_id #

fn (i CarrotItem) block_runtime_id() int

fn (CarrotItem) use_on_block_result #

fn (i CarrotItem) use_on_block_result(block_name string, meta int) ?UseOnBlockResult

struct ChickenItem #

struct ChickenItem {
	FoodItem
}

ChickenItem is the class for 'minecraft:chicken'.

struct CoalItem #

struct CoalItem {
	SimpleItem
}

CoalItem is the class for 'minecraft:coal'.

struct CodItem #

struct CodItem {
	FoodItem
}

CodItem is the class for 'minecraft:cod'.

struct CompassItem #

struct CompassItem {
	SimpleItem
}

CompassItem is the class for 'minecraft:compass'.

struct ConsumeResult #

struct ConsumeResult {
pub:
	effects           []effect.Effect
	replacement_id    string
	replacement_count int
}

struct CookedBeefItem #

struct CookedBeefItem {
	FoodItem
}

CookedBeefItem is the class for 'minecraft:cooked_beef'.

struct CookedChickenItem #

struct CookedChickenItem {
	FoodItem
}

CookedChickenItem is the class for 'minecraft:cooked_chicken'.

struct CookedCodItem #

struct CookedCodItem {
	FoodItem
}

CookedCodItem is the class for 'minecraft:cooked_cod'.

struct CookedMuttonItem #

struct CookedMuttonItem {
	FoodItem
}

CookedMuttonItem is the class for 'minecraft:cooked_mutton'.

struct CookedPorkchopItem #

struct CookedPorkchopItem {
	FoodItem
}

CookedPorkchopItem is the class for 'minecraft:cooked_porkchop'.

struct CookedSalmonItem #

struct CookedSalmonItem {
	FoodItem
}

CookedSalmonItem is the class for 'minecraft:cooked_salmon'.

struct CookieItem #

struct CookieItem {
	FoodItem
}

CookieItem is the class for 'minecraft:cookie'.

struct CooldownComponent #

struct CooldownComponent {
pub:
	category string
	duration f32
}

CooldownComponent gives the item a use cooldown, grouped by category.

struct CopperIngotItem #

struct CopperIngotItem {
	SimpleItem
}

CopperIngotItem is the class for 'minecraft:copper_ingot'.

struct CustomItemClass #

struct CustomItemClass {
pub:
	def CustomItemDefinition
}

CustomItemClass adapts a definition to the Item interface so the session layer treats custom items like any built-in class.

fn (CustomItemClass) identifier #

fn (c CustomItemClass) identifier() string

fn (CustomItemClass) max_stack_size #

fn (c CustomItemClass) max_stack_size() int

fn (CustomItemClass) attack_damage #

fn (c CustomItemClass) attack_damage() f32

fn (CustomItemClass) nutrition #

fn (c CustomItemClass) nutrition() int

fn (CustomItemClass) saturation #

fn (c CustomItemClass) saturation() f32

fn (CustomItemClass) block_runtime_id #

fn (c CustomItemClass) block_runtime_id() int

fn (CustomItemClass) durability #

fn (c CustomItemClass) durability() int

fn (CustomItemClass) mining_speed #

fn (c CustomItemClass) mining_speed() f32

fn (CustomItemClass) armor_points #

fn (c CustomItemClass) armor_points() int

struct CustomItemDefinition #

struct CustomItemDefinition {
pub mut:
	id                      string
	display_name            string
	texture                 string
	max_stack_size          int = 64
	attack_damage_value     int
	hand_equipped           bool
	allow_off_hand          bool
	glint                   bool
	can_destroy_in_creative bool = true
	mining_speed            f32  = 1.0
	fuel_duration           f32
	creative_group_index    int
	tags                    []string
	digger_speeds           []DiggerSpeed
	food                    ?FoodComponent
	wearable                ?WearableComponent
	cooldown                ?CooldownComponent
	enchantable             ?EnchantableComponent
	durability_component    ?DurabilityComponent
	runtime_id              int
}

CustomItemDefinition describes a data-driven item a plugin registers. The definition is turned into component NBT and shipped to the client inside the ItemRegistryPacket, so no resource pack code is needed server-side beyond the texture name.

fn (CustomItemDefinition) components #

fn (d &CustomItemDefinition) components() nbt.RootTag

components builds the component NBT the client consumes: an item_properties compound for the base properties and one minecraft:* compound per opted-in component.

struct CustomRegistry #

struct CustomRegistry {
mut:
	defs    []CustomItemDefinition
	ids     map[string]int
	next_id int = custom_item_runtime_id_start
}

CustomRegistry owns every registered custom item definition and hands out runtime ids sequentially, starting at custom_item_runtime_id_start.

fn (CustomRegistry) register #

fn (mut r CustomRegistry) register(def CustomItemDefinition) int

register allocates a runtime id for def and stores it. Registering the same id again returns the previously allocated runtime id unchanged.

fn (CustomRegistry) all #

fn (r &CustomRegistry) all() []CustomItemDefinition

all returns every registered definition with its runtime id filled in.

fn (CustomRegistry) len #

fn (r &CustomRegistry) len() int

fn (CustomRegistry) runtime_id #

fn (r &CustomRegistry) runtime_id(id string) ?int

fn (CustomRegistry) names #

fn (r &CustomRegistry) names() []string

struct DamageResult #

struct DamageResult {
pub:
	broken   bool
	new_meta int
}

DamageResult is the outcome of applying durability damage to a stack. broken means the item should be removed (or replaced with its broken item, once anything defines one. For now, every durable item just disappears.

struct DiamondItem #

struct DiamondItem {
	SimpleItem
}

DiamondItem is the class for 'minecraft:diamond'.

struct DiggerSpeed #

struct DiggerSpeed {
pub:
	block string
	speed int
}

DiggerSpeed is one block (or block tag query) the item digs faster.

struct DriedKelpItem #

struct DriedKelpItem {
	FoodItem
}

DriedKelpItem is the class for 'minecraft:dried_kelp'.

struct DurabilityComponent #

struct DurabilityComponent {
pub:
	max_durability int
}

DurabilityComponent gives the item a durability bar.

struct DurabilityItem #

struct DurabilityItem {
pub:
	id             string
	damage         f32
	max_durability int
}

DurabilityItem is the base class for held combat items whose only shared behaviour is "takes durability damage, one per slot"; unlike ToolItem/ ArmorItem there's no tier x shape matrix here (shield/bow/crossbow/trident are each one-off items).

fn (DurabilityItem) identifier #

fn (i DurabilityItem) identifier() string

fn (DurabilityItem) max_stack_size #

fn (i DurabilityItem) max_stack_size() int

fn (DurabilityItem) attack_damage #

fn (i DurabilityItem) attack_damage() f32

fn (DurabilityItem) nutrition #

fn (i DurabilityItem) nutrition() int

fn (DurabilityItem) saturation #

fn (i DurabilityItem) saturation() f32

fn (DurabilityItem) block_runtime_id #

fn (i DurabilityItem) block_runtime_id() int

fn (DurabilityItem) durability #

fn (i DurabilityItem) durability() int

fn (DurabilityItem) mining_speed #

fn (i DurabilityItem) mining_speed() f32

fn (DurabilityItem) armor_points #

fn (i DurabilityItem) armor_points() int

struct EmeraldItem #

struct EmeraldItem {
	SimpleItem
}

EmeraldItem is the class for 'minecraft:emerald'.

struct EnchantableComponent #

struct EnchantableComponent {
pub:
	slot  string
	value int
}

EnchantableComponent controls which enchantment slot the item accepts and its enchantability value.

struct FallbackEntry #

struct FallbackEntry {
pub:
	id            string
	block_runtime int
}

struct FoodComponent #

struct FoodComponent {
pub:
	nutrition      int
	saturation     f32
	can_always_eat bool
}

FoodComponent makes a custom item edible.

struct FoodItem #

struct FoodItem {
pub:
	id             string
	food_points    int
	saturation_mod f32
	stack_max      int = 64
}

FoodItem is the base class for edibles. food_points is the number of hunger points restored on eat, saturation_mod the saturation modifier. Concrete foods embed it, one class per food.

fn (FoodItem) identifier #

fn (i FoodItem) identifier() string

fn (FoodItem) max_stack_size #

fn (i FoodItem) max_stack_size() int

fn (FoodItem) attack_damage #

fn (i FoodItem) attack_damage() f32

fn (FoodItem) nutrition #

fn (i FoodItem) nutrition() int

fn (FoodItem) saturation #

fn (i FoodItem) saturation() f32

fn (FoodItem) block_runtime_id #

fn (i FoodItem) block_runtime_id() int

fn (FoodItem) durability #

fn (i FoodItem) durability() int

fn (FoodItem) mining_speed #

fn (i FoodItem) mining_speed() f32

fn (FoodItem) armor_points #

fn (i FoodItem) armor_points() int

struct GlowBerriesItem #

struct GlowBerriesItem {
	FoodItem
}

GlowBerriesItem is the class for 'minecraft:glow_berries'.

struct GoatHornItem #

struct GoatHornItem {
	SimpleItem
}

GoatHornItem is the class for 'minecraft:goat_horn'.

fn (GoatHornItem) use_result #

fn (i GoatHornItem) use_result(meta int) UseResult

fn (GoatHornItem) cooldown_ticks #

fn (i GoatHornItem) cooldown_ticks() int

struct GoldIngotItem #

struct GoldIngotItem {
	SimpleItem
}

GoldIngotItem is the class for 'minecraft:gold_ingot'.

struct GoldenAppleItem #

struct GoldenAppleItem {
	FoodItem
}

GoldenAppleItem is the class for 'minecraft:golden_apple'.

struct GoldenCarrotItem #

struct GoldenCarrotItem {
	FoodItem
}

GoldenCarrotItem is the class for 'minecraft:golden_carrot'.

struct HoneyBottleItem #

struct HoneyBottleItem {
	FoodItem
}

HoneyBottleItem is the class for 'minecraft:honey_bottle'.

struct IronIngotItem #

struct IronIngotItem {
	SimpleItem
}

IronIngotItem is the class for 'minecraft:iron_ingot'.

struct LapisLazuliItem #

struct LapisLazuliItem {
	SimpleItem
}

LapisLazuliItem is the class for 'minecraft:lapis_lazuli'.

struct LodestoneCompassItem #

struct LodestoneCompassItem {
	SimpleItem
}

LodestoneCompassItem is the class for 'minecraft:lodestone_compass'.

struct MelonSliceItem #

struct MelonSliceItem {
	FoodItem
}

MelonSliceItem is the class for 'minecraft:melon_slice'.

struct MushroomStewItem #

struct MushroomStewItem {
	FoodItem
}

MushroomStewItem is the class for 'minecraft:mushroom_stew'.

struct MuttonItem #

struct MuttonItem {
	FoodItem
}

MuttonItem is the class for 'minecraft:mutton'.

struct PoisonousPotatoItem #

struct PoisonousPotatoItem {
	FoodItem
}

PoisonousPotatoItem is the class for 'minecraft:poisonous_potato'.

struct PorkchopItem #

struct PorkchopItem {
	FoodItem
}

PorkchopItem is the class for 'minecraft:porkchop'.

struct PotatoItem #

struct PotatoItem {
	FoodItem
pub:
	block_runtime int
}

PotatoItem is the class for 'minecraft:potato'. No separate seed item exists (unlike wheat/beetroot).

fn (PotatoItem) block_runtime_id #

fn (i PotatoItem) block_runtime_id() int

fn (PotatoItem) use_on_block_result #

fn (i PotatoItem) use_on_block_result(block_name string, meta int) ?UseOnBlockResult

struct PotionItem #

struct PotionItem {}

fn (PotionItem) identifier #

fn (i PotionItem) identifier() string

fn (PotionItem) max_stack_size #

fn (i PotionItem) max_stack_size() int

fn (PotionItem) attack_damage #

fn (i PotionItem) attack_damage() f32

fn (PotionItem) nutrition #

fn (i PotionItem) nutrition() int

fn (PotionItem) saturation #

fn (i PotionItem) saturation() f32

fn (PotionItem) block_runtime_id #

fn (i PotionItem) block_runtime_id() int

fn (PotionItem) durability #

fn (i PotionItem) durability() int

fn (PotionItem) mining_speed #

fn (i PotionItem) mining_speed() f32

fn (PotionItem) armor_points #

fn (i PotionItem) armor_points() int

fn (PotionItem) consume_result #

fn (i PotionItem) consume_result(meta int) ConsumeResult

struct PotionType #

struct PotionType {
	value int
}

fn (PotionType) id #

fn (p PotionType) id() int

fn (PotionType) effects #

fn (p PotionType) effects() []effect.Effect

struct PumpkinPieItem #

struct PumpkinPieItem {
	FoodItem
}

PumpkinPieItem is the class for 'minecraft:pumpkin_pie'.

struct RabbitStewItem #

struct RabbitStewItem {
	FoodItem
}

RabbitStewItem is the class for 'minecraft:rabbit_stew'.

struct RawCopperItem #

struct RawCopperItem {
	SimpleItem
}

RawCopperItem is the class for 'minecraft:raw_copper'.

struct RawGoldItem #

struct RawGoldItem {
	SimpleItem
}

RawGoldItem is the class for 'minecraft:raw_gold'.

struct RawIronItem #

struct RawIronItem {
	SimpleItem
}

RawIronItem is the class for 'minecraft:raw_iron'.

struct Recipe #

struct Recipe {
pub:
	id           string
	ingredients  []RecipeIngredient
	output_name  string
	output_count int
	block        string = 'crafting_table'
	width        int
	height       int
	pattern      []string
	// 0 is never a valid recipe_network_id on the wire.
	network_id u32
}

Recipe is a crafting table recipe. Matching is identity & quantity only (ignores grid position). width/height/pattern exist only for CraftingDataPacket's wire encoding.

struct RecipeIngredient #

struct RecipeIngredient {
pub:
	name  string
	count int
}

RecipeIngredient is one required input for a Recipe, aggregated by identity. Name + total count needed, grid position never checked.

struct RecipeRegistry #

struct RecipeRegistry {
mut:
	recipes    []Recipe
	by_network map[u32]int
}

fn (RecipeRegistry) by_network_id #

fn (r &RecipeRegistry) by_network_id(id u32) ?Recipe

fn (RecipeRegistry) all #

fn (r &RecipeRegistry) all() []Recipe

struct RecoveryCompassItem #

struct RecoveryCompassItem {
	SimpleItem
}

RecoveryCompassItem is the class for 'minecraft:recovery_compass'.

struct Registry #

struct Registry {
mut:
	items map[string]Item
}

Registry maps namespaced item ids to their concrete Item class. The session layer holds one Registry and queries it for per-item behaviour (stack size, attack damage, ...) instead of hard-coding numeric ids.

fn (Registry) register #

fn (mut r Registry) register(it Item)

register adds or overrides the class for an item id.

fn (Registry) register_fallbacks #

fn (mut r Registry) register_fallbacks(entries []FallbackEntry)

fn (Registry) get #

fn (r &Registry) get(id string) ?Item

get returns the registered class for id, or none if unregistered.

fn (Registry) max_stack_size #

fn (r &Registry) max_stack_size(id string) int

max_stack_size returns the stack size for id, falling back to 64 for unregistered items.

fn (Registry) consume_result #

fn (r &Registry) consume_result(id string, meta int) ?ConsumeResult

fn (Registry) use_result #

fn (r &Registry) use_result(id string, meta int) ?UseResult

fn (Registry) use_on_block_result #

fn (r &Registry) use_on_block_result(id string, block_name string, meta int) ?UseOnBlockResult

fn (Registry) use_on_entity_result #

fn (r &Registry) use_on_entity_result(id string, entity_name string, meta int) ?UseOnEntityResult

fn (Registry) cooldown_ticks #

fn (r &Registry) cooldown_ticks(id string) ?int

fn (Registry) len #

fn (r &Registry) len() int

len is the number of registered item classes.

struct SalmonItem #

struct SalmonItem {
	FoodItem
}

SalmonItem is the class for 'minecraft:salmon'.

struct SimpleItem #

struct SimpleItem {
pub:
	id        string
	stack_max int = 64
}

SimpleItem is the base class for items that carry no special behaviour (dyes, sticks, string, ...). Concrete simple items embed it and fill in their identity; anything unregistered behaves like a default SimpleItem.

fn (SimpleItem) identifier #

fn (i SimpleItem) identifier() string

fn (SimpleItem) max_stack_size #

fn (i SimpleItem) max_stack_size() int

fn (SimpleItem) attack_damage #

fn (i SimpleItem) attack_damage() f32

fn (SimpleItem) nutrition #

fn (i SimpleItem) nutrition() int

fn (SimpleItem) saturation #

fn (i SimpleItem) saturation() f32

fn (SimpleItem) block_runtime_id #

fn (i SimpleItem) block_runtime_id() int

fn (SimpleItem) durability #

fn (i SimpleItem) durability() int

fn (SimpleItem) mining_speed #

fn (i SimpleItem) mining_speed() f32

fn (SimpleItem) armor_points #

fn (i SimpleItem) armor_points() int

struct StickItem #

struct StickItem {
	SimpleItem
}

StickItem is the class for 'minecraft:stick'.

struct SweetBerriesItem #

struct SweetBerriesItem {
	FoodItem
}

SweetBerriesItem is the class for 'minecraft:sweet_berries'.

struct ToolItem #

struct ToolItem {
pub:
	id             string
	tier           ToolTier
	tool_type      ToolType
	damage         f32
	max_durability int
	speed          f32
}

ToolItem is the class for every tier x type combination (e.g. tier .diamond, tool_type .pickaxe -> 'minecraft:diamond_pickaxe'). One parametrized struct instead of 30 near-identical classes, since nothing about a tool's behaviour is unique per material - it's entirely tier+type data (see ITEMS_BLOCKS.md open question 1).

fn (ToolItem) armor_points #

fn (i ToolItem) armor_points() int

fn (ToolItem) attack_damage #

fn (i ToolItem) attack_damage() f32

fn (ToolItem) block_runtime_id #

fn (i ToolItem) block_runtime_id() int

fn (ToolItem) block_tool_type #

fn (i ToolItem) block_tool_type() int

fn (ToolItem) durability #

fn (i ToolItem) durability() int

fn (ToolItem) harvest_level #

fn (i ToolItem) harvest_level() int

fn (ToolItem) identifier #

fn (i ToolItem) identifier() string

fn (ToolItem) max_stack_size #

fn (i ToolItem) max_stack_size() int

fn (ToolItem) mining_speed #

fn (i ToolItem) mining_speed() f32

fn (ToolItem) nutrition #

fn (i ToolItem) nutrition() int

fn (ToolItem) saturation #

fn (i ToolItem) saturation() f32

struct UseOnBlockResult #

struct UseOnBlockResult {
pub:
	sound       string
	state_key   string
	state_delta int
}

UseOnBlockResult describes what a UsableOnBlockItem does when used on a qualifying block: which int block-state to advance and by how much, plus an optional sound.

struct UseOnEntityResult #

struct UseOnEntityResult {
pub:
	sound         string
	replaces_with string
}

UseOnEntityResult describes what a UsableOnEntityItem does when used on a qualifying entity: an optional sound plus an optional item id the held stack is replaced with (empty means no swap, just the sound).

struct UseResult #

struct UseResult {
pub:
	sound string
}

UseResult describes what happens when a UseableItem is used. sound is broadcast at the user's position if non empty; empty means no sound.

struct WearableComponent #

struct WearableComponent {
pub:
	slot       string
	protection int
}

WearableComponent makes a custom item equippable as armor. Slot is a vanilla slot string like 'slot.armor.head', 'slot.armor.chest', 'slot.armor.legs', 'slot.armor.feet'.

struct WheatItem #

struct WheatItem {
	SimpleItem
}

WheatItem is the class for raw 'minecraft:wheat'.

fn (WheatItem) use_on_block_result #

fn (i WheatItem) use_on_block_result(block_name string, meta int) ?UseOnBlockResult