net.minestom.server.item.ItemComponent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of minestom-snapshots Show documentation
Show all versions of minestom-snapshots Show documentation
1.20.4 Lightweight Minecraft server
package net.minestom.server.item;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.util.RGBLike;
import net.minestom.server.color.Color;
import net.minestom.server.color.DyeColor;
import net.minestom.server.component.DataComponent;
import net.minestom.server.component.DataComponentMap;
import net.minestom.server.item.component.*;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.utils.NamespaceID;
import net.minestom.server.utils.Unit;
import net.minestom.server.utils.collection.ObjectArray;
import net.minestom.server.utils.nbt.BinaryTagSerializer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public final class ItemComponent {
// Note that even non-networked components are registered here as they still contribute to the component ID counter.
// The order in this file determines the component protocol IDs, so it is important to match the client.
static final Map> NAMESPACES = new HashMap<>(32);
static final ObjectArray> IDS = ObjectArray.singleThread(32);
public static final DataComponent CUSTOM_DATA = register("custom_data", CustomData.NETWORK_TYPE, CustomData.NBT_TYPE);
public static final DataComponent MAX_STACK_SIZE = register("max_stack_size", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
public static final DataComponent MAX_DAMAGE = register("max_damage", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
public static final DataComponent DAMAGE = register("damage", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
public static final DataComponent UNBREAKABLE = register("unbreakable", Unbreakable.NETWORK_TYPE, Unbreakable.NBT_TYPE);
public static final DataComponent CUSTOM_NAME = register("custom_name", NetworkBuffer.COMPONENT, BinaryTagSerializer.JSON_COMPONENT);
public static final DataComponent ITEM_NAME = register("item_name", NetworkBuffer.COMPONENT, BinaryTagSerializer.JSON_COMPONENT);
public static final DataComponent> LORE = register("lore", NetworkBuffer.COMPONENT.list(256), BinaryTagSerializer.JSON_COMPONENT.list());
public static final DataComponent RARITY = register("rarity", ItemRarity.NETWORK_TYPE, ItemRarity.NBT_TYPE);
public static final DataComponent ENCHANTMENTS = register("enchantments", EnchantmentList.NETWORK_TYPE, EnchantmentList.NBT_TYPE);
public static final DataComponent CAN_PLACE_ON = register("can_place_on", BlockPredicates.NETWORK_TYPE, BlockPredicates.NBT_TYPE);
public static final DataComponent CAN_BREAK = register("can_break", BlockPredicates.NETWORK_TYPE, BlockPredicates.NBT_TYPE);
public static final DataComponent ATTRIBUTE_MODIFIERS = register("attribute_modifiers", AttributeList.NETWORK_TYPE, AttributeList.NBT_TYPE);
public static final DataComponent CUSTOM_MODEL_DATA = register("custom_model_data", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
public static final DataComponent HIDE_ADDITIONAL_TOOLTIP = register("hide_additional_tooltip", NetworkBuffer.UNIT, BinaryTagSerializer.UNIT);
public static final DataComponent HIDE_TOOLTIP = register("hide_tooltip", NetworkBuffer.UNIT, BinaryTagSerializer.UNIT);
public static final DataComponent REPAIR_COST = register("repair_cost", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
public static final DataComponent CREATIVE_SLOT_LOCK = register("creative_slot_lock", NetworkBuffer.UNIT, null);
public static final DataComponent ENCHANTMENT_GLINT_OVERRIDE = register("enchantment_glint_override", NetworkBuffer.BOOLEAN, BinaryTagSerializer.BOOLEAN);
public static final DataComponent INTANGIBLE_PROJECTILE = register("intangible_projectile", null, BinaryTagSerializer.UNIT);
public static final DataComponent FOOD = register("food", Food.NETWORK_TYPE, Food.NBT_TYPE);
public static final DataComponent FIRE_RESISTANT = register("fire_resistant", NetworkBuffer.UNIT, BinaryTagSerializer.UNIT);
public static final DataComponent TOOL = register("tool", Tool.NETWORK_TYPE, Tool.NBT_TYPE);
public static final DataComponent STORED_ENCHANTMENTS = register("stored_enchantments", EnchantmentList.NETWORK_TYPE, EnchantmentList.NBT_TYPE);
public static final DataComponent DYED_COLOR = register("dyed_color", DyedItemColor.NETWORK_TYPE, DyedItemColor.NBT_TYPE);
public static final DataComponent MAP_COLOR = register("map_color", Color.NETWORK_TYPE, Color.NBT_TYPE);
public static final DataComponent MAP_ID = register("map_id", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
public static final DataComponent MAP_DECORATIONS = register("map_decorations", null, MapDecorations.NBT_TYPE);
public static final DataComponent MAP_POST_PROCESSING = register("map_post_processing", MapPostProcessing.NETWORK_TYPE, null);
public static final DataComponent> CHARGED_PROJECTILES = register("charged_projectiles", ItemStack.NETWORK_TYPE.list(Short.MAX_VALUE), BinaryTagSerializer.ITEM.list());
public static final DataComponent> BUNDLE_CONTENTS = register("bundle_contents", ItemStack.NETWORK_TYPE.list(Short.MAX_VALUE), BinaryTagSerializer.ITEM.list());
public static final DataComponent POTION_CONTENTS = register("potion_contents", PotionContents.NETWORK_TYPE, PotionContents.NBT_TYPE);
public static final DataComponent SUSPICIOUS_STEW_EFFECTS = register("suspicious_stew_effects", SuspiciousStewEffects.NETWORK_TYPE, SuspiciousStewEffects.NBT_TYPE);
public static final DataComponent WRITABLE_BOOK_CONTENT = register("writable_book_content", WritableBookContent.NETWORK_TYPE, WritableBookContent.NBT_TYPE);
public static final DataComponent WRITTEN_BOOK_CONTENT = register("written_book_content", WrittenBookContent.NETWORK_TYPE, WrittenBookContent.NBT_TYPE);
public static final DataComponent TRIM = register("trim", ArmorTrim.NETWORK_TYPE, ArmorTrim.NBT_TYPE);
public static final DataComponent DEBUG_STICK_STATE = register("debug_stick_state", null, DebugStickState.NBT_TYPE);
public static final DataComponent ENTITY_DATA = register("entity_data", CustomData.NETWORK_TYPE, CustomData.NBT_TYPE);
public static final DataComponent BUCKET_ENTITY_DATA = register("bucket_entity_data", CustomData.NETWORK_TYPE, CustomData.NBT_TYPE);
public static final DataComponent BLOCK_ENTITY_DATA = register("block_entity_data", CustomData.NETWORK_TYPE, CustomData.NBT_TYPE);
public static final DataComponent INSTRUMENT = register("instrument", NetworkBuffer.STRING, BinaryTagSerializer.STRING);
public static final DataComponent OMINOUS_BOTTLE_AMPLIFIER = register("ominous_bottle_amplifier", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
public static final DataComponent JUKEBOX_PLAYABLE = register("jukebox_playable", JukeboxPlayable.NETWORK_TYPE, JukeboxPlayable.NBT_TYPE);
public static final DataComponent> RECIPES = register("recipes", NetworkBuffer.STRING.list(Short.MAX_VALUE), BinaryTagSerializer.STRING.list());
public static final DataComponent LODESTONE_TRACKER = register("lodestone_tracker", LodestoneTracker.NETWORK_TYPE, LodestoneTracker.NBT_TYPE);
public static final DataComponent FIREWORK_EXPLOSION = register("firework_explosion", FireworkExplosion.NETWORK_TYPE, FireworkExplosion.NBT_TYPE);
public static final DataComponent FIREWORKS = register("fireworks", FireworkList.NETWORK_TYPE, FireworkList.NBT_TYPE);
public static final DataComponent PROFILE = register("profile", HeadProfile.NETWORK_TYPE, HeadProfile.NBT_TYPE);
public static final DataComponent NOTE_BLOCK_SOUND = register("note_block_sound", NetworkBuffer.STRING, BinaryTagSerializer.STRING);
public static final DataComponent BANNER_PATTERNS = register("banner_patterns", BannerPatterns.NETWORK_TYPE, BannerPatterns.NBT_TYPE);
public static final DataComponent BASE_COLOR = register("base_color", DyeColor.NETWORK_TYPE, DyeColor.NBT_TYPE);
public static final DataComponent POT_DECORATIONS = register("pot_decorations", PotDecorations.NETWORK_TYPE, PotDecorations.NBT_TYPE);
public static final DataComponent> CONTAINER = register("container", ItemStack.NETWORK_TYPE.list(256), BinaryTagSerializer.ITEM.list());
public static final DataComponent BLOCK_STATE = register("block_state", ItemBlockState.NETWORK_TYPE, ItemBlockState.NBT_TYPE);
public static final DataComponent> BEES = register("bees", Bee.NETWORK_TYPE.list(Short.MAX_VALUE), Bee.NBT_TYPE.list());
public static final DataComponent LOCK = register("lock", null, BinaryTagSerializer.STRING);
public static final DataComponent CONTAINER_LOOT = register("container_loot", null, SeededContainerLoot.NBT_TYPE);
public static final NetworkBuffer.Type PATCH_NETWORK_TYPE = DataComponentMap.patchNetworkType(ItemComponent::fromId);
public static final BinaryTagSerializer PATCH_NBT_TYPE = DataComponentMap.patchNbtType(ItemComponent::fromId, ItemComponent::fromNamespaceId);
public static @Nullable DataComponent> fromNamespaceId(@NotNull String namespaceId) {
return NAMESPACES.get(namespaceId);
}
public static @Nullable DataComponent> fromNamespaceId(@NotNull NamespaceID namespaceId) {
return fromNamespaceId(namespaceId.asString());
}
public static @Nullable DataComponent> fromId(int id) {
return IDS.get(id);
}
public static @NotNull Collection> values() {
return NAMESPACES.values();
}
static DataComponent register(@NotNull String name, @Nullable NetworkBuffer.Type network, @Nullable BinaryTagSerializer nbt) {
DataComponent impl = DataComponent.createHeadless(NAMESPACES.size(), NamespaceID.from(name), network, nbt);
NAMESPACES.put(impl.name(), impl);
IDS.set(impl.id(), impl);
return impl;
}
private ItemComponent() {
}
}