mirror of https://github.com/PaperMC/Paper.git
update
This commit is contained in:
parent
0a1884ec64
commit
11e49bac13
|
@ -6,30 +6,37 @@ Subject: [PATCH] WIP DataKey API
|
|||
|
||||
diff --git a/src/main/java/io/papermc/paper/datakey/DataKey.java b/src/main/java/io/papermc/paper/datakey/DataKey.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..805926c7f8158680587e543e0f643d1e45d1a94a
|
||||
index 0000000000000000000000000000000000000000..3cfe90cb65723e306792803d115a5309914e43ae
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/datakey/DataKey.java
|
||||
@@ -0,0 +1,9 @@
|
||||
@@ -0,0 +1,17 @@
|
||||
+package io.papermc.paper.datakey;
|
||||
+
|
||||
+import net.kyori.adventure.key.Key;
|
||||
+import org.bukkit.Keyed;
|
||||
+
|
||||
+public interface DataKey<T> extends Keyed {
|
||||
+public interface DataKey extends Keyed {
|
||||
+
|
||||
+ Key key();
|
||||
+
|
||||
+ interface Valued<T> extends DataKey {
|
||||
+
|
||||
+ }
|
||||
+
|
||||
+ interface NonValued extends DataKey {
|
||||
+
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/datakey/DataKeys.java b/src/main/java/io/papermc/paper/datakey/DataKeys.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..26b83069907bbf6dfae98f1a687a982855283b8e
|
||||
index 0000000000000000000000000000000000000000..6d227528930c4d25ebfcc8829057cbacd442683b
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/datakey/DataKeys.java
|
||||
@@ -0,0 +1,73 @@
|
||||
@@ -0,0 +1,77 @@
|
||||
+package io.papermc.paper.datakey;
|
||||
+
|
||||
+import io.papermc.paper.datakey.types.ItemLore;
|
||||
+import io.papermc.paper.datakey.types.Unbreakable;
|
||||
+import io.papermc.paper.util.Unit;
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+import org.bukkit.NamespacedKey;
|
||||
+import org.bukkit.Registry;
|
||||
|
@ -37,27 +44,27 @@ index 0000000000000000000000000000000000000000..26b83069907bbf6dfae98f1a687a9828
|
|||
+
|
||||
+public class DataKeys {
|
||||
+
|
||||
+ public static final DataKey<Integer> MAX_STACK_SIZE = register("max_stack_size");
|
||||
+ public static final DataKey<Integer> MAX_DAMAGE = register("max_damage");
|
||||
+ public static final DataKey<Integer> DAMAGE = register("damage");
|
||||
+ public static final DataKey<Unbreakable> UNBREAKABLE = register("unbreakable");
|
||||
+ public static final DataKey<Component> CUSTOM_NAME = register("custom_name");
|
||||
+ public static final DataKey<Component> ITEM_NAME = register("item_name");
|
||||
+ public static final DataKey<ItemLore> LORE = register("lore");
|
||||
+ public static final DataKey<ItemRarity> RARITY = register("rarity");
|
||||
+ public static final DataKey.Valued<Integer> MAX_STACK_SIZE = typed("max_stack_size");
|
||||
+ public static final DataKey.Valued<Integer> MAX_DAMAGE = typed("max_damage");
|
||||
+ public static final DataKey.Valued<Integer> DAMAGE = typed("damage");
|
||||
+ public static final DataKey.Valued<Unbreakable> UNBREAKABLE = typed("unbreakable");
|
||||
+ public static final DataKey.Valued<Component> CUSTOM_NAME = typed("custom_name");
|
||||
+ public static final DataKey.Valued<Component> ITEM_NAME = typed("item_name");
|
||||
+ public static final DataKey.Valued<ItemLore> LORE = typed("lore");
|
||||
+ public static final DataKey.Valued<ItemRarity> RARITY = typed("rarity");
|
||||
+ // enchantments
|
||||
+ // can_place_on
|
||||
+ // can_break
|
||||
+ // attribute_modifiers
|
||||
+ // custom_model_data
|
||||
+ public static final DataKey<Unit> HIDE_ADDITIONAL_TOOLTIP = register("hide_additional_tooltip");
|
||||
+ public static final DataKey<Unit> HIDE_TOOLTIP = register("hide_tooltip");
|
||||
+ public static final DataKey<Integer> REPAIR_COST = register("repair_cost");
|
||||
+ public static final DataKey<Unit> CREATIVE_SLOT_LOCK = register("creative_slot_lock");
|
||||
+ public static final DataKey<Boolean> ENCHANTMENT_GLINT_OVERRIDE = register("enchantment_glint_override");
|
||||
+ public static final DataKey<Unit> INTANGIBLE_PROJECTILE = register("intangible_projectile");
|
||||
+ public static final DataKey.NonValued HIDE_ADDITIONAL_TOOLTIP = nonTyped("hide_additional_tooltip");
|
||||
+ public static final DataKey.NonValued HIDE_TOOLTIP = nonTyped("hide_tooltip");
|
||||
+ public static final DataKey.Valued<Integer> REPAIR_COST = typed("repair_cost");
|
||||
+ public static final DataKey.NonValued CREATIVE_SLOT_LOCK = nonTyped("creative_slot_lock");
|
||||
+ public static final DataKey.Valued<Boolean> ENCHANTMENT_GLINT_OVERRIDE = typed("enchantment_glint_override");
|
||||
+ public static final DataKey.NonValued INTANGIBLE_PROJECTILE = nonTyped("intangible_projectile");
|
||||
+ // food
|
||||
+ public static final DataKey<Unit> FIRE_RESISTANT = register("fire_resistant");
|
||||
+ public static final DataKey.NonValued FIRE_RESISTANT = nonTyped("fire_resistant");
|
||||
+ // tool
|
||||
+ // stored_enchantments
|
||||
+ // dyed_color
|
||||
|
@ -77,7 +84,7 @@ index 0000000000000000000000000000000000000000..26b83069907bbf6dfae98f1a687a9828
|
|||
+ // bucket_entity_data
|
||||
+ // block_entity_data
|
||||
+ // instrument
|
||||
+ public static final DataKey<Integer> OMINOUS_BOTTLE_AMPLIFIER = register("ominous_bottle_amplifier");
|
||||
+ public static final DataKey.Valued<Integer> OMINOUS_BOTTLE_AMPLIFIER = typed("ominous_bottle_amplifier");
|
||||
+ // recipes
|
||||
+ // lodestone_tracker
|
||||
+ // firework_explosion
|
||||
|
@ -94,16 +101,48 @@ index 0000000000000000000000000000000000000000..26b83069907bbf6dfae98f1a687a9828
|
|||
+ // container_loot
|
||||
+
|
||||
+ @SuppressWarnings("unchecked")
|
||||
+ private static <T> DataKey<T> register(String name) {
|
||||
+ return (DataKey<T>) Registry.DATA_KEYS.get(NamespacedKey.minecraft(name));
|
||||
+ private static DataKey.NonValued nonTyped(String name) {
|
||||
+ return (DataKey.NonValued) Registry.DATA_KEYS.get(NamespacedKey.minecraft(name));
|
||||
+ }
|
||||
+
|
||||
+ @SuppressWarnings("unchecked")
|
||||
+ private static <T> DataKey.Valued<T> typed(String name) {
|
||||
+ return (DataKey.Valued<T>) Registry.DATA_KEYS.get(NamespacedKey.minecraft(name));
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/datakey/PatchedDataComponentHolder.java b/src/main/java/io/papermc/paper/datakey/PatchedDataComponentHolder.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..a226c4d1d901ea6086ac49263a0f21867328e36f
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/datakey/PatchedDataComponentHolder.java
|
||||
@@ -0,0 +1,21 @@
|
||||
+package io.papermc.paper.datakey;
|
||||
+
|
||||
+import io.papermc.paper.datakey.map.DataKeyMap;
|
||||
+import org.jetbrains.annotations.Nullable;
|
||||
+
|
||||
+public interface PatchedDataComponentHolder {
|
||||
+
|
||||
+ DataKeyMap data();
|
||||
+
|
||||
+ @Nullable
|
||||
+ <T> T setData(DataKey.Valued<T> type, @Nullable T value);
|
||||
+
|
||||
+ @Nullable
|
||||
+ <T> T setData(DataKey.NonValued type);
|
||||
+
|
||||
+ @Nullable
|
||||
+ <T> T removeData(DataKey type);
|
||||
+
|
||||
+ boolean hasData(DataKey type);
|
||||
+
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/datakey/map/DataKeyMap.java b/src/main/java/io/papermc/paper/datakey/map/DataKeyMap.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..c542860ee47cdd02d55b39aa6f1fe29f4e85773a
|
||||
index 0000000000000000000000000000000000000000..75d07bd3ec9b51f039715590881272eced13ea4f
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/datakey/map/DataKeyMap.java
|
||||
@@ -0,0 +1,27 @@
|
||||
@@ -0,0 +1,25 @@
|
||||
+package io.papermc.paper.datakey.map;
|
||||
+
|
||||
+import io.papermc.paper.datakey.DataKey;
|
||||
|
@ -117,15 +156,13 @@ index 0000000000000000000000000000000000000000..c542860ee47cdd02d55b39aa6f1fe29f
|
|||
+ }
|
||||
+
|
||||
+ @Nullable
|
||||
+ <T> T get(DataKey<T> type);
|
||||
+ <T> T get(DataKey.Valued<T> type);
|
||||
+
|
||||
+ Set<DataKey<?>> keySet();
|
||||
+ Set<DataKey> keySet();
|
||||
+
|
||||
+ default boolean has(DataKey<?> type) {
|
||||
+ return this.get(type) != null;
|
||||
+ }
|
||||
+ boolean has(DataKey type);
|
||||
+
|
||||
+ default <T> T getOrDefault(DataKey<? extends T> type, T fallback) {
|
||||
+ default <T> T getOrDefault(DataKey.Valued<T> type, T fallback) {
|
||||
+ T object = this.get(type);
|
||||
+ return object != null ? object : fallback;
|
||||
+ }
|
||||
|
@ -165,10 +202,10 @@ index 0000000000000000000000000000000000000000..9da6ab689eb43eb960429fe9a752c0c6
|
|||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/datakey/map/PatchedDataKeyMap.java b/src/main/java/io/papermc/paper/datakey/map/PatchedDataKeyMap.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..4a3c74320909d5dadf4fdd48fceeb60da111c311
|
||||
index 0000000000000000000000000000000000000000..3340e13d6f161c521af5bca7a57c173bc0bdfead
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/datakey/map/PatchedDataKeyMap.java
|
||||
@@ -0,0 +1,30 @@
|
||||
@@ -0,0 +1,36 @@
|
||||
+package io.papermc.paper.datakey.map;
|
||||
+
|
||||
+import io.papermc.paper.datakey.DataKey;
|
||||
|
@ -187,10 +224,16 @@ index 0000000000000000000000000000000000000000..4a3c74320909d5dadf4fdd48fceeb60d
|
|||
+ }
|
||||
+
|
||||
+ @Nullable
|
||||
+ <T> T set(DataKey<T> type, @Nullable T value);
|
||||
+ <T> T set(DataKey.Valued<T> type, @Nullable T value);
|
||||
+
|
||||
+ // Returns if this value was previously set
|
||||
+ boolean set(DataKey.NonValued type);
|
||||
+
|
||||
+ @Nullable
|
||||
+ <T> T remove(DataKey<T> type);
|
||||
+ <T> T remove(DataKey.Valued<T> type);
|
||||
+
|
||||
+ // Returns if this value was previously set
|
||||
+ boolean remove(DataKey.NonValued type);
|
||||
+
|
||||
+ @NotNull
|
||||
+ DataKeyMapPatch asPatch();
|
||||
|
@ -277,34 +320,17 @@ index 0000000000000000000000000000000000000000..d6dc5fa334679767096da9f80740bbc9
|
|||
+ @Contract("_ -> new")
|
||||
+ Unbreakable showInTooltip(boolean hideInTooltip);
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/util/Unit.java b/src/main/java/io/papermc/paper/util/Unit.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..540bf0c6f3f33bd3b7282ce9b51d32707d8ffc63
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/util/Unit.java
|
||||
@@ -0,0 +1,8 @@
|
||||
+package io.papermc.paper.util;
|
||||
+
|
||||
+public interface Unit {
|
||||
+
|
||||
+ static Unit of() {
|
||||
+ return UnitHolder.UNIT;
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/util/UnitHolder.java b/src/main/java/io/papermc/paper/util/UnitHolder.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..5312745cb67d48e2370251fb45aa2c5c93c52107
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/util/UnitHolder.java
|
||||
@@ -0,0 +1,8 @@
|
||||
+package io.papermc.paper.util;
|
||||
+
|
||||
+
|
||||
+class UnitHolder {
|
||||
+
|
||||
+ static final Unit UNIT = new Unit() {
|
||||
+ };
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/registry/RegistryKey.java b/src/main/java/io/papermc/paper/registry/RegistryKey.java
|
||||
index c4b30b16ce4db754b958c493ad86d0863592c263..a16f0a3c426598990066f1527ce808ae9c214fc7 100644
|
||||
--- a/src/main/java/io/papermc/paper/registry/RegistryKey.java
|
||||
+++ b/src/main/java/io/papermc/paper/registry/RegistryKey.java
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.papermc.paper.registry;
|
||||
|
||||
+import io.papermc.paper.datakey.DataKey;
|
||||
import net.kyori.adventure.key.Keyed;
|
||||
import org.bukkit.GameEvent;
|
||||
import org.bukkit.block.Biome;
|
||||
diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java
|
||||
index 82d009c0bbe4b3026a535e02d6e0ed20c7bd525d..2e829272171761da93c8d44d3c04e23e3c25516a 100644
|
||||
--- a/src/main/java/org/bukkit/Material.java
|
||||
|
@ -319,7 +345,7 @@ index 82d009c0bbe4b3026a535e02d6e0ed20c7bd525d..2e829272171761da93c8d44d3c04e23e
|
|||
GRANITE(21091),
|
||||
POLISHED_GRANITE(5477),
|
||||
diff --git a/src/main/java/org/bukkit/Registry.java b/src/main/java/org/bukkit/Registry.java
|
||||
index 542c0516e19b6177ff8007ca6f8955dc9082da95..329480202c35908bb2ce6970d23f486b9666652c 100644
|
||||
index 542c0516e19b6177ff8007ca6f8955dc9082da95..3b6f3bccf7b009c35065d94532f0d0b4b606e015 100644
|
||||
--- a/src/main/java/org/bukkit/Registry.java
|
||||
+++ b/src/main/java/org/bukkit/Registry.java
|
||||
@@ -317,6 +317,8 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
|
||||
|
@ -327,7 +353,7 @@ index 542c0516e19b6177ff8007ca6f8955dc9082da95..329480202c35908bb2ce6970d23f486b
|
|||
}
|
||||
};
|
||||
+
|
||||
+ Registry<io.papermc.paper.datakey.DataKey<?>> DATA_KEYS = (Registry) Bukkit.getRegistry(io.papermc.paper.datakey.DataKey.class);
|
||||
+ Registry<io.papermc.paper.datakey.DataKey> DATA_KEYS = (Registry) Bukkit.getRegistry(io.papermc.paper.datakey.DataKey.class);
|
||||
// Paper end
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,263 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
|
||||
Date: Mon, 29 Apr 2024 10:46:46 -0400
|
||||
Subject: [PATCH] squash! WIP DataKey API
|
||||
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/datakey/ComponentAdapters.java b/src/main/java/io/papermc/paper/datakey/ComponentAdapters.java
|
||||
index d1b5eff0a0ef9c40892f7e8804309619770712cc..c241e4f4d9dcd8078dbd28c6e472642140b7ce29 100644
|
||||
--- a/src/main/java/io/papermc/paper/datakey/ComponentAdapters.java
|
||||
+++ b/src/main/java/io/papermc/paper/datakey/ComponentAdapters.java
|
||||
@@ -5,7 +5,6 @@ import io.papermc.paper.datakey.types.ItemLore;
|
||||
import io.papermc.paper.datakey.types.PaperItemLore;
|
||||
import io.papermc.paper.datakey.types.PaperUnbreakable;
|
||||
import io.papermc.paper.datakey.types.Unbreakable;
|
||||
-import io.papermc.paper.util.Unit;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
@@ -30,25 +29,25 @@ public class ComponentAdapters {
|
||||
register(DataComponents.ITEM_NAME, DataKeys.ITEM_NAME, Component.class, PaperAdventure::asVanilla, PaperAdventure::asAdventure);
|
||||
register(DataComponents.LORE, DataKeys.LORE, ItemLore.class, (api) -> ((PaperItemLore) api).getHandle(), PaperItemLore::new);
|
||||
register(DataComponents.RARITY, DataKeys.RARITY, ItemRarity.class, (api) -> Rarity.valueOf(api.name()), (nms) -> ItemRarity.valueOf(nms.name()));
|
||||
- registerUnit(DataComponents.HIDE_ADDITIONAL_TOOLTIP);
|
||||
- registerUnit(DataComponents.HIDE_TOOLTIP);
|
||||
+ registerUntyped(DataComponents.HIDE_ADDITIONAL_TOOLTIP);
|
||||
+ registerUntyped(DataComponents.HIDE_TOOLTIP);
|
||||
registerIdentity(DataComponents.REPAIR_COST, Integer.class);
|
||||
- registerUnit(DataComponents.CREATIVE_SLOT_LOCK);
|
||||
+ registerUntyped(DataComponents.CREATIVE_SLOT_LOCK);
|
||||
registerIdentity(DataComponents.ENCHANTMENT_GLINT_OVERRIDE, Boolean.class);
|
||||
- registerUnit(DataComponents.INTANGIBLE_PROJECTILE);
|
||||
- registerUnit(DataComponents.FIRE_RESISTANT);
|
||||
+ registerUntyped(DataComponents.INTANGIBLE_PROJECTILE);
|
||||
+ registerUntyped(DataComponents.FIRE_RESISTANT);
|
||||
registerIdentity(DataComponents.OMINOUS_BOTTLE_AMPLIFIER, Integer.class);
|
||||
}
|
||||
|
||||
|
||||
- public static void registerUnit(DataComponentType<net.minecraft.util.Unit> type) {
|
||||
- ADAPTERS.put(BuiltInRegistries.DATA_COMPONENT_TYPE.getKey(type), new ComponentAdapter<>(type, Unit.class, unit -> net.minecraft.util.Unit.INSTANCE, unit -> Unit.of()));
|
||||
+ public static void registerUntyped(DataComponentType<net.minecraft.util.Unit> type) {
|
||||
+ ADAPTERS.put(BuiltInRegistries.DATA_COMPONENT_TYPE.getKey(type), new ComponentAdapter<>(type, Void.class, unit -> net.minecraft.util.Unit.INSTANCE, unit -> {throw new UnsupportedOperationException();}));
|
||||
}
|
||||
public static <COMMON> void registerIdentity(DataComponentType<COMMON> type, Class<COMMON> apiTypeValidation) {
|
||||
ADAPTERS.put(BuiltInRegistries.DATA_COMPONENT_TYPE.getKey(type), new ComponentAdapter<>(type, apiTypeValidation, (c) -> c, (c) -> c));
|
||||
}
|
||||
|
||||
- public static <NMS, API> void register(DataComponentType<NMS> type, DataKey<API> dummy, Class<API> apiTypeValidation, Function<API, NMS> nmsConverter, Function<NMS, API> apiConverter) {
|
||||
+ public static <NMS, API> void register(DataComponentType<NMS> type, DataKey.Valued<API> dummy, Class<API> apiTypeValidation, Function<API, NMS> nmsConverter, Function<NMS, API> apiConverter) {
|
||||
ADAPTERS.put(BuiltInRegistries.DATA_COMPONENT_TYPE.getKey(type), new ComponentAdapter<>(type, apiTypeValidation, nmsConverter, apiConverter));
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/datakey/PaperComponentType.java b/src/main/java/io/papermc/paper/datakey/PaperComponentType.java
|
||||
index d78d42a76cfc8c816635ce16cd9e830fd04bced5..93ce96e0f95b88d051543d09b1141047e6662f86 100644
|
||||
--- a/src/main/java/io/papermc/paper/datakey/PaperComponentType.java
|
||||
+++ b/src/main/java/io/papermc/paper/datakey/PaperComponentType.java
|
||||
@@ -14,15 +14,15 @@ import org.bukkit.craftbukkit.util.Handleable;
|
||||
import org.bukkit.damage.DamageType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
-public class PaperComponentType<T, NMS> implements DataKey<T>, Handleable<DataComponentType<NMS>> {
|
||||
+public class PaperComponentType<T, NMS> implements DataKey, Handleable<DataComponentType<NMS>> {
|
||||
static {
|
||||
ComponentAdapters.bootstrap();
|
||||
}
|
||||
- public static <T> DataComponentType<T> bukkitToMinecraft(DataKey<T> bukkitDamageType) {
|
||||
+ public static <T> DataComponentType<T> bukkitToMinecraft(DataKey bukkitDamageType) {
|
||||
return CraftRegistry.bukkitToMinecraft(bukkitDamageType);
|
||||
}
|
||||
|
||||
- public static DataKey<?> minecraftToBukkit(DataComponentType<?> minecraftDamageType) {
|
||||
+ public static DataKey minecraftToBukkit(DataComponentType<?> minecraftDamageType) {
|
||||
return CraftRegistry.minecraftToBukkit(minecraftDamageType, Registries.DATA_COMPONENT_TYPE, Registry.DATA_KEYS);
|
||||
}
|
||||
|
||||
@@ -30,9 +30,9 @@ public class PaperComponentType<T, NMS> implements DataKey<T>, Handleable<DataCo
|
||||
private final ComponentAdapters.ComponentAdapter<T, NMS> adapter;
|
||||
private final DataComponentType<NMS> dataComponentType;
|
||||
|
||||
- public PaperComponentType(NamespacedKey namespacedKey, DataComponentType<?> dataComponentType) {
|
||||
+ public PaperComponentType(NamespacedKey namespacedKey, DataComponentType<?> dataComponentType, ComponentAdapters.ComponentAdapter<T, NMS> adapter) {
|
||||
this.key = namespacedKey;
|
||||
- this.adapter = (ComponentAdapters.ComponentAdapter<T, NMS>) ComponentAdapters.ADAPTERS.get(CraftNamespacedKey.toMinecraft(key));
|
||||
+ this.adapter = adapter;
|
||||
this.dataComponentType = (DataComponentType<NMS>) dataComponentType;
|
||||
}
|
||||
|
||||
@@ -54,4 +54,28 @@ public class PaperComponentType<T, NMS> implements DataKey<T>, Handleable<DataCo
|
||||
public DataComponentType<NMS> getHandle() {
|
||||
return this.dataComponentType;
|
||||
}
|
||||
+
|
||||
+ public static DataKey of(NamespacedKey namespacedKey, DataComponentType<?> dataComponentType) {
|
||||
+ ComponentAdapters.ComponentAdapter adapter = ComponentAdapters.ADAPTERS.get(CraftNamespacedKey.toMinecraft(namespacedKey));
|
||||
+ if (adapter != null && adapter.apiTypeValidation() == Void.class) {
|
||||
+ return new NonypedPaperComponentType<>(namespacedKey, dataComponentType, adapter);
|
||||
+ } else {
|
||||
+ return new TypedPaperComponentType<>(namespacedKey, dataComponentType, adapter);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+
|
||||
+ private static class TypedPaperComponentType<T, NMS> extends PaperComponentType<T, NMS> implements DataKey.Valued<T> {
|
||||
+
|
||||
+ public TypedPaperComponentType(final NamespacedKey namespacedKey, final DataComponentType<?> dataComponentType, ComponentAdapters.ComponentAdapter<T, NMS> adapter) {
|
||||
+ super(namespacedKey, dataComponentType, adapter);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ private static class NonypedPaperComponentType<T, NMS> extends PaperComponentType<T, NMS> implements DataKey.NonValued {
|
||||
+
|
||||
+ public NonypedPaperComponentType(final NamespacedKey namespacedKey, final DataComponentType<?> dataComponentType, ComponentAdapters.ComponentAdapter<T, NMS> adapter) {
|
||||
+ super(namespacedKey, dataComponentType, adapter);
|
||||
+ }
|
||||
+ }
|
||||
}
|
||||
diff --git a/src/main/java/io/papermc/paper/datakey/PaperDataKeyMap.java b/src/main/java/io/papermc/paper/datakey/PaperDataKeyMap.java
|
||||
index e55c1bcbf62de62d7699cf2a050132b208083a3d..478c73363e64e861a8285234f2f294f45ecbfdf5 100644
|
||||
--- a/src/main/java/io/papermc/paper/datakey/PaperDataKeyMap.java
|
||||
+++ b/src/main/java/io/papermc/paper/datakey/PaperDataKeyMap.java
|
||||
@@ -17,7 +17,7 @@ public class PaperDataKeyMap implements DataKeyMap {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
- public <T> T get(final DataKey<T> type) {
|
||||
+ public <T> T get(final DataKey.Valued<T> type) {
|
||||
PaperComponentType<T, Object> paperComponentType = (PaperComponentType<T, Object>) type;
|
||||
ComponentAdapters.ComponentAdapter<T, Object> adapter = paperComponentType.getAdapter();
|
||||
Object keyValue = this.nmsComponentMap.get(paperComponentType.getHandle());
|
||||
@@ -26,13 +26,19 @@ public class PaperDataKeyMap implements DataKeyMap {
|
||||
}
|
||||
|
||||
@Override
|
||||
- public Set<DataKey<?>> keySet() {
|
||||
+ public Set<DataKey> keySet() {
|
||||
Set<DataComponentType<?>> nmsKeys = this.nmsComponentMap.keySet();
|
||||
- Set<DataKey<?>> keys = new HashSet<>(nmsKeys.size());
|
||||
+ Set<DataKey> keys = new HashSet<>(nmsKeys.size());
|
||||
for (DataComponentType<?> nmsKey : nmsKeys) {
|
||||
keys.add(PaperComponentType.minecraftToBukkit(nmsKey));
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean has(final DataKey type) {
|
||||
+ PaperComponentType<?, Object> paperComponentType = (PaperComponentType<?, Object>) type;
|
||||
+ return this.nmsComponentMap.has(paperComponentType.getHandle());
|
||||
+ }
|
||||
}
|
||||
diff --git a/src/main/java/io/papermc/paper/datakey/PaperPatchedDataKeyMap.java b/src/main/java/io/papermc/paper/datakey/PaperPatchedDataKeyMap.java
|
||||
index a7bd48c01c473ccde84760d121dcad73aa6d0a59..36802d32ed1724e87f707c0cc46e566ef04a5b77 100644
|
||||
--- a/src/main/java/io/papermc/paper/datakey/PaperPatchedDataKeyMap.java
|
||||
+++ b/src/main/java/io/papermc/paper/datakey/PaperPatchedDataKeyMap.java
|
||||
@@ -17,16 +17,25 @@ public class PaperPatchedDataKeyMap extends PaperDataKeyMap implements PatchedDa
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
- public <T> T set(final DataKey<T> type, @Nullable final T value) {
|
||||
+ public <T> T set(final DataKey.Valued<T> type, @Nullable final T value) {
|
||||
PaperComponentType<T, Object> paperComponentType = (PaperComponentType<T, Object>) type;
|
||||
ComponentAdapters.ComponentAdapter<T, Object> adapter = paperComponentType.getAdapter();
|
||||
|
||||
return adapter.apiConverter().apply(this.patched().set(paperComponentType.getHandle(), value == null ? null : adapter.nmsConverter().apply(value)));
|
||||
}
|
||||
|
||||
- @Nullable
|
||||
@Override
|
||||
- public <T> T remove(final DataKey<T> type) {
|
||||
+ public boolean set(final DataKey.NonValued type) {
|
||||
+ PaperComponentType<?, Object> paperComponentType = (PaperComponentType<?, Object>) type;
|
||||
+ ComponentAdapters.ComponentAdapter<?, Object> adapter = paperComponentType.getAdapter();
|
||||
+
|
||||
+ boolean hasValue = this.has(type);
|
||||
+ this.patched().set(paperComponentType.getHandle(), adapter.nmsConverter().apply(null));
|
||||
+ return hasValue;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public <T> @Nullable T remove(final DataKey.Valued<T> type) {
|
||||
PaperComponentType<T, Object> paperComponentType = (PaperComponentType<T, Object>) type;
|
||||
ComponentAdapters.ComponentAdapter<T, Object> adapter = paperComponentType.getAdapter();
|
||||
|
||||
@@ -38,6 +47,19 @@ public class PaperPatchedDataKeyMap extends PaperDataKeyMap implements PatchedDa
|
||||
return adapter.apiConverter().apply(removed);
|
||||
}
|
||||
|
||||
+ @Override
|
||||
+ public boolean remove(final DataKey.NonValued type) {
|
||||
+ PaperComponentType<?, Object> paperComponentType = (PaperComponentType<?, Object>) type;
|
||||
+ ComponentAdapters.ComponentAdapter<?, Object> adapter = paperComponentType.getAdapter();
|
||||
+
|
||||
+ Object removed = this.patched().remove(adapter.type());
|
||||
+ if (removed == null) {
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
@Override
|
||||
public @NotNull DataKeyMapPatch asPatch() {
|
||||
return null;
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java
|
||||
index 189b8d995caa7e8190c6c07400c75d791f6465ed..2ea46a3620fffcee18ad0e1d571ebfeedb66fd41 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftRegistry.java
|
||||
@@ -146,7 +146,7 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
|
||||
// Paper end
|
||||
// Paper start - remove this after a while along with all ConfiguredStructure stuff
|
||||
if (bukkitClass == io.papermc.paper.datakey.DataKey.class) {
|
||||
- return new CraftRegistry<>(io.papermc.paper.datakey.DataKey.class, registryHolder.registryOrThrow(Registries.DATA_COMPONENT_TYPE), io.papermc.paper.datakey.PaperComponentType::new);
|
||||
+ return new CraftRegistry<>(io.papermc.paper.datakey.DataKey.class, registryHolder.registryOrThrow(Registries.DATA_COMPONENT_TYPE), io.papermc.paper.datakey.PaperComponentType::of);
|
||||
}
|
||||
// Paper end
|
||||
|
||||
diff --git a/src/test/java/io/papermc/paper/item/MetaDataKeyMetaTest.java b/src/test/java/io/papermc/paper/item/MetaDataKeyMetaTest.java
|
||||
index c60ec00464d5d4216544240f64a867e51ac7335d..517ea27fe792b1e6ec54075b4330d9a08c834bcf 100644
|
||||
--- a/src/test/java/io/papermc/paper/item/MetaDataKeyMetaTest.java
|
||||
+++ b/src/test/java/io/papermc/paper/item/MetaDataKeyMetaTest.java
|
||||
@@ -3,7 +3,6 @@ package io.papermc.paper.item;
|
||||
import io.papermc.paper.datakey.DataKey;
|
||||
import io.papermc.paper.datakey.DataKeys;
|
||||
import io.papermc.paper.datakey.types.Unbreakable;
|
||||
-import io.papermc.paper.util.Unit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -56,23 +55,23 @@ public class MetaDataKeyMetaTest extends AbstractTestingBase {
|
||||
@Test
|
||||
public void testToolTipAdditional() {
|
||||
ItemStack itemStack = new ItemStack(Material.STONE);
|
||||
- itemStack.getDataKeyMap().set(DataKeys.HIDE_ADDITIONAL_TOOLTIP, Unit.of());
|
||||
+ itemStack.getDataKeyMap().set(DataKeys.HIDE_ADDITIONAL_TOOLTIP);
|
||||
|
||||
Assertions.assertTrue(itemStack.getItemMeta().getItemFlags().contains(ItemFlag.HIDE_ADDITIONAL_TOOLTIP));
|
||||
- itemStack.getDataKeyMap().set(DataKeys.HIDE_ADDITIONAL_TOOLTIP, null);
|
||||
+ itemStack.getDataKeyMap().remove(DataKeys.HIDE_ADDITIONAL_TOOLTIP);
|
||||
Assertions.assertFalse(itemStack.getItemMeta().getItemFlags().contains(ItemFlag.HIDE_ADDITIONAL_TOOLTIP));
|
||||
}
|
||||
|
||||
- @Test
|
||||
- public void testToolTip() {
|
||||
- ItemStack itemStack = new ItemStack(Material.STONE);
|
||||
- testSimpleValue(itemStack, DataKeys.HIDE_TOOLTIP, Unit.of(), (meta) -> meta.isHideTooltip() ? Unit.of() : null, (meta, val) -> meta.setHideTooltip(val != null), ItemMeta.class);
|
||||
- itemStack = new ItemStack(Material.STONE);
|
||||
- testSimpleValue(itemStack, DataKeys.HIDE_TOOLTIP, null, (meta) -> meta.isHideTooltip() ? Unit.of() : null, (meta, val) -> meta.setHideTooltip(false), ItemMeta.class);
|
||||
- }
|
||||
+ // @Test
|
||||
+ // public void testToolTip() {
|
||||
+ // ItemStack itemStack = new ItemStack(Material.STONE);
|
||||
+ // testSimpleValue(itemStack, DataKeys.HIDE_TOOLTIP, Unit.of(), (meta) -> meta.isHideTooltip() ? Unit.of() : null, (meta, val) -> meta.setHideTooltip(val != null), ItemMeta.class);
|
||||
+ // itemStack = new ItemStack(Material.STONE);
|
||||
+ // testSimpleValue(itemStack, DataKeys.HIDE_TOOLTIP, null, (meta) -> meta.isHideTooltip() ? Unit.of() : null, (meta, val) -> meta.setHideTooltip(false), ItemMeta.class);
|
||||
+ // }
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
- private static <T, M> void testSimpleValue(ItemStack itemStack, DataKey<T> dataKey, T value, Function<M, T> metaGetter, BiConsumer<M, T> metaSetter, Class<M> meta) {
|
||||
+ private static <T, M> void testSimpleValue(ItemStack itemStack, DataKey.Valued<T> dataKey, T value, Function<M, T> metaGetter, BiConsumer<M, T> metaSetter, Class<M> meta) {
|
||||
itemStack.getDataKeyMap().set(dataKey, value);
|
||||
Assertions.assertEquals(value, itemStack.getDataKeyMap().get(dataKey));
|
||||
|
Loading…
Reference in New Issue