Skip to content

Commit e753417

Browse files
committed
Some marginal work on DataComponents
1 parent 0a5ea70 commit e753417

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

paper-api/src/main/java/io/papermc/paper/datacomponent/DataComponentTypes.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,21 @@ public final class DataComponentTypes {
378378

379379

380380
private static DataComponentType.NonValued unvalued(final String name) {
381-
return (DataComponentType.NonValued) requireNonNull(Registry.DATA_COMPONENT_TYPE.get(NamespacedKey.minecraft(name)), name + " unvalued data component type couldn't be found, this is a bug.");
381+
final DataComponentType dataComponentType = requireNonNull(Registry.DATA_COMPONENT_TYPE.get(NamespacedKey.minecraft(name)), name + " unvalued data component type couldn't be found, this is a bug.");
382+
if (dataComponentType instanceof DataComponentType.NonValued) {
383+
return (DataComponentType.NonValued) dataComponentType;
384+
}
385+
throw new IllegalStateException(name + " is not a valid unvalued type, it is a " + dataComponentType.getClass().getTypeName());
382386
}
383387

384388
@SuppressWarnings("unchecked")
385389
private static <T> DataComponentType.Valued<T> valued(final String name) {
386-
return (DataComponentType.Valued<T>) requireNonNull(Registry.DATA_COMPONENT_TYPE.get(NamespacedKey.minecraft(name)), name + " valued data component type couldn't be found, this is a bug.");
390+
DataComponentType dataComponentType = requireNonNull(Registry.DATA_COMPONENT_TYPE.get(NamespacedKey.minecraft(name)), name + " valued data component type couldn't be found, this is a bug.");
391+
if (dataComponentType instanceof DataComponentType.Valued) {
392+
return (DataComponentType.Valued<T>) dataComponentType;
393+
}
394+
throw new IllegalStateException(name + " is not a valid valued type, it is a " + dataComponentType.getClass().getTypeName());
395+
387396
}
388397

389398
private DataComponentTypes() {

paper-server/src/main/java/io/papermc/paper/datacomponent/DataComponentAdapters.java

+11
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.HashMap;
4444
import java.util.Map;
4545
import java.util.function.Function;
46+
import io.papermc.paper.registry.PaperRegistries;
4647
import net.minecraft.core.component.DataComponentType;
4748
import net.minecraft.core.component.DataComponents;
4849
import net.minecraft.core.registries.BuiltInRegistries;
@@ -53,6 +54,7 @@
5354
import net.minecraft.world.item.component.MapPostProcessing;
5455
import org.bukkit.DyeColor;
5556
import org.bukkit.craftbukkit.CraftMusicInstrument;
57+
import org.bukkit.craftbukkit.entity.CraftWolf;
5658
import org.bukkit.craftbukkit.inventory.CraftMetaFirework;
5759
import org.bukkit.craftbukkit.util.Handleable;
5860
import org.bukkit.inventory.ItemRarity;
@@ -75,6 +77,7 @@ public static void bootstrap() {
7577
registerIdentity(DataComponents.MAX_STACK_SIZE);
7678
registerIdentity(DataComponents.MAX_DAMAGE);
7779
registerIdentity(DataComponents.DAMAGE);
80+
registerUntyped(DataComponents.UNBREAKABLE);
7881
registerIdentity(DataComponents.POTION_DURATION_SCALE);
7982
register(DataComponents.CUSTOM_NAME, PaperAdventure::asAdventure, PaperAdventure::asVanilla);
8083
register(DataComponents.ITEM_NAME, PaperAdventure::asAdventure, PaperAdventure::asVanilla);
@@ -120,8 +123,11 @@ public static void bootstrap() {
120123
// bucket entity data
121124
// block entity data
122125
//register(DataComponents.INSTRUMENT, CraftMusicInstrument::minecraftHolderToBukkit, CraftMusicInstrument::bukkitToMinecraftHolder); // TODO
126+
registerIdentity(DataComponents.INSTRUMENT);
127+
registerIdentity(DataComponents.PROVIDES_TRIM_MATERIAL); // TODO
123128
register(DataComponents.OMINOUS_BOTTLE_AMPLIFIER, PaperOminousBottleAmplifier::new);
124129
register(DataComponents.JUKEBOX_PLAYABLE, PaperJukeboxPlayable::new);
130+
register(DataComponents.PROVIDES_BANNER_PATTERNS, PaperRegistries::fromNms, PaperRegistries::toNms);
125131
register(DataComponents.RECIPES,
126132
nms -> transformUnmodifiable(nms, PaperAdventure::asAdventureKey),
127133
api -> transformUnmodifiable(api, key -> PaperAdventure.asVanilla(Registries.RECIPE, key))
@@ -139,6 +145,11 @@ public static void bootstrap() {
139145
// bees
140146
// register(DataComponents.LOCK, PaperLockCode::new);
141147
register(DataComponents.CONTAINER_LOOT, PaperSeededContainerLoot::new);
148+
register(DataComponents.BREAK_SOUND, nms -> PaperAdventure.asAdventureKey(nms.unwrapKey().get()), api -> BuiltInRegistries.SOUND_EVENT.getOrThrow(PaperAdventure.asVanilla(Registries.SOUND_EVENT, api)));
149+
register(DataComponents.VILLAGER_VARIANT, nms -> PaperAdventure.asAdventureKey(nms.unwrapKey().get()), api -> BuiltInRegistries.VILLAGER_TYPE.getOrThrow(PaperAdventure.asVanilla(Registries.VILLAGER_TYPE, api)));
150+
register(DataComponents.WOLF_VARIANT, CraftWolf.CraftVariant::minecraftHolderToBukkit, CraftWolf.CraftVariant::bukkitToMinecraftHolder);
151+
register(DataComponents.WOLF_COLLAR, nms -> DyeColor.getByWoolData((byte) nms.getId()), api -> net.minecraft.world.item.DyeColor.byId(api.getWoolData()));
152+
register(DataComponents.FOX_VARIANT, nms -> org.bukkit.entity.Fox.Type.values()[nms.ordinal()], api -> net.minecraft.world.entity.animal.Fox.Variant.byId(api.ordinal()));
142153
// TODO break_sound, provides_, entity data
143154
register(DataComponents.TOOLTIP_DISPLAY, PaperTooltipDisplay::new);
144155
register(DataComponents.WEAPON, PaperWeapon::new);

0 commit comments

Comments
 (0)