Package cn.nukkit.item
Class RuntimeItemMapping
java.lang.Object
cn.nukkit.item.RuntimeItemMapping
Responsible for mapping item full ids, item network ids and item namespaced ids between each other.
- A full id is a combination of item id and item damage. The way they are combined may change in future, so you should not combine them by yourself and neither store them permanently. It's mainly used to preserve backward compatibility with plugins that don't support namespaced ids.
- A network id is an id that is used to communicated with the client, it may change between executions of the same server version depending on how the plugins are setup.
- A namespaced id is the new way Mojang saves the ids, a string like
minecraft:stone
. It may change in Minecraft updates but tends to be permanent, unless Mojang decides to change them for some random reasons...
-
Constructor Summary
ConstructorDescriptionRuntimeItemMapping
(byte[] itemDataPalette, it.unimi.dsi.fastutil.ints.Int2IntMap legacyNetworkMap, it.unimi.dsi.fastutil.ints.Int2IntMap networkLegacyMap) Deprecated.RuntimeItemMapping
(byte[] itemDataPalette, it.unimi.dsi.fastutil.ints.Int2IntMap legacyNetworkMap, it.unimi.dsi.fastutil.ints.Int2IntMap networkLegacyMap, Map<String, Integer> namespaceNetworkMap, it.unimi.dsi.fastutil.ints.Int2ObjectMap<String> networkNamespaceMap) Deprecated.RuntimeItemMapping
(Collection<RuntimeItems.Entry> entries) -
Method Summary
Modifier and TypeMethodDescriptionvoid
deleteCustomBlock
(List<CustomBlock> blocks) void
deleteCustomItem
(ItemCustom itemCustom) getItemByNamespaceId
(String namespaceId, int amount) Creates a new instance of the respectiveItem
by the namespaced id.byte[]
int
getLegacyFullId
(int networkId) Returns the full id of a given network id.getNamespacedIdByNetworkId
(int networkId) Returns the namespaced id of a given network id.int
getNetworkFullId
(Item item) Returns the network id based on the full id of the given item.getNetworkIdByNamespaceId
(String namespaceId) Returns the network id of a given namespaced id.void
registerCustomBlock
(List<CustomBlock> blocks) void
registerCustomItem
(ItemCustom itemCustom) void
void
registerNamespacedIdItem
(Class<? extends StringItem> item) void
registerNamespacedIdItem
(String namespacedId, Constructor<? extends Item> constructor)
-
Constructor Details
-
RuntimeItemMapping
@Since("1.4.0.0-PN") @PowerNukkitOnly @Deprecated public RuntimeItemMapping(byte[] itemDataPalette, it.unimi.dsi.fastutil.ints.Int2IntMap legacyNetworkMap, it.unimi.dsi.fastutil.ints.Int2IntMap networkLegacyMap) Deprecated. -
RuntimeItemMapping
@PowerNukkitOnly @Since("1.4.0.0-PN") @Deprecated public RuntimeItemMapping(byte[] itemDataPalette, it.unimi.dsi.fastutil.ints.Int2IntMap legacyNetworkMap, it.unimi.dsi.fastutil.ints.Int2IntMap networkLegacyMap, Map<String, Integer> namespaceNetworkMap, it.unimi.dsi.fastutil.ints.Int2ObjectMap<String> networkNamespaceMap) Deprecated. -
RuntimeItemMapping
@PowerNukkitXOnly @Since("1.6.0.0-PNX") public RuntimeItemMapping(Collection<RuntimeItems.Entry> entries)
-
-
Method Details
-
registerCustomItem
-
deleteCustomItem
-
registerCustomBlock
-
deleteCustomBlock
-
getNetworkFullId
Returns the network id based on the full id of the given item.- Parameters:
item
- Given item- Returns:
- The network id
- Throws:
IllegalArgumentException
- If the mapping of the full id to the network id is unknown
-
getLegacyFullId
Returns the full id of a given network id.- Parameters:
networkId
- The given network id- Returns:
- The full id
- Throws:
IllegalArgumentException
- If the mapping of the full id to the network id is unknown
-
getItemDataPalette
-
getNamespacedIdByNetworkId
@PowerNukkitOnly @Since("1.4.0.0-PN") @Nullable public String getNamespacedIdByNetworkId(int networkId) Returns the namespaced id of a given network id.- Parameters:
networkId
- The given network id- Returns:
- The namespace id or
null
if it is unknown
-
getNetworkIdByNamespaceId
@PowerNukkitOnly @Since("1.4.0.0-PN") @Nonnull public OptionalInt getNetworkIdByNamespaceId(@Nonnull String namespaceId) Returns the network id of a given namespaced id.- Parameters:
namespaceId
- The given namespaced id- Returns:
- A network id wrapped in
OptionalInt
or an emptyOptionalInt
if it is unknown
-
getItemByNamespaceId
@PowerNukkitOnly @Since("1.4.0.0-PN") @Nonnull public Item getItemByNamespaceId(@Nonnull String namespaceId, int amount) Creates a new instance of the respectiveItem
by the namespaced id.- Parameters:
namespaceId
- The namespaced idamount
- How many items will be in the stack.- Returns:
- The correct
Item
instance with the write item id and item damage values. - Throws:
IllegalArgumentException
- If there are unknown mappings in the process.
-
registerNamespacedIdItem
@PowerNukkitOnly @Since("FUTURE") public void registerNamespacedIdItem(@Nonnull String namespacedId, @Nonnull Constructor<? extends Item> constructor) -
registerNamespacedIdItem
-
registerNamespacedIdItem
@PowerNukkitOnly @Since("FUTURE") public void registerNamespacedIdItem(@Nonnull Class<? extends StringItem> item)
-