Documentation ¶
Index ¶
- Constants
- Variables
- func EmitNBT(compound *gonbt.Compound, stack *Stack)
- func FromKey(key string) (int16, int16)
- func GetKey(id int16, data int16) string
- func ParseNBT(compound *gonbt.Compound, stack *Stack)
- type Manager
- func (registry *Manager) Deregister(stringId string) bool
- func (registry *Manager) DeregisterCreativeType(stringId string) bool
- func (registry *Manager) Get(stringId string, count int) (*Stack, bool)
- func (registry *Manager) GetCreativeTypes() map[string]Type
- func (registry *Manager) GetTypes() map[string]Type
- func (registry *Manager) IsCreativeTypeRegistered(stringId string) bool
- func (registry *Manager) IsRegistered(stringId string) bool
- func (registry *Manager) Register(t Type, registerCreative bool)
- func (registry *Manager) RegisterCreativeType(t Type)
- func (registry *Manager) RegisterDefaults()
- func (registry *Manager) RegisterMultiple(types []Type, registerCreative bool)
- type Stack
- func (stack Stack) CanStackOn(stack2 *Stack) (bool, int)
- func (stack Stack) Equals(stack2 *Stack) bool
- func (stack Stack) EqualsEnchantments(stack2 *Stack) bool
- func (stack Stack) EqualsExact(stack2 *Stack) bool
- func (stack Stack) EqualsLore(stack2 *Stack) bool
- func (stack Stack) GetDisplayName() string
- func (stack *Stack) StackOn(stack2 *Stack) (success bool, notZero bool, stackCount int)
- func (stack Stack) String() string
- type Type
Constants ¶
const ( Display = "display" DisplayName = "Name" DisplayLore = "Lore" Ench = "ench" EnchId = "id" EnchLevel = "lvl" )
Variables ¶
var DefaultManager = NewManager()
DefaultManager is the default item manager. The default items are registered upon the init function.
var IdToType = map[string]Type{ GetKey(0, 0): DefaultManager.stringIds["minecraft:air"], GetKey(1, 0): DefaultManager.stringIds["minecraft:stone"], }
IdToState is a map used to convert an ID + item data combination to item type. The keys of these maps are created using the getKey method.
var TypeToId = map[string]string{ fmt.Sprint(DefaultManager.stringIds["minecraft:air"]): GetKey(0, 0), fmt.Sprint(DefaultManager.stringIds["minecraft:stone"]): GetKey(1, 0), }
TypeToId is a map used to convert a block state to an ID + data combination.
Functions ¶
func EmitNBT ¶
EmitNBT implements default behaviour for emitting NBT. This is the default function passed in for `NBTEmitFunction`. The compound first gets set to the cached compound of the item type.
func FromKey ¶
FromKey attempts to retrieve an ID + data combination, from a string created with getKey. Any errors that occur are logged to the default logger.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager supplies helper functions for item type registering. Item types get registered by their string ID, and can be retrieved using these.
func NewManager ¶
func NewManager() *Manager
NewManager returns a new item registry. New registries will not have default items registered. Default registries should be registered using RegisterDefaults.
func (*Manager) Deregister ¶
Deregister deregisters an item type, by its string ID in the stringIds map. Returns true if the item type was deregistered successfully.
func (*Manager) DeregisterCreativeType ¶
DeregisterCreativeType deregisters a creative item. Creative items can be deregistered using the string ID of that particular item. A bool gets returned to indicate success of the action.
func (*Manager) Get ¶
Get attempts to return a new item stack by a string ID, and sets the stack's count to the count given. A bool gets returned to indicate whether any item was found. If no item type could be found with the given string ID, a default air item and a bool false gets returned.
func (*Manager) GetCreativeTypes ¶
GetCreativeTypes returns all creative items. A map gets returned in the form of stringId => Type.
func (*Manager) GetTypes ¶
GetTypes returns all registered item types. Item types are returned in a map of the form stringId => Type.
func (*Manager) IsCreativeTypeRegistered ¶
IsCreativeTypeRegistered checks if an item type is registered to the creative inventory map.
func (*Manager) IsRegistered ¶
IsRegistered checks if an item type is registered, by its string ID in the stringIds map. Returns true if the string ID is registered.
func (*Manager) Register ¶
Register registers a new item type. The item type will be registered to the stringIds map. Registered item types can be deregistered, using the Deregister functions. If registerCreative is set to true, the item will also be registered as creative item.
func (*Manager) RegisterCreativeType ¶
RegisterCreativeType registers an item type, to the creative items map. All creative items will be displayed, in the creative inventory.
func (*Manager) RegisterDefaults ¶
func (registry *Manager) RegisterDefaults()
RegisterDefaults registers all default items. This function should be called immediately after NewManager, in order to register the proper default items.
func (*Manager) RegisterMultiple ¶
RegisterMultiple registers multiple types at once. Item types will be registered to the stringIds map, and can be deregistered separately from each other. If registerCreative is set to true, the items will also be registered as creative item.
type Stack ¶
type Stack struct { // Stack embeds Type. Therefore functions // in the Type struct may also be used in Stack. Type // Count is the current count of an item. // The count of an item is usually 16/64. Count int // Durability is the current left durability of the stack. // Durability on non-breakable item types has no effect. Durability int16 // DisplayName is the display name of an item. // If a non-empty display name has been set, // this name will be displayed, // rather than the original Type name. DisplayName string // Lore is the displayed lore of an item. // The lore is displayed under the item, // when hovering over it in the inventory. Lore []string // contains filtered or unexported fields }
Stack is an instance of a given amount of items. A stack may also be referred to as an item instance. A stack holds additional information about an item, that could differ on an every item base.
func (Stack) CanStackOn ¶
CanStackWith checks if two stacks can stack with each other. A bool is returned which indicates if the two can stack, and an integer is returned which specifies the count of of the item that can still be stacked on this stack. The returned integer may be 0, if the stack is already at the max stack size.
func (Stack) Equals ¶
Equals checks if two item stacks are considered equal. Equals checks if the item type is equal and if the count is equal. For more deep checks, EqualsExact should be used.
func (Stack) EqualsEnchantments ¶
EqualsEnchantments checks if enchantments of two item stacks are equal to each other.
func (Stack) EqualsExact ¶
EqualsExact checks if two item stacks are considered exact equal. EqualsExact does all the checks Equals does, and checks if the lore and enchantments are equal.
func (Stack) EqualsLore ¶
EqualsLore checks if the lore of two item stacks are equal to each other.
func (Stack) GetDisplayName ¶
GetDisplayName returns the displayed name of an item. The custom name of the item always gets returned, unless the custom name is empty; Then the actual item type name gets returned.
func (*Stack) StackOn ¶
StackOn attempts to stack a stack on another stack. A first bool is returned which indicates if the two stacked successfully. A second bool is returned which is true as long as the item stack is not at count 0. An integer is returned to specify the count of items that got stacked on the other stack. The integer returned may be 0, which happens if the other stack is already at max stack size.
type Type ¶
type Type struct { // NBTParseFunction gets called once NBT is attempted // to be decoded for an item. The compound passed is the // compound the NBT data should be coming out of, and the stack // passed is the stack that encapsulates this type. NBTParseFunction func(compound *gonbt.Compound, stack *Stack) // NBTEmitFunction gets called once NBT is attempted // to be obtained from an item. The compound passed is the // compound the NBT data should be going into, and the stack // passed is the stack that encapsulates this type. NBTEmitFunction func(compound *gonbt.Compound, stack *Stack) // contains filtered or unexported fields }
Type is the type that identifies an item. Types contain a string ID, which can be used to construct a new item stack.
func NewBreakable ¶
NewType returns a new breakable type. The given string ID is used as identifier, and all properties are immune in the type. Type names prefixed with `minecraft:` get their name set to it without the prefix. Types get the default NBT parsing and emitting functions.
func NewType ¶
NewType returns a new non-breakable type. The given string ID is used as identifier, and all properties are immune in the type. Type names prefixed with `minecraft:` get their name set to it without the prefix. Types get the default NBT parsing and emitting functions.
func (Type) Equals ¶
Equals checks if two item types are considered equal. Item types are merely checked against each other's string IDs, but should not require more comparisons.
func (Type) GetAuxValue ¶
GetAuxValue returns the aux value for the item stack with item data. This aux value is used for writing stacks over network.
func (Type) GetId ¶
GetId returns the string ID of an item type. StringIds are a string used as an identifier, in order to lookup items by it.
func (Type) GetMaximumStackSize ¶
GetMaximumStackSize returns the maximum stack size of an item. Item stacks of the type are not limited to this size themselves, but are when set into an inventory.
func (Type) GetName ¶
GetName returns the readable name of an item type. This name may contains spaces.
func (Type) IsBreakable ¶
IsBreakable checks if an item is breakable. Breakable items use data fields for durability, but we separate them for forward compatibility sake.