From 3b35456b3f5773f6384c0ae5edd21549394cd3a4 Mon Sep 17 00:00:00 2001 From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Date: Wed, 4 Dec 2024 00:33:47 -0500 Subject: [PATCH] Implement assetid --- patches/api/0495-DataComponent-API.patch | 6 +++--- patches/server/1031-DataComponent-API.patch | 22 ++++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/patches/api/0495-DataComponent-API.patch b/patches/api/0495-DataComponent-API.patch index 7b2b1bc9e4..7f7c5480f1 100644 --- a/patches/api/0495-DataComponent-API.patch +++ b/patches/api/0495-DataComponent-API.patch @@ -1187,7 +1187,7 @@ index 0000000000000000000000000000000000000000..a128348247d8845321d3fecebaa09a51 +} diff --git a/src/main/java/io/papermc/paper/datacomponent/item/Equippable.java b/src/main/java/io/papermc/paper/datacomponent/item/Equippable.java new file mode 100644 -index 0000000000000000000000000000000000000000..135ebe0b84027073793c21c71d37eff496d23fec +index 0000000000000000000000000000000000000000..f72d412a09c710f30eb219abc25ca4c95d49f4b1 --- /dev/null +++ b/src/main/java/io/papermc/paper/datacomponent/item/Equippable.java @@ -0,0 +1,169 @@ @@ -1241,9 +1241,9 @@ index 0000000000000000000000000000000000000000..135ebe0b84027073793c21c71d37eff4 + Key equipSound(); + + /** -+ * Gets the model key if present. ++ * Gets the asset id if present. + * -+ * @return the model key or null ++ * @return the asset id or null + */ + @Contract(pure = true) + @Nullable Key assetId(); diff --git a/patches/server/1031-DataComponent-API.patch b/patches/server/1031-DataComponent-API.patch index af60a90785..729d60471f 100644 --- a/patches/server/1031-DataComponent-API.patch +++ b/patches/server/1031-DataComponent-API.patch @@ -1243,25 +1243,31 @@ index 0000000000000000000000000000000000000000..422e1a4d606481f0dc68843fbbc8126c +} diff --git a/src/main/java/io/papermc/paper/datacomponent/item/PaperEquippable.java b/src/main/java/io/papermc/paper/datacomponent/item/PaperEquippable.java new file mode 100644 -index 0000000000000000000000000000000000000000..cb4dd5b88da769f00060ad24ff4ccd8e0a40a1a6 +index 0000000000000000000000000000000000000000..f0c2b30069b2df060a39683636296567bce172a6 --- /dev/null +++ b/src/main/java/io/papermc/paper/datacomponent/item/PaperEquippable.java -@@ -0,0 +1,170 @@ +@@ -0,0 +1,174 @@ +package io.papermc.paper.datacomponent.item; + +import io.papermc.paper.adventure.PaperAdventure; ++import io.papermc.paper.registry.PaperRegistries; +import io.papermc.paper.registry.RegistryKey; +import io.papermc.paper.registry.set.PaperRegistrySets; +import io.papermc.paper.registry.set.RegistryKeySet; +import java.util.Optional; ++import java.util.function.Function; +import net.kyori.adventure.key.Key; +import net.minecraft.core.Holder; +import net.minecraft.core.HolderSet; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; ++import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; ++import net.minecraft.util.datafix.fixes.EquippableAssetRenameFix; ++import net.minecraft.world.item.equipment.EquipmentAsset; ++import net.minecraft.world.item.equipment.EquipmentAssets; +import org.bukkit.craftbukkit.CraftEquipmentSlot; +import org.bukkit.craftbukkit.util.Handleable; +import org.bukkit.entity.EntityType; @@ -1289,11 +1295,9 @@ index 0000000000000000000000000000000000000000..cb4dd5b88da769f00060ad24ff4ccd8e + + @Override + public @Nullable Key assetId() { -+ // TODO -+ throw new UnsupportedOperationException("Not yet implemented"); -+ //return this.impl.assetId() -+ // .map(PaperAdventure::asAdventure) -+ // .orElse(null); ++ return this.impl.assetId() ++ .map(PaperAdventure::asAdventureKey) ++ .orElse(null); + } + + @Override @@ -1342,7 +1346,7 @@ index 0000000000000000000000000000000000000000..cb4dd5b88da769f00060ad24ff4ccd8e + + private final net.minecraft.world.entity.EquipmentSlot equipmentSlot; + private Holder equipSound = SoundEvents.ARMOR_EQUIP_GENERIC; -+ private Optional assetId = Optional.empty(); ++ private Optional> assetId = Optional.empty(); + private Optional cameraOverlay = Optional.empty(); + private Optional>> allowedEntities = Optional.empty(); + private boolean dispensable = true; @@ -1362,7 +1366,7 @@ index 0000000000000000000000000000000000000000..cb4dd5b88da769f00060ad24ff4ccd8e + @Override + public Builder assetId(final @Nullable Key model) { + this.assetId = Optional.ofNullable(model) -+ .map(PaperAdventure::asVanilla); ++ .map(key -> PaperAdventure.asVanilla(EquipmentAssets.ROOT_ID, key)); + + return this; + }