Class RuntimeItemMapping

java.lang.Object
cn.nukkit.item.RuntimeItemMapping

@Since("1.4.0.0-PN") public class RuntimeItemMapping extends Object
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 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

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public void registerCustomItem(CustomItem customItem, Supplier<Item> constructor)
    • deleteCustomItem

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public void deleteCustomItem(CustomItem customItem)
    • registerCustomBlock

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public void registerCustomBlock(List<CustomBlock> blocks)
    • deleteCustomBlock

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public void deleteCustomBlock(List<CustomBlock> blocks)
    • getNetworkFullId

      @PowerNukkitOnly @Since("1.4.0.0-PN") public int getNetworkFullId(Item item)
      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

      @PowerNukkitOnly @Since("1.4.0.0-PN") public int getLegacyFullId(int networkId)
      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

      @PowerNukkitOnly @Since("1.4.0.0-PN") public byte[] 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") @NotNull public OptionalInt getNetworkIdByNamespaceId(@NotNull 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 empty OptionalInt if it is unknown
    • getItemByNamespaceId

      @PowerNukkitOnly @Since("1.4.0.0-PN") @NotNull public Item getItemByNamespaceId(@NotNull String namespaceId, int amount)
      Creates a new instance of the respective Item by the namespaced id.
      Parameters:
      namespaceId - The namespaced id
      amount - 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 public void registerNamespacedIdItem(@NotNull Class<? extends StringItem> item)
    • registerNamespacedIdItem

      @PowerNukkitOnly public void registerNamespacedIdItem(@NotNull String namespacedId, @NotNull Constructor<? extends Item> constructor)
    • registerNamespacedIdItem

      @PowerNukkitOnly public void registerNamespacedIdItem(@NotNull String namespacedId, @NotNull Supplier<Item> constructor)