Documentation

ItemFactory
in package
Uses SingletonTrait

Manages deserializing item types from their legacy ID/metadata.

This is primarily needed for loading inventories saved in the world (or playerdata storage).

Table of Contents

$instance  : self|null
$list  : array<string|int, Item>
__construct()  : mixed
air()  : Item
get()  : Item
getAllRegistered()  : array<string|int, Item>
getInstance()  : self
isRegistered()  : bool
Returns whether the specified item ID is already registered in the item factory.
register()  : void
Maps an item type to its corresponding ID. This is necessary to ensure that the item is correctly loaded when reading data from disk storage.
remap()  : void
reset()  : void
setInstance()  : void
getListOffset()  : int
itemToBlockId()  : int
make()  : self
registerArmorItems()  : void
registerSpawnEggs()  : void
registerTierToolItems()  : void

Properties

Methods

__construct()

public __construct() : mixed
Return values
mixed

get()

public get(int $id[, int $meta = 0 ][, int $count = 1 ][, CompoundTag|null $tags = null ]) : Item
Parameters
$id : int
$meta : int = 0
$count : int = 1
$tags : CompoundTag|null = null
Tags
deprecated

This method should ONLY be used for deserializing data, e.g. from a config or database. For all other purposes, use VanillaItems.

see
VanillaItems

Deserializes an item from the provided legacy ID, legacy meta, count and NBT.

throws
InvalidArgumentException
throws
NbtException
Return values
Item

getAllRegistered()

public getAllRegistered() : array<string|int, Item>
Return values
array<string|int, Item>

getInstance()

public static getInstance() : self
Return values
self

isRegistered()

Returns whether the specified item ID is already registered in the item factory.

public isRegistered(int $id[, int $variant = 0 ]) : bool
Parameters
$id : int
$variant : int = 0
Return values
bool

register()

Maps an item type to its corresponding ID. This is necessary to ensure that the item is correctly loaded when reading data from disk storage.

public register(Item $item[, bool $override = false ]) : void

NOTE: If you are registering a new item type, you will need to add it to the creative inventory yourself - it will not automatically appear there.

Parameters
$item : Item
$override : bool = false
Tags
throws
RuntimeException

if something attempted to override an already-registered item without specifying the $override parameter.

Return values
void

setInstance()

public static setInstance(self $instance) : void
Parameters
$instance : self
Return values
void

getListOffset()

private static getListOffset(int $id, int $variant) : int
Parameters
$id : int
$variant : int
Return values
int

itemToBlockId()

private static itemToBlockId(int $id) : int
Parameters
$id : int
Return values
int

registerArmorItems()

private registerArmorItems() : void
Return values
void

registerSpawnEggs()

private registerSpawnEggs() : void
Return values
void

registerTierToolItems()

private registerTierToolItems() : void
Return values
void

Search results