Package cn.nukkit.item
Class RuntimeItemMapping
java.lang.Object
cn.nukkit.item.RuntimeItemMapping
这个类用于将旧版本物品以id:damage形式转换到新版本物品无damage值(0)的形式,以及提供
StartGamePacket
中item Palette的作用例如在1.19.70中,不同颜色的羊毛由wool:color damage变成了minecraft:white_wool,minecraft:orange_wool这类字面量形式。
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final record
static final record
The type Runtime entry. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
deleteCustomBlock
(List<CustomBlock> blocks) void
deleteCustomItem
(CustomItem customItem) fromIdentifier
(String identifier) From identifier to get legacy entry.According to item_mappings.jsonfromRuntime
(int runtimeId) From runtimeId to get legacy item entry.getItemByNamespaceId
(String namespaceId, int amount) Creates a new instance of the respectiveItem
by the namespaced id.byte[]
byte[]
Get item palette 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
getNetworkId
(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
(CustomItem customItem, Supplier<Item> constructor) void
registerNamespacedIdItem
(Class<? extends StringItem> item) void
registerNamespacedIdItem
(String namespacedId, Constructor<? extends Item> constructor) void
registerNamespacedIdItem
(String namespacedId, Supplier<Item> constructor) toRuntime
(int id, int meta) from legacy item id and meta value to get runtimeId
-
Constructor Details
-
RuntimeItemMapping
-
-
Method Details
-
fromRuntime
From runtimeId to get legacy item entry.- Parameters:
runtimeId
- the runtime id- Returns:
- the legacy entry
-
toRuntime
from legacy item id and meta value to get runtimeId- Parameters:
id
- the idmeta
- the meta- Returns:
- the runtime entry
-
fromIdentifier
From identifier to get legacy entry.According to item_mappings.json- Parameters:
identifier
- the identifier- Returns:
- the legacy entry
-
getItemPalette
public byte[] getItemPalette()Get item palette byte [ ].- Returns:
- the byte [ ]
-
registerCustomItem
@PowerNukkitXOnly @Since("1.6.0.0-PNX") public void registerCustomItem(CustomItem customItem, Supplier<Item> constructor) -
deleteCustomItem
-
registerCustomBlock
-
deleteCustomBlock
-
getNetworkId
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") @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 emptyOptionalInt
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 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
@PowerNukkitXOnly @Since("1.19.70-r2") 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) -
getBlockMapping
@DoNotModify @Since("1.19.80-r1") @PowerNukkitXOnly public static com.google.common.collect.BiMap<String,String> getBlockMapping()
-