github.com/df-mc/dragonfly@v0.9.13/server/block/enchanting_table.go (about)

     1  package block
     2  
     3  import (
     4  	"github.com/df-mc/dragonfly/server/block/cube"
     5  	"github.com/df-mc/dragonfly/server/block/model"
     6  	"github.com/df-mc/dragonfly/server/item"
     7  	"github.com/df-mc/dragonfly/server/world"
     8  )
     9  
    10  // EnchantingTable is a block that allows players to spend their experience point levels to enchant tools, weapons,
    11  // books, armor, and certain other items.
    12  type EnchantingTable struct {
    13  	transparent
    14  	bassDrum
    15  	sourceWaterDisplacer
    16  }
    17  
    18  // Model ...
    19  func (e EnchantingTable) Model() world.BlockModel {
    20  	return model.EnchantingTable{}
    21  }
    22  
    23  // BreakInfo ...
    24  func (e EnchantingTable) BreakInfo() BreakInfo {
    25  	return newBreakInfo(5, pickaxeHarvestable, pickaxeEffective, oneOf(e)).withBlastResistance(6000)
    26  }
    27  
    28  // SideClosed ...
    29  func (EnchantingTable) SideClosed(cube.Pos, cube.Pos, *world.World) bool {
    30  	return false
    31  }
    32  
    33  // LightEmissionLevel ...
    34  func (EnchantingTable) LightEmissionLevel() uint8 {
    35  	return 7
    36  }
    37  
    38  // Activate ...
    39  func (EnchantingTable) Activate(pos cube.Pos, _ cube.Face, _ *world.World, u item.User, _ *item.UseContext) bool {
    40  	if opener, ok := u.(ContainerOpener); ok {
    41  		opener.OpenBlockContainer(pos)
    42  		return true
    43  	}
    44  	return false
    45  }
    46  
    47  // EncodeItem ...
    48  func (EnchantingTable) EncodeItem() (name string, meta int16) {
    49  	return "minecraft:enchanting_table", 0
    50  }
    51  
    52  // EncodeBlock ...
    53  func (EnchantingTable) EncodeBlock() (string, map[string]any) {
    54  	return "minecraft:enchanting_table", nil
    55  }
    56  
    57  // EncodeNBT is used to encode the block to NBT, so that the enchanting table book will be rendered properly client-side.
    58  // The actual rotation value doesn't need to be set in the NBT, we just need to write the default NBT for the block.
    59  func (e EnchantingTable) EncodeNBT() map[string]any {
    60  	return map[string]any{"id": "EnchantTable"}
    61  }
    62  
    63  // DecodeNBT is used to implement world.NBTer.
    64  func (e EnchantingTable) DecodeNBT(map[string]any) any {
    65  	return e
    66  }