From 3f0dbe8b499ad9ff3ccc20d8247bd82efdbc3898 Mon Sep 17 00:00:00 2001 From: Gugle Date: Sat, 20 Jun 2026 17:47:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(registrum):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BB=84=E4=BB=B6=E8=B0=93=E8=AF=8D=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E5=99=A8=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 引入 DataComponentPredicateBuilder 类用于构建数据组件谓词 - 添加 DataComponentPredicateEntry 工具类用于注册表条目管理 - 在 AbstractRegistrum 中新增 dataComponentPredicate 相关方法 - 实现数据组件谓词类型的编解码器支持 - 添加完整的 JavaDoc 注释和 MIT 许可证声明 --- .../lib/v2/registrum/AbstractRegistrum.java | 38 ++++++++++++++ .../data/DataComponentPredicateBuilder.java | 50 +++++++++++++++++++ .../data/DataComponentPredicateEntry.java | 47 +++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 module.registrum/src/main/java/dev/anvilcraft/lib/v2/registrum/builders/data/DataComponentPredicateBuilder.java create mode 100644 module.registrum/src/main/java/dev/anvilcraft/lib/v2/registrum/util/entry/data/DataComponentPredicateEntry.java diff --git a/module.registrum/src/main/java/dev/anvilcraft/lib/v2/registrum/AbstractRegistrum.java b/module.registrum/src/main/java/dev/anvilcraft/lib/v2/registrum/AbstractRegistrum.java index 8c77bd41..c7abf115 100644 --- a/module.registrum/src/main/java/dev/anvilcraft/lib/v2/registrum/AbstractRegistrum.java +++ b/module.registrum/src/main/java/dev/anvilcraft/lib/v2/registrum/AbstractRegistrum.java @@ -41,6 +41,7 @@ import dev.anvilcraft.lib.v2.registrum.builders.MobEffectBuilder; import dev.anvilcraft.lib.v2.registrum.builders.NoConfigBuilder; import dev.anvilcraft.lib.v2.registrum.builders.SelfBuilder; +import dev.anvilcraft.lib.v2.registrum.builders.data.DataComponentPredicateBuilder; import dev.anvilcraft.lib.v2.registrum.builders.self.PotionBuilder; import dev.anvilcraft.lib.v2.registrum.builders.self.SoundEventBuilder; import dev.anvilcraft.lib.v2.registrum.builders.data.AttachmentBuilder; @@ -82,6 +83,7 @@ import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.core.Holder; import net.minecraft.core.Registry; +import net.minecraft.core.component.predicates.DataComponentPredicate; import net.minecraft.core.registries.Registries; import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.chat.Component; @@ -1656,6 +1658,42 @@ public DataComponentBuilder dataComponent(String name) { return dataComponent(self(), name); } + /** + * Release under the MIT License. The full license text is available at this + * + * @author Gugle + */ + public DataComponentBuilder dataComponent(String name, Class clazz) { + return dataComponent(self(), name); + } + + /** + * Release under the MIT License. The full license text is available at this + * + * @author Gugle + */ + protected DataComponentPredicateBuilder dataComponentPredicate(P parent, String name) { + return entry(name, callback -> new DataComponentPredicateBuilder<>(this, parent, name, callback)); + } + + /** + * Release under the MIT License. The full license text is available at this + * + * @author Gugle + */ + public DataComponentBuilder dataComponentPredicate(String name) { + return dataComponent(self(), name); + } + + /** + * Release under the MIT License. The full license text is available at this + * + * @author Gugle + */ + public DataComponentBuilder dataComponentPredicate(String name, Class clazz) { + return dataComponent(self(), name); + } + // Biome Modifier /** diff --git a/module.registrum/src/main/java/dev/anvilcraft/lib/v2/registrum/builders/data/DataComponentPredicateBuilder.java b/module.registrum/src/main/java/dev/anvilcraft/lib/v2/registrum/builders/data/DataComponentPredicateBuilder.java new file mode 100644 index 00000000..6d751018 --- /dev/null +++ b/module.registrum/src/main/java/dev/anvilcraft/lib/v2/registrum/builders/data/DataComponentPredicateBuilder.java @@ -0,0 +1,50 @@ +package dev.anvilcraft.lib.v2.registrum.builders.data; + +import com.mojang.serialization.Codec; +import dev.anvilcraft.lib.v2.registrum.AbstractRegistrum; +import dev.anvilcraft.lib.v2.registrum.builders.AbstractBuilder; +import dev.anvilcraft.lib.v2.registrum.builders.BuilderCallback; +import dev.anvilcraft.lib.v2.registrum.util.entry.data.DataComponentPredicateEntry; +import net.minecraft.core.component.predicates.DataComponentPredicate; +import net.minecraft.core.registries.Registries; +import net.neoforged.neoforge.registries.DeferredHolder; +import org.jspecify.annotations.Nullable; + +public class DataComponentPredicateBuilder + extends AbstractBuilder, DataComponentPredicate.Type, P, DataComponentPredicateBuilder> { + @Nullable Codec codec; + + public DataComponentPredicateBuilder( + AbstractRegistrum owner, + P parent, + String name, + BuilderCallback callback + ) { + super(owner, parent, name, callback, Registries.DATA_COMPONENT_PREDICATE_TYPE); + } + + public DataComponentPredicateBuilder codec(Codec codec) { + this.codec = codec; + return this; + } + + @Override + protected DataComponentPredicate.Type createEntry() { + if (this.codec == null) { + throw new IllegalStateException("Codec is not set"); + } + return new DataComponentPredicate.ConcreteType<>(this.codec); + } + + @Override + protected DataComponentPredicateEntry createEntryWrapper( + DeferredHolder, DataComponentPredicate.Type> delegate + ) { + return new DataComponentPredicateEntry<>(this.getOwner(), delegate); + } + + @Override + public DataComponentPredicateEntry register() { + return (DataComponentPredicateEntry) super.register(); + } +} diff --git a/module.registrum/src/main/java/dev/anvilcraft/lib/v2/registrum/util/entry/data/DataComponentPredicateEntry.java b/module.registrum/src/main/java/dev/anvilcraft/lib/v2/registrum/util/entry/data/DataComponentPredicateEntry.java new file mode 100644 index 00000000..8c695c7b --- /dev/null +++ b/module.registrum/src/main/java/dev/anvilcraft/lib/v2/registrum/util/entry/data/DataComponentPredicateEntry.java @@ -0,0 +1,47 @@ +/* + * + * Original work copyright (c) 2026 Anvil-Dev (AnvilLib-Registrum) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +package dev.anvilcraft.lib.v2.registrum.util.entry.data; + +import dev.anvilcraft.lib.v2.registrum.AbstractRegistrum; +import dev.anvilcraft.lib.v2.registrum.util.entry.RegistryEntry; +import net.minecraft.core.component.predicates.DataComponentPredicate; +import net.neoforged.neoforge.registries.DeferredHolder; + +public class DataComponentPredicateEntry + extends RegistryEntry, DataComponentPredicate.Type> { + + public DataComponentPredicateEntry( + AbstractRegistrum owner, + DeferredHolder, DataComponentPredicate.Type> key + ) { + super(owner, key); + } + + public static DataComponentPredicateEntry cast( + RegistryEntry, DataComponentPredicate.Type> entry + ) { + return RegistryEntry.cast(DataComponentPredicateEntry.class, entry); + } +} From 659f84a95fd484fb6ab8a07c54f2752329bf0254 Mon Sep 17 00:00:00 2001 From: Gugle Date: Sat, 20 Jun 2026 18:02:21 +0800 Subject: [PATCH 2/2] =?UTF-8?q?chore(workflow):=20=E6=B7=BB=E5=8A=A0=20iss?= =?UTF-8?q?ues=20=E5=86=99=E6=9D=83=E9=99=90=E5=88=B0=20pull=20request=20?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 为 pull request 工作流添加 issues 写权限 - 保持现有的 actions、packages 和 pull-requests 权限配置 - 新增的 issues 权限允许工作流创建或更新相关议题 --- .github/workflows/pull_request.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 234bf631..33dc5af0 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -22,6 +22,7 @@ permissions: actions: read packages: read pull-requests: write + issues: write jobs: codec: