mirror of https://github.com/Minestom/Minestom.git
chore: trying to fix nightmare loop
This commit is contained in:
parent
93450a5d26
commit
6dd4b95980
|
@ -15,6 +15,7 @@ import net.minestom.server.event.server.ServerListPingEvent;
|
|||
import net.minestom.server.extras.lan.OpenToLAN;
|
||||
import net.minestom.server.extras.lan.OpenToLANConfig;
|
||||
import net.minestom.server.instance.block.BlockManager;
|
||||
import net.minestom.server.item.ItemComponent;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.item.Material;
|
||||
import net.minestom.server.network.packet.server.play.DeclareRecipesPacket;
|
||||
|
@ -32,13 +33,9 @@ public class Main {
|
|||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
|
||||
Class.forName("net.minestom.server.item.ItemComponent");
|
||||
Class.forName("net.minestom.server.item.ItemStack");
|
||||
Class.forName(ItemComponent.class.getName());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.err.println("Failed to load Minestom classes, make sure you are using the correct dependencies");
|
||||
return;
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
System.setProperty("minestom.experiment.pose-updates", "true");
|
||||
|
||||
|
|
|
@ -1,96 +1,74 @@
|
|||
package net.minestom.server.item;
|
||||
|
||||
import net.kyori.adventure.nbt.BinaryTag;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.color.Color;
|
||||
import net.minestom.server.item.component.*;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.registry.StaticProtocolObject;
|
||||
import net.minestom.server.utils.NamespaceID;
|
||||
import net.minestom.server.utils.nbt.BinaryTagSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static net.minestom.server.item.ItemComponentImpl.declare;
|
||||
import static net.minestom.server.item.ItemComponentTypeImpl.declare;
|
||||
|
||||
public sealed interface ItemComponent<T> extends StaticProtocolObject permits ItemComponentImpl {
|
||||
public final class ItemComponent {
|
||||
// Note that even non-networked components are declared here as they still contribute to the component ID counter.
|
||||
|
||||
ItemComponent<CustomData> CUSTOM_DATA = declare("custom_data", CustomData.NETWORK_TYPE, CustomData.NBT_TYPE);
|
||||
ItemComponent<Integer> MAX_STACK_SIZE = declare("max_stack_size", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
|
||||
ItemComponent<Integer> MAX_DAMAGE = declare("max_damage", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
|
||||
ItemComponent<Integer> DAMAGE = declare("damage", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
|
||||
ItemComponent<Unbreakable> UNBREAKABLE = declare("unbreakable", Unbreakable.NETWORK_TYPE, Unbreakable.NBT_TYPE);
|
||||
ItemComponent<Component> CUSTOM_NAME = declare("custom_name", NetworkBuffer.COMPONENT, BinaryTagSerializer.JSON_COMPONENT);
|
||||
ItemComponent<Component> ITEM_NAME = declare("item_name", NetworkBuffer.COMPONENT, BinaryTagSerializer.JSON_COMPONENT);
|
||||
ItemComponent<List<Component>> LORE = declare("lore", NetworkBuffer.COMPONENT.list(256), BinaryTagSerializer.JSON_COMPONENT.list());
|
||||
ItemComponent<ItemRarity> RARITY = declare("rarity", ItemRarity.NETWORK_TYPE, ItemRarity.NBT_TYPE);
|
||||
ItemComponent<EnchantmentList> ENCHANTMENTS = declare("enchantments", EnchantmentList.NETWORK_TYPE, EnchantmentList.NBT_TYPE);
|
||||
ItemComponent<Void> CAN_PLACE_ON = declare("can_place_on", null, null); //todo
|
||||
ItemComponent<Void> CAN_BREAK = declare("can_break", null, null); //todo
|
||||
ItemComponent<AttributeList> ATTRIBUTE_MODIFIERS = declare("attribute_modifiers", AttributeList.NETWORK_TYPE, AttributeList.NBT_TYPE);
|
||||
ItemComponent<Integer> CUSTOM_MODEL_DATA = declare("custom_model_data", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
|
||||
ItemComponent<Void> HIDE_ADDITIONAL_TOOLTIP = declare("hide_additional_tooltip", NetworkBuffer.NOTHING, BinaryTagSerializer.NOTHING);
|
||||
ItemComponent<Void> HIDE_TOOLTIP = declare("hide_tooltip", NetworkBuffer.NOTHING, BinaryTagSerializer.NOTHING);
|
||||
ItemComponent<Integer> REPAIR_COST = declare("repair_cost", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
|
||||
ItemComponent<Void> CREATIVE_SLOT_LOCK = declare("creative_slot_lock", NetworkBuffer.NOTHING, null);
|
||||
ItemComponent<Boolean> ENCHANTMENT_GLINT_OVERRIDE = declare("enchantment_glint_override", NetworkBuffer.BOOLEAN, BinaryTagSerializer.BOOLEAN);
|
||||
ItemComponent<Void> INTANGIBLE_PROJECTILE = declare("intangible_projectile", null, BinaryTagSerializer.NOTHING);
|
||||
ItemComponent<Void> FOOD = declare("food", null, null); //todo
|
||||
ItemComponent<Void> FIRE_RESISTANT = declare("fire_resistant", NetworkBuffer.NOTHING, BinaryTagSerializer.NOTHING);
|
||||
ItemComponent<Void> TOOL = declare("tool", null, null); //todo
|
||||
ItemComponent<EnchantmentList> STORED_ENCHANTMENTS = declare("stored_enchantments", EnchantmentList.NETWORK_TYPE, EnchantmentList.NBT_TYPE);
|
||||
ItemComponent<DyedItemColor> DYED_COLOR = declare("dyed_color", DyedItemColor.NETWORK_TYPE, DyedItemColor.NBT_TYPE);
|
||||
ItemComponent<Color> MAP_COLOR = declare("map_color", NetworkBuffer.COLOR, BinaryTagSerializer.INT.map(Color::new, Color::asRGB));
|
||||
ItemComponent<Integer> MAP_ID = declare("map_id", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
|
||||
ItemComponent<MapDecorations> MAP_DECORATIONS = declare("map_decorations", null, MapDecorations.NBT_TYPE);
|
||||
ItemComponent<MapPostProcessing> MAP_POST_PROCESSING = declare("map_post_processing", MapPostProcessing.NETWORK_TYPE, null);
|
||||
ItemComponent<List<ItemStack>> CHARGED_PROJECTILES = declare("charged_projectiles", ItemStack.NETWORK_TYPE.list(Short.MAX_VALUE), BinaryTagSerializer.ITEM.list());
|
||||
ItemComponent<List<ItemStack>> BUNDLE_CONTENTS = declare("bundle_contents", ItemStack.NETWORK_TYPE.list(Short.MAX_VALUE), BinaryTagSerializer.ITEM.list());
|
||||
ItemComponent<Void> POTION_CONTENTS = declare("potion_contents", null, null); //todo
|
||||
ItemComponent<Void> SUSPICIOUS_STEW_EFFECTS = declare("suspicious_stew_effects", null, null); //todo
|
||||
ItemComponent<WritableBookContent> WRITABLE_BOOK_CONTENT = declare("writable_book_content", WritableBookContent.NETWORK_TYPE, WritableBookContent.NBT_TYPE);
|
||||
ItemComponent<WrittenBookContent> WRITTEN_BOOK_CONTENT = declare("written_book_content", WrittenBookContent.NETWORK_TYPE, WrittenBookContent.NBT_TYPE);
|
||||
ItemComponent<Void> TRIM = declare("trim", null, null); //todo
|
||||
ItemComponent<Void> DEBUG_STICK_STATE = declare("debug_stick_state", null, null); //todo
|
||||
ItemComponent<CustomData> ENTITY_DATA = declare("entity_data", CustomData.NETWORK_TYPE, CustomData.NBT_TYPE);
|
||||
ItemComponent<CustomData> BUCKET_ENTITY_DATA = declare("bucket_entity_data", CustomData.NETWORK_TYPE, CustomData.NBT_TYPE);
|
||||
ItemComponent<CustomData> BLOCK_ENTITY_DATA = declare("block_entity_data", CustomData.NETWORK_TYPE, CustomData.NBT_TYPE);
|
||||
ItemComponent<Void> INSTRUMENT = declare("instrument", null, null); //todo
|
||||
ItemComponent<Integer> OMINOUS_BOTTLE_AMPLIFIER = declare("ominous_bottle_amplifier", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
|
||||
ItemComponent<List<String>> RECIPES = declare("recipes", NetworkBuffer.STRING.list(Short.MAX_VALUE), BinaryTagSerializer.STRING.list());
|
||||
ItemComponent<LodestoneTracker> LODESTONE_TRACKER = declare("lodestone_tracker", LodestoneTracker.NETWORK_TYPE, LodestoneTracker.NBT_TYPE);
|
||||
ItemComponent<FireworkExplosion> FIREWORK_EXPLOSION = declare("firework_explosion", FireworkExplosion.NETWORK_TYPE, FireworkExplosion.NBT_TYPE);
|
||||
ItemComponent<FireworkList> FIREWORKS = declare("fireworks", FireworkList.NETWORK_TYPE, FireworkList.NBT_TYPE);
|
||||
ItemComponent<Void> PROFILE = declare("profile", null, null); //todo
|
||||
ItemComponent<String> NOTE_BLOCK_SOUND = declare("note_block_sound", NetworkBuffer.STRING, BinaryTagSerializer.STRING);
|
||||
ItemComponent<Void> BANNER_PATTERNS = declare("banner_patterns", null, null); //todo
|
||||
ItemComponent<Void> BASE_COLOR = declare("base_color", null, null); //todo dyecolor is the same stringrepresentable as item rarity
|
||||
ItemComponent<Void> POT_DECORATIONS = declare("pot_decorations", null, null); //todo
|
||||
ItemComponent<List<ItemStack>> CONTAINER = declare("container", ItemStack.NETWORK_TYPE.list(256), BinaryTagSerializer.ITEM.list());
|
||||
ItemComponent<Void> BLOCK_STATE = declare("block_state", null, null); //todo
|
||||
ItemComponent<Void> BEES = declare("bees", null, null); //todo
|
||||
ItemComponent<String> LOCK = declare("lock", null, BinaryTagSerializer.STRING);
|
||||
ItemComponent<SeededContainerLoot> CONTAINER_LOOT = declare("container_loot", null, SeededContainerLoot.NBT_TYPE);
|
||||
public static final ItemComponentType<CustomData> CUSTOM_DATA = declare("custom_data", CustomData.NETWORK_TYPE, CustomData.NBT_TYPE);
|
||||
public static final ItemComponentType<Integer> MAX_STACK_SIZE = declare("max_stack_size", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
|
||||
public static final ItemComponentType<Integer> MAX_DAMAGE = declare("max_damage", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
|
||||
public static final ItemComponentType<Integer> DAMAGE = declare("damage", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
|
||||
public static final ItemComponentType<Unbreakable> UNBREAKABLE = declare("unbreakable", Unbreakable.NETWORK_TYPE, Unbreakable.NBT_TYPE);
|
||||
public static final ItemComponentType<Component> CUSTOM_NAME = declare("custom_name", NetworkBuffer.COMPONENT, BinaryTagSerializer.JSON_COMPONENT);
|
||||
public static final ItemComponentType<Component> ITEM_NAME = declare("item_name", NetworkBuffer.COMPONENT, BinaryTagSerializer.JSON_COMPONENT);
|
||||
public static final ItemComponentType<List<Component>> LORE = declare("lore", NetworkBuffer.COMPONENT.list(256), BinaryTagSerializer.JSON_COMPONENT.list());
|
||||
public static final ItemComponentType<ItemRarity> RARITY = declare("rarity", ItemRarity.NETWORK_TYPE, ItemRarity.NBT_TYPE);
|
||||
public static final ItemComponentType<EnchantmentList> ENCHANTMENTS = declare("enchantments", EnchantmentList.NETWORK_TYPE, EnchantmentList.NBT_TYPE);
|
||||
public static final ItemComponentType<Void> CAN_PLACE_ON = declare("can_place_on", null, null); //todo
|
||||
public static final ItemComponentType<Void> CAN_BREAK = declare("can_break", null, null); //todo
|
||||
public static final ItemComponentType<AttributeList> ATTRIBUTE_MODIFIERS = declare("attribute_modifiers", AttributeList.NETWORK_TYPE, AttributeList.NBT_TYPE);
|
||||
public static final ItemComponentType<Integer> CUSTOM_MODEL_DATA = declare("custom_model_data", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
|
||||
public static final ItemComponentType<Void> HIDE_ADDITIONAL_TOOLTIP = declare("hide_additional_tooltip", NetworkBuffer.NOTHING, BinaryTagSerializer.NOTHING);
|
||||
public static final ItemComponentType<Void> HIDE_TOOLTIP = declare("hide_tooltip", NetworkBuffer.NOTHING, BinaryTagSerializer.NOTHING);
|
||||
public static final ItemComponentType<Integer> REPAIR_COST = declare("repair_cost", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
|
||||
public static final ItemComponentType<Void> CREATIVE_SLOT_LOCK = declare("creative_slot_lock", NetworkBuffer.NOTHING, null);
|
||||
public static final ItemComponentType<Boolean> ENCHANTMENT_GLINT_OVERRIDE = declare("enchantment_glint_override", NetworkBuffer.BOOLEAN, BinaryTagSerializer.BOOLEAN);
|
||||
public static final ItemComponentType<Void> INTANGIBLE_PROJECTILE = declare("intangible_projectile", null, BinaryTagSerializer.NOTHING);
|
||||
public static final ItemComponentType<Void> FOOD = declare("food", null, null); //todo
|
||||
public static final ItemComponentType<Void> FIRE_RESISTANT = declare("fire_resistant", NetworkBuffer.NOTHING, BinaryTagSerializer.NOTHING);
|
||||
public static final ItemComponentType<Void> TOOL = declare("tool", null, null); //todo
|
||||
public static final ItemComponentType<EnchantmentList> STORED_ENCHANTMENTS = declare("stored_enchantments", EnchantmentList.NETWORK_TYPE, EnchantmentList.NBT_TYPE);
|
||||
public static final ItemComponentType<DyedItemColor> DYED_COLOR = declare("dyed_color", DyedItemColor.NETWORK_TYPE, DyedItemColor.NBT_TYPE);
|
||||
public static final ItemComponentType<Color> MAP_COLOR = declare("map_color", NetworkBuffer.COLOR, BinaryTagSerializer.INT.map(Color::new, Color::asRGB));
|
||||
public static final ItemComponentType<Integer> MAP_ID = declare("map_id", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
|
||||
public static final ItemComponentType<MapDecorations> MAP_DECORATIONS = declare("map_decorations", null, MapDecorations.NBT_TYPE);
|
||||
public static final ItemComponentType<MapPostProcessing> MAP_POST_PROCESSING = declare("map_post_processing", MapPostProcessing.NETWORK_TYPE, null);
|
||||
public static final ItemComponentType<List<ItemStack>> CHARGED_PROJECTILES = declare("charged_projectiles", ItemStack.NETWORK_TYPE.list(Short.MAX_VALUE), BinaryTagSerializer.ITEM.list());
|
||||
public static final ItemComponentType<List<ItemStack>> BUNDLE_CONTENTS = declare("bundle_contents", ItemStack.NETWORK_TYPE.list(Short.MAX_VALUE), BinaryTagSerializer.ITEM.list());
|
||||
public static final ItemComponentType<Void> POTION_CONTENTS = declare("potion_contents", null, null); //todo
|
||||
public static final ItemComponentType<Void> SUSPICIOUS_STEW_EFFECTS = declare("suspicious_stew_effects", null, null); //todo
|
||||
public static final ItemComponentType<WritableBookContent> WRITABLE_BOOK_CONTENT = declare("writable_book_content", WritableBookContent.NETWORK_TYPE, WritableBookContent.NBT_TYPE);
|
||||
public static final ItemComponentType<WrittenBookContent> WRITTEN_BOOK_CONTENT = declare("written_book_content", WrittenBookContent.NETWORK_TYPE, WrittenBookContent.NBT_TYPE);
|
||||
public static final ItemComponentType<Void> TRIM = declare("trim", null, null); //todo
|
||||
public static final ItemComponentType<Void> DEBUG_STICK_STATE = declare("debug_stick_state", null, null); //todo
|
||||
public static final ItemComponentType<CustomData> ENTITY_DATA = declare("entity_data", CustomData.NETWORK_TYPE, CustomData.NBT_TYPE);
|
||||
public static final ItemComponentType<CustomData> BUCKET_ENTITY_DATA = declare("bucket_entity_data", CustomData.NETWORK_TYPE, CustomData.NBT_TYPE);
|
||||
public static final ItemComponentType<CustomData> BLOCK_ENTITY_DATA = declare("block_entity_data", CustomData.NETWORK_TYPE, CustomData.NBT_TYPE);
|
||||
public static final ItemComponentType<Void> INSTRUMENT = declare("instrument", null, null); //todo
|
||||
public static final ItemComponentType<Integer> OMINOUS_BOTTLE_AMPLIFIER = declare("ominous_bottle_amplifier", NetworkBuffer.VAR_INT, BinaryTagSerializer.INT);
|
||||
public static final ItemComponentType<List<String>> RECIPES = declare("recipes", NetworkBuffer.STRING.list(Short.MAX_VALUE), BinaryTagSerializer.STRING.list());
|
||||
public static final ItemComponentType<LodestoneTracker> LODESTONE_TRACKER = declare("lodestone_tracker", LodestoneTracker.NETWORK_TYPE, LodestoneTracker.NBT_TYPE);
|
||||
public static final ItemComponentType<FireworkExplosion> FIREWORK_EXPLOSION = declare("firework_explosion", FireworkExplosion.NETWORK_TYPE, FireworkExplosion.NBT_TYPE);
|
||||
public static final ItemComponentType<FireworkList> FIREWORKS = declare("fireworks", FireworkList.NETWORK_TYPE, FireworkList.NBT_TYPE);
|
||||
public static final ItemComponentType<Void> PROFILE = declare("profile", null, null); //todo
|
||||
public static final ItemComponentType<String> NOTE_BLOCK_SOUND = declare("note_block_sound", NetworkBuffer.STRING, BinaryTagSerializer.STRING);
|
||||
public static final ItemComponentType<Void> BANNER_PATTERNS = declare("banner_patterns", null, null); //todo
|
||||
public static final ItemComponentType<Void> BASE_COLOR = declare("base_color", null, null); //todo dyecolor is the same stringrepresentable as item rarity
|
||||
public static final ItemComponentType<Void> POT_DECORATIONS = declare("pot_decorations", null, null); //todo
|
||||
public static final ItemComponentType<List<ItemStack>> CONTAINER = declare("container", ItemStack.NETWORK_TYPE.list(256), BinaryTagSerializer.ITEM.list());
|
||||
public static final ItemComponentType<Void> BLOCK_STATE = declare("block_state", null, null); //todo
|
||||
public static final ItemComponentType<Void> BEES = declare("bees", null, null); //todo
|
||||
public static final ItemComponentType<String> LOCK = declare("lock", null, BinaryTagSerializer.STRING);
|
||||
public static final ItemComponentType<SeededContainerLoot> CONTAINER_LOOT = declare("container_loot", null, SeededContainerLoot.NBT_TYPE);
|
||||
|
||||
@NotNull T read(@NotNull BinaryTag tag);
|
||||
@NotNull BinaryTag write(@NotNull T value);
|
||||
|
||||
@NotNull T read(@NotNull NetworkBuffer reader);
|
||||
void write(@NotNull NetworkBuffer writer, @NotNull T value);
|
||||
|
||||
|
||||
static @Nullable ItemComponent<?> fromNamespaceId(@NotNull String namespaceId) {
|
||||
return ItemComponentImpl.NAMESPACES.get(namespaceId);
|
||||
}
|
||||
|
||||
static @Nullable ItemComponent<?> fromNamespaceId(@NotNull NamespaceID namespaceId) {
|
||||
return fromNamespaceId(namespaceId.asString());
|
||||
}
|
||||
|
||||
static @Nullable ItemComponent<?> fromId(int id) {
|
||||
return ItemComponentImpl.IDS.get(id);
|
||||
}
|
||||
private ItemComponent() {}
|
||||
}
|
||||
|
|
|
@ -10,20 +10,20 @@ public interface ItemComponentMap {
|
|||
return new ItemComponentMapImpl.BuilderImpl(new Int2ObjectArrayMap<>());
|
||||
}
|
||||
|
||||
boolean has(@NotNull ItemComponent<?> component);
|
||||
boolean has(@NotNull ItemComponentType<?> component);
|
||||
|
||||
<T> @Nullable T get(@NotNull ItemComponent<T> component);
|
||||
<T> @Nullable T get(@NotNull ItemComponentType<T> component);
|
||||
|
||||
default <T> @NotNull T get(@NotNull ItemComponent<T> component, @NotNull T defaultValue) {
|
||||
default <T> @NotNull T get(@NotNull ItemComponentType<T> component, @NotNull T defaultValue) {
|
||||
T value = get(component);
|
||||
return value != null ? value : defaultValue;
|
||||
}
|
||||
|
||||
interface Builder extends ItemComponentMap {
|
||||
|
||||
@NotNull Builder set(@NotNull ItemComponent<?> component, @Nullable Object value);
|
||||
@NotNull Builder set(@NotNull ItemComponentType<?> component, @Nullable Object value);
|
||||
|
||||
@NotNull Builder remove(@NotNull ItemComponent<?> component);
|
||||
@NotNull Builder remove(@NotNull ItemComponentType<?> component);
|
||||
|
||||
@NotNull ItemComponentMap build();
|
||||
}
|
||||
|
|
|
@ -6,35 +6,35 @@ import org.jetbrains.annotations.Nullable;
|
|||
|
||||
public record ItemComponentMapImpl(@NotNull Int2ObjectMap<Object> components) implements ItemComponentMap {
|
||||
@Override
|
||||
public boolean has(@NotNull ItemComponent<?> component) {
|
||||
public boolean has(@NotNull ItemComponentType<?> component) {
|
||||
return components.get(component.id()) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T get(@NotNull ItemComponent<T> component) {
|
||||
public <T> @Nullable T get(@NotNull ItemComponentType<T> component) {
|
||||
return (T) components.get(component.id());
|
||||
}
|
||||
|
||||
public record BuilderImpl(@NotNull Int2ObjectMap<Object> components) implements ItemComponentMap.Builder {
|
||||
|
||||
@Override
|
||||
public boolean has(@NotNull ItemComponent<?> component) {
|
||||
public boolean has(@NotNull ItemComponentType<?> component) {
|
||||
return components.get(component.id()) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T get(@NotNull ItemComponent<T> component) {
|
||||
public <T> @Nullable T get(@NotNull ItemComponentType<T> component) {
|
||||
return (T) components.get(component.id());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Builder set(@NotNull ItemComponent<?> component, @Nullable Object value) {
|
||||
public @NotNull Builder set(@NotNull ItemComponentType<?> component, @Nullable Object value) {
|
||||
components.put(component.id(), value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Builder remove(@NotNull ItemComponent<?> component) {
|
||||
public @NotNull Builder remove(@NotNull ItemComponentType<?> component) {
|
||||
components.remove(component.id());
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ record ItemComponentPatch(@NotNull Int2ObjectMap<Object> patch) {
|
|||
if (entry.getValue() != null) {
|
||||
buffer.write(NetworkBuffer.VAR_INT, entry.getIntKey());
|
||||
//noinspection unchecked
|
||||
ItemComponent<Object> type = (ItemComponent<Object>) ItemComponent.fromId(entry.getIntKey());
|
||||
ItemComponentType<Object> type = (ItemComponentType<Object>) ItemComponentType.fromId(entry.getIntKey());
|
||||
assert type != null;
|
||||
type.write(entry.getValue());
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ record ItemComponentPatch(@NotNull Int2ObjectMap<Object> patch) {
|
|||
for (int i = 0; i < added; i++) {
|
||||
int id = buffer.read(NetworkBuffer.VAR_INT);
|
||||
//noinspection unchecked
|
||||
ItemComponent<Object> type = (ItemComponent<Object>) ItemComponent.fromId(id);
|
||||
ItemComponentType<Object> type = (ItemComponentType<Object>) ItemComponentType.fromId(id);
|
||||
Check.notNull(type, "Unknown item component id: {0}", id);
|
||||
patch.put(id, type.read(buffer));
|
||||
}
|
||||
|
@ -80,7 +80,7 @@ record ItemComponentPatch(@NotNull Int2ObjectMap<Object> patch) {
|
|||
key = key.substring(1);
|
||||
remove = true;
|
||||
}
|
||||
ItemComponent<?> type = ItemComponent.fromNamespaceId(key);
|
||||
ItemComponentType<?> type = ItemComponentType.fromNamespaceId(key);
|
||||
Check.notNull(type, "Unknown item component: {0}", key);
|
||||
if (remove) {
|
||||
patch.put(type.id(), null);
|
||||
|
@ -96,7 +96,7 @@ record ItemComponentPatch(@NotNull Int2ObjectMap<Object> patch) {
|
|||
CompoundBinaryTag.Builder builder = CompoundBinaryTag.builder();
|
||||
for (Int2ObjectMap.Entry<Object> entry : patch.patch.int2ObjectEntrySet()) {
|
||||
//noinspection unchecked
|
||||
ItemComponent<Object> type = (ItemComponent<Object>) ItemComponent.fromId(entry.getIntKey());
|
||||
ItemComponentType<Object> type = (ItemComponentType<Object>) ItemComponentType.fromId(entry.getIntKey());
|
||||
Check.notNull(type, "Unknown item component id: {0}", entry.getIntKey());
|
||||
if (entry.getValue() == null) {
|
||||
builder.put(REMOVAL_PREFIX + type.name(), CompoundBinaryTag.empty());
|
||||
|
@ -108,7 +108,7 @@ record ItemComponentPatch(@NotNull Int2ObjectMap<Object> patch) {
|
|||
}
|
||||
);
|
||||
|
||||
public boolean has(@NotNull ItemComponentMap prototype, @NotNull ItemComponent<?> component) {
|
||||
public boolean has(@NotNull ItemComponentMap prototype, @NotNull ItemComponentType<?> component) {
|
||||
if (patch.containsKey(component.id())) {
|
||||
return patch.get(component.id()) != null;
|
||||
} else {
|
||||
|
@ -116,7 +116,7 @@ record ItemComponentPatch(@NotNull Int2ObjectMap<Object> patch) {
|
|||
}
|
||||
}
|
||||
|
||||
public <T> @Nullable T get(@NotNull ItemComponentMap prototype, @NotNull ItemComponent<T> component) {
|
||||
public <T> @Nullable T get(@NotNull ItemComponentMap prototype, @NotNull ItemComponentType<T> component) {
|
||||
if (patch.containsKey(component.id())) {
|
||||
return (T) patch.get(component.id());
|
||||
} else {
|
||||
|
@ -124,13 +124,13 @@ record ItemComponentPatch(@NotNull Int2ObjectMap<Object> patch) {
|
|||
}
|
||||
}
|
||||
|
||||
public <T> @NotNull ItemComponentPatch with(@NotNull ItemComponent<T> component, @NotNull T value) {
|
||||
public <T> @NotNull ItemComponentPatch with(@NotNull ItemComponentType<T> component, @NotNull T value) {
|
||||
Int2ObjectMap<Object> newPatch = new Int2ObjectArrayMap<>(patch);
|
||||
newPatch.put(component.id(), value);
|
||||
return new ItemComponentPatch(newPatch);
|
||||
}
|
||||
|
||||
public <T> @NotNull ItemComponentPatch without(@NotNull ItemComponent<T> component) {
|
||||
public <T> @NotNull ItemComponentPatch without(@NotNull ItemComponentType<T> component) {
|
||||
Int2ObjectMap<Object> newPatch = new Int2ObjectArrayMap<>(patch);
|
||||
newPatch.put(component.id(), null);
|
||||
return new ItemComponentPatch(newPatch);
|
||||
|
@ -143,21 +143,21 @@ record ItemComponentPatch(@NotNull Int2ObjectMap<Object> patch) {
|
|||
record Builder(@NotNull Int2ObjectMap<Object> patch) implements ItemComponentMap {
|
||||
|
||||
@Override
|
||||
public boolean has(@NotNull ItemComponent<?> component) {
|
||||
public boolean has(@NotNull ItemComponentType<?> component) {
|
||||
return patch.get(component.id()) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T get(@NotNull ItemComponent<T> component) {
|
||||
public <T> @Nullable T get(@NotNull ItemComponentType<T> component) {
|
||||
return (T) patch.get(component.id());
|
||||
}
|
||||
|
||||
public <T> ItemComponentPatch.@NotNull Builder set(@NotNull ItemComponent<T> component, @NotNull T value) {
|
||||
public <T> ItemComponentPatch.@NotNull Builder set(@NotNull ItemComponentType<T> component, @NotNull T value) {
|
||||
patch.put(component.id(), value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemComponentPatch.@NotNull Builder remove(@NotNull ItemComponent<?> component) {
|
||||
public ItemComponentPatch.@NotNull Builder remove(@NotNull ItemComponentType<?> component) {
|
||||
patch.put(component.id(), null);
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package net.minestom.server.item;
|
||||
|
||||
import net.kyori.adventure.nbt.BinaryTag;
|
||||
import net.minestom.server.network.NetworkBuffer;
|
||||
import net.minestom.server.registry.StaticProtocolObject;
|
||||
import net.minestom.server.utils.NamespaceID;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public sealed interface ItemComponentType<T> extends StaticProtocolObject permits ItemComponentTypeImpl {
|
||||
|
||||
@NotNull T read(@NotNull BinaryTag tag);
|
||||
@NotNull BinaryTag write(@NotNull T value);
|
||||
|
||||
@NotNull T read(@NotNull NetworkBuffer reader);
|
||||
void write(@NotNull NetworkBuffer writer, @NotNull T value);
|
||||
|
||||
|
||||
static @Nullable ItemComponentType<?> fromNamespaceId(@NotNull String namespaceId) {
|
||||
return ItemComponentTypeImpl.NAMESPACES.get(namespaceId);
|
||||
}
|
||||
|
||||
static @Nullable ItemComponentType<?> fromNamespaceId(@NotNull NamespaceID namespaceId) {
|
||||
return fromNamespaceId(namespaceId.asString());
|
||||
}
|
||||
|
||||
static @Nullable ItemComponentType<?> fromId(int id) {
|
||||
return ItemComponentTypeImpl.IDS.get(id);
|
||||
}
|
||||
}
|
|
@ -12,17 +12,17 @@ import org.jetbrains.annotations.Nullable;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
record ItemComponentImpl<T>(
|
||||
record ItemComponentTypeImpl<T>(
|
||||
int id,
|
||||
@NotNull NamespaceID namespace,
|
||||
@Nullable NetworkBuffer.Type<T> network,
|
||||
@Nullable BinaryTagSerializer<T> nbt
|
||||
) implements ItemComponent<T> {
|
||||
static final Map<String, ItemComponent<?>> NAMESPACES = new HashMap<>(32);
|
||||
static final ObjectArray<ItemComponent<?>> IDS = ObjectArray.singleThread(32);
|
||||
) implements ItemComponentType<T> {
|
||||
static final Map<String, ItemComponentType<?>> NAMESPACES = new HashMap<>(32);
|
||||
static final ObjectArray<ItemComponentType<?>> IDS = ObjectArray.singleThread(32);
|
||||
|
||||
static <T> ItemComponent<T> declare(@NotNull String name, @Nullable NetworkBuffer.Type<T> network, @Nullable BinaryTagSerializer<T> nbt) {
|
||||
ItemComponent<T> impl = new ItemComponentImpl<>(NAMESPACES.size(), NamespaceID.from(name), network, nbt);
|
||||
static <T> ItemComponentType<T> declare(@NotNull String name, @Nullable NetworkBuffer.Type<T> network, @Nullable BinaryTagSerializer<T> nbt) {
|
||||
ItemComponentType<T> impl = new ItemComponentTypeImpl<>(NAMESPACES.size(), NamespaceID.from(name), network, nbt);
|
||||
NAMESPACES.put(impl.name(), impl);
|
||||
IDS.set(impl.id(), impl);
|
||||
return impl;
|
|
@ -79,16 +79,16 @@ public sealed interface ItemStack extends TagReadable, ItemComponentMap, HoverEv
|
|||
}
|
||||
|
||||
@Contract(value = "_, _ -> new", pure = true)
|
||||
<T> @NotNull ItemStack with(@NotNull ItemComponent<T> component, T value);
|
||||
<T> @NotNull ItemStack with(@NotNull ItemComponentType<T> component, T value);
|
||||
|
||||
default <T> @NotNull ItemStack with(@NotNull ItemComponent<T> component, @NotNull UnaryOperator<T> operator) {
|
||||
default <T> @NotNull ItemStack with(@NotNull ItemComponentType<T> component, @NotNull UnaryOperator<T> operator) {
|
||||
T value = get(component);
|
||||
if (value == null) return this;
|
||||
return with(component, operator.apply(value));
|
||||
}
|
||||
|
||||
@Contract(value = "_, -> new", pure = true)
|
||||
@NotNull ItemStack without(@NotNull ItemComponent<?> component);
|
||||
@NotNull ItemStack without(@NotNull ItemComponentType<?> component);
|
||||
|
||||
@Contract(value = "_, _ -> new", pure = true)
|
||||
default <T> @NotNull ItemStack withTag(@NotNull Tag<T> tag, @Nullable T value) {
|
||||
|
@ -144,10 +144,10 @@ public sealed interface ItemStack extends TagReadable, ItemComponentMap, HoverEv
|
|||
@NotNull Builder amount(int amount);
|
||||
|
||||
@Contract(value = "_, _ -> this")
|
||||
<T> @NotNull Builder set(@NotNull ItemComponent<T> component, T value);
|
||||
<T> @NotNull Builder set(@NotNull ItemComponentType<T> component, T value);
|
||||
|
||||
@Contract(value = "_ -> this")
|
||||
@NotNull Builder remove(@NotNull ItemComponent<?> component);
|
||||
@NotNull Builder remove(@NotNull ItemComponentType<?> component);
|
||||
|
||||
@Contract(value = "_, _ -> this")
|
||||
default <T> @NotNull Builder set(@NotNull Tag<T> tag, @Nullable T value) {
|
||||
|
|
|
@ -47,12 +47,12 @@ record ItemStackImpl(Material material, int amount, ItemComponentPatch component
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T get(@NotNull ItemComponent<T> component) {
|
||||
public <T> @Nullable T get(@NotNull ItemComponentType<T> component) {
|
||||
return components.get(material.prototype(), component);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean has(@NotNull ItemComponent<?> component) {
|
||||
public boolean has(@NotNull ItemComponentType<?> component) {
|
||||
return components.has(material.prototype(), component);
|
||||
}
|
||||
|
||||
|
@ -75,12 +75,12 @@ record ItemStackImpl(Material material, int amount, ItemComponentPatch component
|
|||
}
|
||||
|
||||
@Override
|
||||
public @NotNull <T> ItemStack with(@NotNull ItemComponent<T> component, T value) {
|
||||
public @NotNull <T> ItemStack with(@NotNull ItemComponentType<T> component, T value) {
|
||||
return new ItemStackImpl(material, amount, components.with(component, value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ItemStack without(@NotNull ItemComponent<?> component) {
|
||||
public @NotNull ItemStack without(@NotNull ItemComponentType<?> component) {
|
||||
return new ItemStackImpl(material, amount, components.without(component));
|
||||
}
|
||||
|
||||
|
@ -145,13 +145,13 @@ record ItemStackImpl(Material material, int amount, ItemComponentPatch component
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> ItemStack.@NotNull Builder set(@NotNull ItemComponent<T> component, T value) {
|
||||
public <T> ItemStack.@NotNull Builder set(@NotNull ItemComponentType<T> component, T value) {
|
||||
components.set(component, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack.@NotNull Builder remove(@NotNull ItemComponent<?> component) {
|
||||
public ItemStack.@NotNull Builder remove(@NotNull ItemComponentType<?> component) {
|
||||
components.remove(component);
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import net.minestom.server.entity.EquipmentSlot;
|
|||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.item.ItemComponent;
|
||||
import net.minestom.server.item.ItemComponentMap;
|
||||
import net.minestom.server.item.ItemComponentType;
|
||||
import net.minestom.server.item.Material;
|
||||
import net.minestom.server.utils.NamespaceID;
|
||||
import net.minestom.server.utils.collection.ObjectArray;
|
||||
|
@ -492,11 +493,18 @@ public final class Registry {
|
|||
this.blockSupplier = blockNamespace != null ? () -> Block.fromNamespaceId(blockNamespace) : () -> null;
|
||||
}
|
||||
try {
|
||||
|
||||
try {
|
||||
Class.forName(ItemComponent.class.getName());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
ItemComponentMap.Builder builder = ItemComponentMap.builder();
|
||||
for (Map.Entry<String, Object> entry : main.section("components")) {
|
||||
try {
|
||||
//noinspection unchecked
|
||||
ItemComponent<Object> component = (ItemComponent<Object>) ItemComponent.fromNamespaceId(entry.getKey());
|
||||
ItemComponentType<Object> component = (ItemComponentType<Object>) ItemComponentType.fromNamespaceId(entry.getKey());
|
||||
Check.notNull(component, "Unknown component: " + entry.getKey());
|
||||
|
||||
byte[] rawValue = Base64.getDecoder().decode((String) entry.getValue());
|
||||
|
|
Loading…
Reference in New Issue