Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# RegistrateLib [![License](https://img.shields.io/github/license/ModularMCLib/RegistrateLib?cacheSeconds=36000)](https://www.tldrlegal.com/l/mpl-2.0) ![Minecraft Version](https://img.shields.io/badge/minecraft-26.1.1-blue)
# RegistrateLib [![License](https://img.shields.io/github/license/ModularMCLib/RegistrateLib?cacheSeconds=36000)](https://www.tldrlegal.com/l/mpl-2.0) ![Minecraft Version](https://img.shields.io/badge/minecraft-26.1.2-blue)

<!-- [![Build Status](https://img.shields.io/jenkins/build?jobUrl=https%3A%2F%2Fci.tterrag.com%2Fjob%2FRegistrate%2Fjob%2F1.21%2F)](https://ci.tterrag.com/job/Registrate/job/1.21) -->
<!-- [![Maven Version](https://img.shields.io/maven-metadata/v?metadataUrl=https%3A%2F%2Fmaven.tterrag.com%2Fcom%2Ftterrag%2Fregistrate%2FRegistrate%2Fmaven-metadata.xml)](https://maven.tterrag.com/com/tterrag/registrate/Registrate) -->
Expand All @@ -13,8 +13,8 @@ A powerful wrapper for creating and registering objects in your mod.

## 分支状态 / Fork Status

本仓库是 `com.modularmc.registrate` 命名空间下的 Registrate 分支,为 ModularMCLib 生态维护。它追踪上游 Registrate 的设计,同时面向现代 NeoForge + Minecraft `26.1` 工具链,并保留可安全嵌入下游项目的包命名空间。
This repository is the `com.modularmc.registrate` fork maintained for the ModularMCLib ecosystem. It tracks the upstream Registrate design while targeting the modern NeoForge + Minecraft `26.1` toolchain and preserving a package namespace that can be safely embedded in downstream projects.
本仓库是 `com.modularmc.registrate` 命名空间下的 Registrate 分支,为 ModularMCLib 生态维护。当前分支面向 Minecraft `26.1.2`、NeoForge `26.1.2.126` 和 Java `25`。
This repository is the `com.modularmc.registrate` fork maintained for the ModularMCLib ecosystem. This branch targets Minecraft `26.1.2`, NeoForge `26.1.2.126`, and Java `25`.

---

Expand Down Expand Up @@ -67,7 +67,7 @@ This repository is the `com.modularmc.registrate` fork maintained for the Modula
First, create a `Registrate` object which will be used across your entire project.

```java
public static final Registrate REGISTRATE = Registrate.create(MOD_ID);
public static final Registrate REGISTRATE = Registrate.create(MOD_ID).sourceLocale(MinecraftLocale.EN_US);
```

不一定要使用常量字段,可以在注册设置完成后传递或丢弃。
Expand All @@ -77,7 +77,8 @@ Using a constant field is not necessary, it can be passed around and thrown away
If declared static in your `@Mod` class, you must create the `Registrate` object lazily so it is not created too early during loading. This can be done easily like so:

```java
public static final NonNullSupplier<Registrate> REGISTRATE = NonNullSupplier.lazy(() -> Registrate.create(MOD_ID));
public static final NonNullSupplier<Registrate> REGISTRATE =
NonNullSupplier.lazy(() -> Registrate.create(MOD_ID).sourceLocale(MinecraftLocale.EN_US));
```

接下来,开始添加对象。
Expand Down Expand Up @@ -108,18 +109,19 @@ Registrate 会创建一个方块,并生成默认的简单方块状态、模型
Registrate will create a block, with a default simple blockstate, model, loot table, and lang entry. However, all of these facets can be configured easily to use whatever custom data you may want. Example:

```java
public static final RegistryEntry<MyStairsBlock> MY_STAIRS = REGISTRATE.block("my_block", MyStairsBlock::new)
.defaultItem()
public static final BlockEntry<MyStairsBlock> MY_STAIRS = REGISTRATE.block("my_stairs", MyStairsBlock::new)
.simpleItem()
.tag(BlockTags.STAIRS)
.blockstate(ctx -> ctx.getProvider()
.stairsBlock(ctx.getEntry(), ctx.getProvider().modLoc(ctx.getName())))
.blockstate(() -> (ctx, prov) -> prov.stairsBlock(ctx.getEntry(), prov.modBlockTexture(ctx.getName())))
.lang("Special Stairs")
.register();
```

这个自定义版本会创建 BlockItem(含默认模型和语言条目)、将方块添加到标签、配置楼梯属性方块状态,并添加自定义本地化。
This customized version will create a BlockItem (with its own default model and lang entry), add the block to a tag, configure the blockstate for stair properties, and add a custom localization.

源语言、译文和注解处理器的接入方式见 [本地化与迁移](docs/localization.md)。

<!-- 有关不同 API 和方法的概述,请查阅 [Javadocs](https://ci.tterrag.com/job/Registrate/job/1.21/javadoc/)。 -->
有关不同 API 和方法的概述,请查阅 Javadocs(待定)。更高级的用法请阅读 [维基](https://github.com/ModularMCLib/RegistrateLib/wiki)(编写中)。
<!-- To get an overview of the different APIs and methods, check out the [Javadocs](https://ci.tterrag.com/job/Registrate/job/1.21/javadoc/). -->
Expand Down
40 changes: 18 additions & 22 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import org.jetbrains.kotlin.gradle.dsl.JvmDefaultMode

plugins {
id 'java-library'
id 'org.jetbrains.kotlin.jvm'
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'jacoco'
alias libs.plugins.modDevGradle
//alias libs.plugins.shadow
alias libs.plugins.spotless
alias libs.plugins.lombok
alias libs.plugins.kotlin.jvm
alias libs.plugins.ksp
}

group = maven_group
Expand All @@ -21,6 +23,13 @@ java {
toolchain.languageVersion = JavaLanguageVersion.of(25)
}

kotlin {
jvmToolchain(25)
compilerOptions {
jvmDefault = JvmDefaultMode.NO_COMPATIBILITY
}
}

sourceSets {
// Include resources generated by data generators.
main.resources {
Expand Down Expand Up @@ -79,20 +88,17 @@ apply from: "$rootDir/gradle/scripts/resources.gradle"
apply from: "$rootDir/gradle/scripts/publishing.gradle"
apply from: "$rootDir/gradle/scripts/spotless.gradle"


tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
options.compilerArgs << '-Xmaxerrs' << '2000'
options.compilerArgs << "-Xlint:-removal"
}

tasks.named('test') {
// The test source set is exercised by NeoForge's GameTest server.
failOnNoDiscoveredTests = false
}

lombok {
version = "1.18.38"
}

jacoco {
applyTo runGameTestServer
}
Expand All @@ -102,28 +108,18 @@ tasks.named('runGameTestServer') {
}

jacocoTestReport {
doFirst {
try {
runGameTestServer.exec()
} catch (RuntimeException ignored) {}
}
doLast {
println "Coverage report location:"
println " - file://${layout.buildDirectory.dir('coverage').map(a -> a.file('index.html')).get()}"
println " - file://${layout.buildDirectory.dir('coverage').map(a -> a.file('coverage.xml')).get()}"
}
dependsOn runGameTestServer
executionData runGameTestServer
sourceSets sourceSets.test
reports {
csv.required = false
xml.required = true
html.outputLocation = layout.buildDirectory.dir('coverage')
xml.outputLocation = layout.buildDirectory.dir('coverage').map(a -> a.file('coverage.xml'))
xml.outputLocation = layout.buildDirectory.file('coverage/coverage.xml')
}
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: '**/client/**')
fileTree(dir: it, exclude: '**/mixins/**')
}))
classDirectories.setFrom(classDirectories.asFileTree.matching {
exclude '**/client/**', '**/mixins/**'
})
}
}
6 changes: 6 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
dependencies {
compileOnly(libs.jetbrains.annotations)
compileOnly(libs.jspecify)

jarJar(api(libs.kotlin.stdlib.get())) {
exclude group: 'org.jetbrains', module: 'annotations'
}
testImplementation(libs.testframework.get())
testAnnotationProcessor(project(':localization-processor'))
kspTest(project(':localization-processor'))

// Standard runtime mods //
localRuntime(libs.testframework)
Expand Down
7 changes: 3 additions & 4 deletions docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,13 @@ REGISTRATE.fluid("my_fluid", still, flow, FluidType::new)
```java
// 方块着色 / Block tinting
REGISTRATE.block("my_block", MyBlock::new)
.color(() -> () -> List.of(
BlockTintSources.constant(0xFFFF0000) // 红色着色 / Red tint
))
.color(() -> () -> (state, level, pos, tintIndex) -> 0xFF0000)
.register();

// 物品模型着色(通过 ItemBuilder)/ Item model tinting (via ItemBuilder)
REGISTRATE.item("my_item", Item::new)
.defaultModel(new ItemTintSource("layer0", Constant.create(0xFFFF0000)))
.defaultModel()
.color(() -> () -> (stack, tintIndex) -> tintIndex == 0 ? 0xFF0000 : -1)
.register();
```

Expand Down
4 changes: 2 additions & 2 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,5 @@ Treat the root package plus `builders` and `util.entry` as the main downstream-f
Keep public entrypoints small and push complexity into focused layers
- 对下游模组预期集成的扩展点进行文档化
Document extension points where downstream mods are expected to integrate
- 在此开发分支上,优先采用 26.1 原生结构而非保持遗留兼容性
Favor 26.1-native structure over preserving legacy compatibility on this dev branch
- 使用 Minecraft 26.1.2 和 NeoForge 的模型、配方与注册 API
Use the Minecraft 26.1.2 and NeoForge model, recipe, and registry APIs
19 changes: 9 additions & 10 deletions docs/builders.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ registrate.block("my_block", MyBlock::new)
| `item(NonNullBiFunction)` | 使用自定义工厂创建 BlockItem / Create BlockItem with a custom factory |
| `simpleBlockEntity(BlockEntityFactory)` | 快速创建没有额外配置的方块实体 / Quickly create a block entity without extra configuration |
| `blockEntity(BlockEntityFactory)` | 返回 `BlockEntityBuilder` 用于完全配置方块实体 / Return BlockEntityBuilder for full BE configuration |
| `color(NonNullSupplier<Supplier<List<BlockTintSource>>>)` | 设置方块着色器 / Set block tint sources |
| `color(NonNullSupplier<Supplier<List<BlockTintSource>>>)` | 按索引注册方块着色源 / Register indexed block tint sources |
| `defaultBlockstate()` | 使用默认方块状态生成 / Use default blockstate generation |
| `blockstate(NonNullSupplier<NonNullBiConsumer>)` | 自定义方块状态生成 / Custom blockstate generation |
| `defaultLang()` | 自动生成语言条目 / Auto-generate lang entry |
Expand All @@ -101,10 +101,9 @@ registrate.block("my_block", MyBlock::new)
```java
public static final BlockEntry<MyStairsBlock> MY_STAIRS = REGISTRATE
.block("my_stairs", MyStairsBlock::new)
.defaultItem() // 或 .item() 进行自定义 / or .item() for custom
.simpleItem() // 或 .item() 进行自定义 / or .item() for custom
.tag(BlockTags.STAIRS)
.blockstate(ctx -> ctx.getProvider()
.stairsBlock(ctx.getEntry(), ctx.getProvider().modLoc(ctx.getName())))
.blockstate(() -> (ctx, prov) -> prov.stairsBlock(ctx.getEntry(), prov.modBlockTexture(ctx.getName())))
.lang("Special Stairs")
.register();
```
Expand All @@ -130,6 +129,7 @@ public class ItemBuilder<T extends Item, P>
| `tab(ResourceKey<CreativeModeTab>, ...)` | 添加到创造模式标签页 / Add to creative mode tab |
| `removeTab(ResourceKey<CreativeModeTab>)` | 从标签页移除 / Remove from tab |
| `defaultModel()` | 使用默认物品模型 / Use default item model |
| `defaultModel(ItemTintSource...)` | 为默认模型指定着色源 / Generate a default model with tints |
| `model(NonNullSupplier<NonNullBiConsumer>)` | 自定义物品模型 / Custom item model |
| `defaultLang()` | 自动生成语言条目 / Auto-generate lang entry |
| `lang(String)` | 自定义语言名称 / Custom lang name |
Expand Down Expand Up @@ -247,8 +247,8 @@ public class FluidBuilder<T extends BaseFlowingFluid, P>
```java
// 基本创建(默认 FluidType)/ Basic creation (default FluidType)
registrate.fluid("my_fluid",
Identifier.of("minecraft:block/water_still"),
Identifier.of("minecraft:block/water_flow"),
Identifier.withDefaultNamespace("block/water_still"),
Identifier.withDefaultNamespace("block/water_flow"),
FluidType::new)
```

Expand All @@ -270,8 +270,7 @@ registrate.fluid("my_fluid",
| `bucket()` | 返回 `ItemBuilder` 配置流体桶 / Return ItemBuilder for bucket |
| `bucket(NonNullBiFunction)` | 自定义桶 / Custom bucket |
| `noBucket()` | 不生成桶 / Skip bucket generation |
| `model(Identifier, Identifier)` | 设置静态和流动纹理 / Set still and flowing textures |
| `model(NonNullSupplier)` | 自定义模型 / Custom model |
| `model(Identifier, Identifier)` | 设置静态和流动纹理 / Set still and flowing textures |
| `clientExtension(NonNullSupplier)` | 添加客户端流体类型扩展 / Add client fluid type extensions |
| `tag(TagKey<Fluid>...)` | 添加流体标签 / Add fluid tags |
| `removeTag(TagKey<Fluid>...)` | 移除流体标签 / Remove fluid tags |
Expand All @@ -282,8 +281,8 @@ registrate.fluid("my_fluid",
```java
public static final FluidEntry<BaseFlowingFluid.Flowing> MY_FLUID = REGISTRATE
.fluid("my_fluid",
Identifier.of("minecraft:block/water_still"),
Identifier.of("minecraft:block/water_flow"),
Identifier.withDefaultNamespace("block/water_still"),
Identifier.withDefaultNamespace("block/water_flow"),
FluidType::new)
.properties(p -> p.lightLevel(15).canConvertToSource(true))
.register();
Expand Down
11 changes: 6 additions & 5 deletions docs/entries.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public class ItemProviderEntry<R extends ItemLike, T extends R>
|---------------------|-------------------------------------------------------------------------|
| `asStack()` | 创建包含此物品的 `ItemStack`(数量 1)/ Create an ItemStack (count 1) |
| `asStack(int)` | 创建指定数量的 `ItemStack` / Create an ItemStack with specified count |
| `asStackTemplate()` | 创建 `ItemStackTemplate`(用于配方)/ Create an ItemStackTemplate (for recipes) |
| `isIn(ItemStack)` | 检查物品栈是否包含此物品 / Check if a stack contains this item |
| `is(Item)` | 检查是否特定物品 / Check if specific item |
| `asItem()` | 获取 `Item` 对象 / Get the Item object |
Expand Down Expand Up @@ -161,7 +160,7 @@ public class EntityEntry<T extends Entity>

| 方法 / Method | 描述 / Description |
|------------------------------------|-----------------------------------------------|
| `create(Level, EntitySpawnReason)` | 创建实体实例 / Create an entity instance |
| `create(Level)` | 创建实体实例 / Create an entity instance |
| `is(Entity)` | 检查实体是否属于此类型 / Check if entity is of this type |
| `cast(RegistryEntry)` | 静态转换方法 / Static cast method |

Expand All @@ -170,9 +169,11 @@ public class EntityEntry<T extends Entity>
```java
// 生成实体
// Spawn entity
MyEntity entity = MY_ENTITY.create(level, EntitySpawnReason.SPAWN_EGG);
entity.setPos(x, y, z);
level.addFreshEntity(entity);
MyEntity entity = MY_ENTITY.create(level);
if (entity != null) {
entity.setPos(x, y, z);
level.addFreshEntity(entity);
}
```

---
Expand Down
4 changes: 2 additions & 2 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class MyMod {

// 简单方式(注意:需确保不在构造之前访问)
// Simple approach (ensure it's not accessed before construction)
public static final Registrate REGISTRATE = Registrate.create(MOD_ID);
public static final Registrate REGISTRATE = Registrate.create(MOD_ID).sourceLocale(MinecraftLocale.EN_US);

public MyMod(IEventBus modEventBus) {
// 在此处注册事件监听器
Expand All @@ -55,7 +55,7 @@ If you need lazy initialization to avoid creating too early during class loading

```java
public static final NonNullSupplier<Registrate> REGISTRATE =
NonNullSupplier.lazy(() -> Registrate.create(MOD_ID));
NonNullSupplier.lazy(() -> Registrate.create(MOD_ID).sourceLocale(MinecraftLocale.EN_US));
```

## 注册你的第一个对象 / Registering Your First Object
Expand Down
3 changes: 2 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RegistrateLib is a powerful fluent registration API wrapper for creating and reg

```java
// 创建 Registrate 实例 / Create a Registrate instance
public static final Registrate REGISTRATE = Registrate.create(MOD_ID);
public static final Registrate REGISTRATE = Registrate.create(MOD_ID).sourceLocale(MinecraftLocale.EN_US);

// 注册一个简单的方块 / Register a simple block
public static final BlockEntry<Block> MY_BLOCK = REGISTRATE.block("my_block", Block::new)
Expand All @@ -38,6 +38,7 @@ public static final ItemEntry<Item> MY_ITEM = REGISTRATE.item("my_item", Item::n
3. [注册条目](entries.md) — 注册返回的强类型句柄 / Strongly-typed registry entry handles
4. [数据提供者](providers.md) — 数据生成系统详解 / Data generation system in detail
5. [高级用法](advanced.md) — 自定义注册表、生命周期钩子等 / Custom registries, lifecycle hooks, and more
6. [本地化与迁移](localization.md) / Localization and migration

## 架构概述 / Architecture Overview

Expand Down
Loading
Loading