items

package
v0.0.0-...-b9cfb1f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 8, 2019 License: GPL-3.0 Imports: 6 Imported by: 8

Documentation

Index

Constants

View Source
const (
	Display     = "display"
	DisplayName = "Name"
	DisplayLore = "Lore"

	Ench      = "ench"
	EnchId    = "id"
	EnchLevel = "lvl"
)

Variables

View Source
var DefaultManager = NewManager()

DefaultManager is the default item manager. The default items are registered upon the init function.

View Source
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.

View Source
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

func EmitNBT(compound *gonbt.Compound, stack *Stack)

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

func FromKey(key string) (int16, int16)

FromKey attempts to retrieve an ID + data combination, from a string created with getKey. Any errors that occur are logged to the default logger.

func GetKey

func GetKey(id int16, data int16) string

getKey returns the key of an ID + data combination, which is used in both maps.

func ParseNBT

func ParseNBT(compound *gonbt.Compound, stack *Stack)

ParseNBT implements default behaviour for parsing NBT. This is the default function passed in for `NBTParseFunction`. The cached NBT gets set when parsing NBT.

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

func (registry *Manager) Deregister(stringId string) bool

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

func (registry *Manager) DeregisterCreativeType(stringId string) bool

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

func (registry *Manager) Get(stringId string, count int) (*Stack, bool)

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

func (registry *Manager) GetCreativeTypes() map[string]Type

GetCreativeTypes returns all creative items. A map gets returned in the form of stringId => Type.

func (*Manager) GetTypes

func (registry *Manager) GetTypes() map[string]Type

GetTypes returns all registered item types. Item types are returned in a map of the form stringId => Type.

func (*Manager) IsCreativeTypeRegistered

func (registry *Manager) IsCreativeTypeRegistered(stringId string) bool

IsCreativeTypeRegistered checks if an item type is registered to the creative inventory map.

func (*Manager) IsRegistered

func (registry *Manager) IsRegistered(stringId string) bool

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

func (registry *Manager) Register(t Type, registerCreative bool)

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

func (registry *Manager) RegisterCreativeType(t Type)

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

func (registry *Manager) RegisterMultiple(types []Type, registerCreative bool)

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

func (stack Stack) CanStackOn(stack2 *Stack) (bool, int)

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

func (stack Stack) Equals(stack2 *Stack) bool

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

func (stack Stack) EqualsEnchantments(stack2 *Stack) bool

EqualsEnchantments checks if enchantments of two item stacks are equal to each other.

func (Stack) EqualsExact

func (stack Stack) EqualsExact(stack2 *Stack) bool

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

func (stack Stack) EqualsLore(stack2 *Stack) bool

EqualsLore checks if the lore of two item stacks are equal to each other.

func (Stack) GetDisplayName

func (stack Stack) GetDisplayName() string

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

func (stack *Stack) StackOn(stack2 *Stack) (success bool, notZero bool, stackCount int)

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.

func (Stack) String

func (stack Stack) String() string

String returns a string representation of a stack. It implements fmt.Stringer, and returns a string as such: x29 Emerald (minecraft:emerald)

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

func NewBreakable(stringId string) Type

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

func NewType(stringId string) Type

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

func (t Type) Equals(t2 Type) bool

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

func (t Type) GetAuxValue(stack *Stack, data int16) int32

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

func (t Type) GetId() string

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

func (t Type) GetMaximumStackSize() int

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

func (t Type) GetName() string

GetName returns the readable name of an item type. This name may contains spaces.

func (Type) IsBreakable

func (t Type) IsBreakable() bool

IsBreakable checks if an item is breakable. Breakable items use data fields for durability, but we separate them for forward compatibility sake.

func (Type) String

func (t Type) String() string

String returns a string representation of a type. It implements fmt.Stringer, and returns a string as such: Emerald(minecraft:emerald)

Directories

Path Synopsis
io

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL