diff options
author | Jake Potrebic <[email protected]> | 2024-06-03 21:39:30 -0700 |
---|---|---|
committer | Owen1212055 <[email protected]> | 2024-11-18 14:50:37 -0500 |
commit | be61121b6cb90c1c80eff022b5fcd4c436e171ee (patch) | |
tree | 76dc19498985d7938d8dc0e98c33578fc29d61b0 | |
parent | cd5149c36239b89b1cb3a9cf9556cbd574fbe4f7 (diff) | |
download | Paper-be61121b6cb90c1c80eff022b5fcd4c436e171ee.tar.gz Paper-be61121b6cb90c1c80eff022b5fcd4c436e171ee.zip |
add blockdata component
-rw-r--r-- | patches/api/0485-WIP-DataComponent-API.patch | 52 | ||||
-rw-r--r-- | patches/server/1054-WIP-DataComponent-API.patch | 104 |
2 files changed, 139 insertions, 17 deletions
diff --git a/patches/api/0485-WIP-DataComponent-API.patch b/patches/api/0485-WIP-DataComponent-API.patch index b4a2697a44..ca0aab69fb 100644 --- a/patches/api/0485-WIP-DataComponent-API.patch +++ b/patches/api/0485-WIP-DataComponent-API.patch @@ -39,13 +39,14 @@ index 0000000000000000000000000000000000000000..50d15b4e0ed5cd17fdc95476ee4650ef +} diff --git a/src/main/java/io/papermc/paper/component/DataComponentTypes.java b/src/main/java/io/papermc/paper/component/DataComponentTypes.java new file mode 100644 -index 0000000000000000000000000000000000000000..e094dbc6919ee7fe08270e8865f80375b4dc7f8a +index 0000000000000000000000000000000000000000..dfb4bfa4183818d7aa6a714979b5f7b8808867f0 --- /dev/null +++ b/src/main/java/io/papermc/paper/component/DataComponentTypes.java -@@ -0,0 +1,111 @@ +@@ -0,0 +1,112 @@ +package io.papermc.paper.component; + +import io.papermc.paper.component.item.BannerPatternLayers; ++import io.papermc.paper.component.item.BlockItemDataProperties; +import io.papermc.paper.component.item.BundleContents; +import io.papermc.paper.component.item.ChargedProjectiles; +import io.papermc.paper.component.item.CustomModelData; @@ -78,7 +79,6 @@ index 0000000000000000000000000000000000000000..e094dbc6919ee7fe08270e8865f80375 +import org.bukkit.NamespacedKey; +import org.bukkit.Registry; +import org.bukkit.inventory.ItemRarity; -+import org.bukkit.inventory.meta.WritableBookMeta; +import java.security.Key; +import java.util.List; + @@ -86,6 +86,7 @@ index 0000000000000000000000000000000000000000..e094dbc6919ee7fe08270e8865f80375 + +public final class DataComponentTypes { + ++ // public static final DataComponentType.Valued<BinaryTagHolder> CUSTOM_DATA = valued("custom_data"); + public static final DataComponentType.Valued<Integer> MAX_STACK_SIZE = valued("max_stack_size"); + public static final DataComponentType.Valued<Integer> MAX_DAMAGE = valued("max_damage"); + public static final DataComponentType.Valued<Integer> DAMAGE = valued("damage"); @@ -137,7 +138,7 @@ index 0000000000000000000000000000000000000000..e094dbc6919ee7fe08270e8865f80375 + public static final DataComponentType.Valued<DyeColor> BASE_COLOR = valued("base_color"); + public static final DataComponentType.Valued<PotDecorations> POT_DECORATIONS = valued("pot_decorations"); + public static final DataComponentType.Valued<ItemContainerContents> CONTAINER = valued("container"); -+ // block_state ++ public static final DataComponentType.Valued<BlockItemDataProperties> BLOCK_DATA = valued("block_state"); + // bees + public static final DataComponentType.Valued<LockCode> LOCK = valued("lock"); + public static final DataComponentType.Valued<SeededContainerLoot> CONTAINER_LOOT = valued("container_loot"); @@ -193,6 +194,43 @@ index 0000000000000000000000000000000000000000..76331ddfbd6e8b70b101c1152235d624 + @NonNull BannerPatternLayers build(); + } +} +diff --git a/src/main/java/io/papermc/paper/component/item/BlockItemDataProperties.java b/src/main/java/io/papermc/paper/component/item/BlockItemDataProperties.java +new file mode 100644 +index 0000000000000000000000000000000000000000..1bbea041d6424ba0ccb1b23024566deb919a7c55 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/component/item/BlockItemDataProperties.java +@@ -0,0 +1,31 @@ ++package io.papermc.paper.component.item; ++ ++import org.bukkit.Material; ++import org.bukkit.block.data.BlockData; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.jetbrains.annotations.ApiStatus; ++import org.jetbrains.annotations.Contract; ++ ++public interface BlockItemDataProperties { ++ ++ @Contract(value = "-> new", pure = true) ++ static BlockItemDataProperties.@NonNull Builder blockItemStateProperties() { ++ return ComponentTypesBridge.bridge().blockItemStateProperties(); ++ } ++ ++ @Contract(pure = true) ++ @NonNull BlockData createBlockData(@NonNull Material blockType); ++ ++ @Contract(pure = true) ++ @NonNull BlockData applyToBlockData(@NonNull BlockData blockData); ++ ++ @ApiStatus.NonExtendable ++ interface Builder { ++ // building this requires BlockProperty API, so an empty builder for now (essentially read-only) ++ ++ @Contract(value = "-> new", pure = true) ++ @NonNull ++ BlockItemDataProperties build(); ++ } ++} diff --git a/src/main/java/io/papermc/paper/component/item/BundleContents.java b/src/main/java/io/papermc/paper/component/item/BundleContents.java new file mode 100644 index 0000000000000000000000000000000000000000..8ce39bac83316a7315eae4c99cb6666ba5876b7c @@ -273,10 +311,10 @@ index 0000000000000000000000000000000000000000..7b8195dfa17226f1bf5bf33341c222e3 +} diff --git a/src/main/java/io/papermc/paper/component/item/ComponentTypesBridge.java b/src/main/java/io/papermc/paper/component/item/ComponentTypesBridge.java new file mode 100644 -index 0000000000000000000000000000000000000000..5bef3cfbd232483d09e62c8744e4f21cf186ce0c +index 0000000000000000000000000000000000000000..6b00f5383bb3c957da62d2abe675f0d3059bad33 --- /dev/null +++ b/src/main/java/io/papermc/paper/component/item/ComponentTypesBridge.java -@@ -0,0 +1,74 @@ +@@ -0,0 +1,76 @@ +package io.papermc.paper.component.item; + +import io.papermc.paper.util.Filtered; @@ -347,6 +385,8 @@ index 0000000000000000000000000000000000000000..5bef3cfbd232483d09e62c8744e4f21c + + BannerPatternLayers.Builder bannerPatternLayers(); + ++ BlockItemDataProperties.Builder blockItemStateProperties(); ++ + LockCode.Builder lockCode(); + + ItemContainerContents.Builder itemContainerContents(); diff --git a/patches/server/1054-WIP-DataComponent-API.patch b/patches/server/1054-WIP-DataComponent-API.patch index dc273d0ef5..635b08867a 100644 --- a/patches/server/1054-WIP-DataComponent-API.patch +++ b/patches/server/1054-WIP-DataComponent-API.patch @@ -40,14 +40,16 @@ index 0000000000000000000000000000000000000000..e538819c873a324c58bcd8e73f89510e +} diff --git a/src/main/java/io/papermc/paper/component/ComponentAdapters.java b/src/main/java/io/papermc/paper/component/ComponentAdapters.java new file mode 100644 -index 0000000000000000000000000000000000000000..ad40c6e7b96471e21a43fddd73e55031e39a64a8 +index 0000000000000000000000000000000000000000..067930a2f5d3655f74a52c75a10d1d2958c1adfa --- /dev/null +++ b/src/main/java/io/papermc/paper/component/ComponentAdapters.java -@@ -0,0 +1,165 @@ +@@ -0,0 +1,181 @@ +package io.papermc.paper.component; + ++import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.papermc.paper.adventure.PaperAdventure; +import io.papermc.paper.component.item.PaperBannerPatternLayers; ++import io.papermc.paper.component.item.PaperBlockItemDataProperties; +import io.papermc.paper.component.item.PaperBundleContents; +import io.papermc.paper.component.item.PaperChargedProjectiles; +import io.papermc.paper.component.item.PaperCustomModelData; @@ -70,22 +72,25 @@ index 0000000000000000000000000000000000000000..ad40c6e7b96471e21a43fddd73e55031 +import io.papermc.paper.component.item.PaperSeededContainerLoot; +import io.papermc.paper.component.item.PaperSuspiciousStewEffects; +import io.papermc.paper.component.item.PaperUnbreakable; ++import io.papermc.paper.component.item.PaperWritableBookContent; ++import io.papermc.paper.component.item.PaperWrittenBookContent; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Function; -+import io.papermc.paper.component.item.PaperWritableBookContent; -+import io.papermc.paper.component.item.PaperWrittenBookContent; +import net.kyori.adventure.key.Key; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.core.component.DataComponents; +import net.minecraft.core.registries.BuiltInRegistries; ++import net.minecraft.nbt.CompoundTag; ++import net.minecraft.nbt.Tag; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.Unit; +import net.minecraft.world.item.Rarity; ++import net.minecraft.world.item.component.CustomData; +import net.minecraft.world.item.component.MapPostProcessing; +import org.bukkit.DyeColor; +import org.bukkit.craftbukkit.CraftMusicInstrument; @@ -106,7 +111,18 @@ index 0000000000000000000000000000000000000000..ad40c6e7b96471e21a43fddd73e55031 + static final Map<ResourceKey<DataComponentType<?>>, ComponentAdapter<?, ?>> ADAPTERS = new HashMap<>(); + + public static void bootstrap() { -+ // custom data ++ //noinspection deprecation ++ register(DataComponents.CUSTOM_DATA, data -> PaperAdventure.asBinaryTagHolder(data.getUnsafe()), holder -> { // unsafe is fine because it serializes right away ++ try { ++ final Tag tag = holder.get(PaperAdventure.NBT_CODEC); ++ if (!(tag instanceof final CompoundTag compoundTag)) { ++ throw new IllegalArgumentException(holder + " doesn't represent a compound tag"); ++ } ++ return CustomData.of(compoundTag); ++ } catch (final CommandSyntaxException e) { ++ throw new RuntimeException(e); ++ } ++ }); + registerIdentity(DataComponents.MAX_STACK_SIZE); + registerIdentity(DataComponents.MAX_DAMAGE); + registerIdentity(DataComponents.DAMAGE); @@ -156,9 +172,9 @@ index 0000000000000000000000000000000000000000..ad40c6e7b96471e21a43fddd73e55031 + + return Collections.unmodifiableList(api); + }, api -> { -+ List<ResourceLocation> nms = new ArrayList<>(api.size()); -+ for (Key key : api) { -+ nms.add(new ResourceLocation(key.namespace(), key.value())); ++ final List<ResourceLocation> nms = new ArrayList<>(api.size()); ++ for (final Key key : api) { ++ nms.add(PaperAdventure.asVanilla(key)); + } + + return Collections.unmodifiableList(nms); @@ -172,7 +188,7 @@ index 0000000000000000000000000000000000000000..ad40c6e7b96471e21a43fddd73e55031 + register(DataComponents.BASE_COLOR, nms -> DyeColor.getByWoolData((byte) nms.getId()), api -> net.minecraft.world.item.DyeColor.byId(api.getWoolData())); + register(DataComponents.POT_DECORATIONS, PaperPotDecorations::new); + register(DataComponents.CONTAINER, PaperItemContainerContents::new); -+ // block state (block data) ++ register(DataComponents.BLOCK_STATE, PaperBlockItemDataProperties::new); + // bees + register(DataComponents.LOCK, PaperLockCode::new); + register(DataComponents.CONTAINER_LOOT, PaperSeededContainerLoot::new); @@ -335,10 +351,10 @@ index 0000000000000000000000000000000000000000..5639559368e6866e9b0afa6688f3b12c +} diff --git a/src/main/java/io/papermc/paper/component/item/ComponentTypesBridgesImpl.java b/src/main/java/io/papermc/paper/component/item/ComponentTypesBridgesImpl.java new file mode 100644 -index 0000000000000000000000000000000000000000..649070a5b6c249b7810d0eeae5afbc3fcb490384 +index 0000000000000000000000000000000000000000..5c26aec36c4e2ad2cc683735485f139cb32c05be --- /dev/null +++ b/src/main/java/io/papermc/paper/component/item/ComponentTypesBridgesImpl.java -@@ -0,0 +1,145 @@ +@@ -0,0 +1,150 @@ +package io.papermc.paper.component.item; + +import io.papermc.paper.util.Filtered; @@ -480,6 +496,11 @@ index 0000000000000000000000000000000000000000..649070a5b6c249b7810d0eeae5afbc3f + } + + @Override ++ public BlockItemDataProperties.Builder blockItemStateProperties() { ++ return new PaperBlockItemDataProperties.BuilderImpl(); ++ } ++ ++ @Override + public LockCode.Builder lockCode() { + return new PaperLockCode.BuilderImpl(); + } @@ -596,6 +617,67 @@ index 0000000000000000000000000000000000000000..3077a38a5b33b155ea23ebf163c5c4c4 + } + } +} +diff --git a/src/main/java/io/papermc/paper/component/item/PaperBlockItemDataProperties.java b/src/main/java/io/papermc/paper/component/item/PaperBlockItemDataProperties.java +new file mode 100644 +index 0000000000000000000000000000000000000000..ec156e305c4aebf2972082f6bde2390be8544269 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/component/item/PaperBlockItemDataProperties.java +@@ -0,0 +1,55 @@ ++package io.papermc.paper.component.item; ++ ++import com.google.common.base.Preconditions; ++import java.util.HashMap; ++import java.util.Map; ++import net.minecraft.world.item.component.BlockItemStateProperties; ++import net.minecraft.world.level.block.Block; ++import net.minecraft.world.level.block.state.BlockState; ++import org.bukkit.Material; ++import org.bukkit.block.data.BlockData; ++import org.bukkit.craftbukkit.block.CraftBlockType; ++import org.bukkit.craftbukkit.block.data.CraftBlockData; ++import org.bukkit.craftbukkit.util.Handleable; ++import org.checkerframework.checker.nullness.qual.NonNull; ++import org.checkerframework.framework.qual.DefaultQualifier; ++ ++@DefaultQualifier(NonNull.class) ++public record PaperBlockItemDataProperties( ++ BlockItemStateProperties impl ++) implements BlockItemDataProperties, Handleable<BlockItemStateProperties> { ++ ++ @Override ++ public BlockData createBlockData(final Material blockType) { ++ Preconditions.checkArgument(blockType.isBlock(), "%s is not a block", blockType); ++ final Block block = CraftBlockType.bukkitToMinecraft(blockType); ++ final BlockState defaultState = block.defaultBlockState(); ++ return this.impl.apply(defaultState).createCraftBlockData(); ++ } ++ ++ @Override ++ public BlockData applyToBlockData(final BlockData blockData) { ++ final BlockState state = ((CraftBlockData) blockData).getState(); ++ return this.impl.apply(state).createCraftBlockData(); ++ } ++ ++ @Override ++ public BlockItemStateProperties getHandle() { ++ return this.impl; ++ } ++ ++ static final class BuilderImpl implements BlockItemDataProperties.Builder { ++ ++ private final Map<String, String> properties = new HashMap<>(); ++ ++ // TODO when BlockProperty API is merged ++ ++ @Override ++ public BlockItemDataProperties build() { ++ if (this.properties.isEmpty()) { ++ return new PaperBlockItemDataProperties(BlockItemStateProperties.EMPTY); ++ } ++ return new PaperBlockItemDataProperties(new BlockItemStateProperties(Map.copyOf(this.properties))); ++ } ++ } ++} diff --git a/src/main/java/io/papermc/paper/component/item/PaperBundleContents.java b/src/main/java/io/papermc/paper/component/item/PaperBundleContents.java new file mode 100644 index 0000000000000000000000000000000000000000..db7b9104469e53a4eeefb4dde59167996898d011 |