TFC Registry API
一个轻量级的库模组,能够自动发现并统一所有由任何模组添加的 TerraFirmaCraft 注册表类型。它适用于任意附加模组,只要它们正确实现了此库的注册表接口或 TFC 自身的接口:
RegistryMetal
RegistryRock
RegistrySoilVariant
RegistryWood
由本库提供的注册表类型包括:
RegistryOre
RegistrySand
RegistrySoil
发现机制工作原理
当满足以下条件时,该模组会自动发现所有类型:
- 该类型实现了正确的
Registry[Type] 接口
- 该类型是一个 枚举(这是自动发现的必要条件)
如果某个附加模组没有使用枚举,或者需要手动注册,附加模组的开发者仍可以通过直接调用辅助注册方法来支持它:
示例:从非枚举源手动注册土壤变体
SoilVariantRegistryHelper.registerTypes(
YourSoilVariantClass.class,
List.of(yourVariant1, yourVariant2, ...),
"yourmodid"
);
每个辅助类中都有相同的方法:
MetalRegistryHelper.registerTypes(...)
WoodRegistryHelper.registerTypes(...)
RockRegistryHelper.registerTypes(...)
OreRegistryHelper.registerTypes(...)
SoilRegistryHelper.registerTypes(...)
SandRegistryHelper.registerTypes(...)
SoilVariantRegistryHelper.registerTypes(...)
代码示例:
// 金属
List<RegistryMetal> allMetals = MetalRegistryHelper.getAllMetalValues();
RegistryMetal brass = MetalRegistryHelper.getMetalValueOrDefault("brass");
// 木材
List<RegistryWood> allWoods = WoodRegistryHelper.getAllWoodValues();
RegistryWood ebony = WoodRegistryHelper.getWoodValueOrDefault("ebony");
// 岩石
List<RegistryRock> allRocks = RockRegistryHelper.getAllRockValues();
RegistryRock marble = RockRegistryHelper.getRockValueOrDefault("marble");
// 矿石
List<RegistryOre> allOres = OreRegistryHelper.getAllOreValues();
RegistryOre sphalerite = OreRegistryHelper.getOreValueOrDefault("sphalerite");
// 土壤
List<RegistrySoil> allSoils = SoilRegistryHelper.getAllSoilValues();
RegistrySoil duff = SoilRegistryHelper.getSoilValueOrDefault("duff");
// 沙子颜色
List<RegistrySand> allSands = SandRegistryHelper.getAllSandValues();
RegistrySand white = SandRegistryHelper.getSandValueOrDefault("white");
// 土壤变体
List<RegistrySoilVariant> allVariants = SoilVariantRegistryHelper.getAllSoilVariantValues();
RegistrySoilVariant inceptisol = SoilVariantRegistryHelper.getSoilVariantValueOrDefault("inceptisol");
所有 get[Type]ValueOrDefault("name") 方法均不区分大小写,并在未找到时返回安全回退值。
例如,遍历 List<RegistryWood> 列表,可以生成如下木材类型列表,这里展示了安装了 ArborFirmaCraft 的情况:
acacia, ash, aspen, birch, blackwood, chestnut, douglas_fir, hickory, kapok, mangrove, maple, oak, palm, pine, rosewood, sequoia, spruce, sycamore, white_cedar, willow, araucaria, baobab, beech, cypress, eucalyptus, fig, ginkgo, hevea, ipe, ironwood, mahoe, mahogany, teak, tualang
你可以轻松使用辅助类提供的列表/获取器来注册新方块。以下展示了如何为所有已注册的土壤类型和土壤变体添加新的 SoilBlock 的示例:
public static final Map<RegistrySoil, Map<RegistrySoilVariant, Id<Block>>> NEW_SOIL_BLOCKS =
SoilRegistryHelper.getAllSoilValues().stream()
.collect(Collectors.toMap(
type -> type,
type -> SoilVariantRegistryHelper.getAllSoilVariantValues().stream()
.collect(Collectors.toMap(
variant -> variant,
variant -> register(type.toString() + "/" + variant.toString(),
() -> new SoilBlock(Block.Properties.of().mapColor(MapColor.DIRT).strength(1.4f), type, variant))
))
));
例如:如果一个方块/物品/实体等构造函数 坚持 使用诸如 SoilBlockType 之类的类型(如 ConnectedGrassBlock),你可以安全地将来自 RegistrySoil 接口的 soil 强制转换为此类型,像这样 (RegistrySoil)(Object)soil(或者以你喜欢的其他方式进行转换),因为我已让 TFC 的 SoilBlockType 枚举类实现了自定义的 RegistrySoil 接口。
非常适合附加模组、整合包制作者,或任何需要与所有兼容 TFC 的金属、木材、岩石、矿石、土壤、沙子或变体协同工作的场景,无论安装了哪些模组。
例如,你可以使用本库创建的注册表类型列表,轻松为所有或特定类型的所需条目创建新的方块、物品、实体等。
TFC Registry API
A lightweight library mod that automatically discovers and unifies all TerraFirmaCraft registry types added by any mod. It works with any addon, as long as they correctly implement this library's registry interfaces or TFC's own:
RegistryMetal
RegistryRock
RegistrySoilVariant
RegistryWood
Where these are provided by this library:
RegistryOre
RegistrySand
RegistrySoil
How discovery works
The mod automatically finds all types if:
- The type implements the correct
Registry[Type] interface
- The type is an enum (required for auto-discovery)
If an addon does not use enums or needs manual registration, it can still be supported by the addon developer by calling the helper registration methods directly:
Example: manually register soil variants from a non-enum source
SoilVariantRegistryHelper.registerTypes(
YourSoilVariantClass.class,
List.of(yourVariant1, yourVariant2, ...),
"yourmodid"
);
Same method exists in every helper class:
MetalRegistryHelper.registerTypes(...)
WoodRegistryHelper.registerTypes(...)
RockRegistryHelper.registerTypes(...)
OreRegistryHelper.registerTypes(...)
SoilRegistryHelper.registerTypes(...)
SandRegistryHelper.registerTypes(...)
SoilVariantRegistryHelper.registerTypes(...)
Code examples:
// Metals
List<RegistryMetal> allMetals = MetalRegistryHelper.getAllMetalValues();
RegistryMetal brass = MetalRegistryHelper.getMetalValueOrDefault("brass");
// Woods
List<RegistryWood> allWoods = WoodRegistryHelper.getAllWoodValues();
RegistryWood ebony = WoodRegistryHelper.getWoodValueOrDefault("ebony");
// Rocks
List<RegistryRock> allRocks = RockRegistryHelper.getAllRockValues();
RegistryRock marble = RockRegistryHelper.getRockValueOrDefault("marble");
// Ores
List<RegistryOre> allOres = OreRegistryHelper.getAllOreValues();
RegistryOre sphalerite = OreRegistryHelper.getOreValueOrDefault("sphalerite");
// Soils
List<RegistrySoil> allSoils = SoilRegistryHelper.getAllSoilValues();
RegistrySoil duff = SoilRegistryHelper.getSoilValueOrDefault("duff");
// Sand colors
List<RegistrySand> allSands = SandRegistryHelper.getAllSandValues();
RegistrySand white = SandRegistryHelper.getSandValueOrDefault("white");
// Soil variants
List<RegistrySoilVariant> allVariants = SoilVariantRegistryHelper.getAllSoilVariantValues();
RegistrySoilVariant inceptisol = SoilVariantRegistryHelper.getSoilVariantValueOrDefault("inceptisol");
All get[Type]ValueOrDefault("name") methods are case-insensitive and return a safe fallback if not found.
For example, iterating over the List<RegistryWood> list, can yield a list of wood types like this, where this shows a scenario with ArborFirmaCraft installed:
acacia, ash, aspen, birch, blackwood, chestnut, douglas_fir, hickory, kapok, mangrove, maple, oak, palm, pine, rosewood, sequoia, spruce, sycamore, white_cedar, willow, araucaria, baobab, beech, cypress, eucalyptus, fig, ginkgo, hevea, ipe, ironwood, mahoe, mahogany, teak, tualang
You can easily register new blocks using the lists/getters provided by the helpers. Here is shown an example of how to add a new SoilBlock for all registered soil types and soil variants:
public static final Map<RegistrySoil, Map<RegistrySoilVariant, Id<Block>>> NEW_SOIL_BLOCKS =
SoilRegistryHelper.getAllSoilValues().stream()
.collect(Collectors.toMap(
type -> type,
type -> SoilVariantRegistryHelper.getAllSoilVariantValues().stream()
.collect(Collectors.toMap(
variant -> variant,
variant -> register(type.toString() + "/" + variant.toString(),
() -> new SoilBlock(Block.Properties.of().mapColor(MapColor.DIRT).strength(1.4f), type, variant))
))
));
For example: if a block/item/entity/whatever constructor insists on using e.g. SoilBlockType, such as ConnectedGrassBlock, you can safely cast your soil from the RegistrySoil interface to it like this (RegistrySoil)(Object)soil (or however else you prefer to do it), since I've made TFC's SoilBlockTypeenum class implement the custom RegistrySoil interface.
Ideal for addons, modpack makers, or any setting that needs to work with every TFC-compatible metal, wood, rock, ore, soil, sand, or variant regardless of which mods are installed.
For example, you can use the registry type lists created by this library, to easily create new blocks, items, entities etc. for all of or the desired entries of the specific type.
评论 0
登录后参与评分
还没有评论,来抢沙发吧