Контракты контента (v0.2)
Typed и классические поведения для блоков и предметов.
В этом разделе
Другие страницы раздела:
Поведения
- Используйте
ctx.RegisterBlock(content.DefineBlock(...))иcontent.DefineTypedBlock(...). - Для предметов:
content.DefineItem(...)иcontent.DefineTypedItem(...). - Есть интерфейсы RedstonePowerSource, RedstoneWire, RedstoneDiode/Connect.
- Light/Liquid/Falling/Replaceable пока в v0.2 часто объявляются как контракт без полного runtime-контента.
content-behaviors.go
ctx.RegisterBlock(content.DefineBlock("example:crate"). Container(27). Hardness(4). Tool("axe"). Drop(item.New("example:ruby").Stack()). OnInteract(func(event content.BlockContext) error { return nil }). Spec())ctx.RegisterItem(content.DefineItem("example:wand"). MaxCount(1). Component("minecraft:foil", true). OnUseOnBlock(func(event content.ItemContext) error { return event.World.SetBlock(event.Pos, block.New("gold_block").Block()) }). Spec())ctx.RegisterEffect(content.DefineEffect("example:focus"). BedrockID(200). Spec())