
TFC注册表API
动态发现并统一访问所有模组添加的TFC注册表类型(金属、木材、矿石、岩石、土壤、沙子、土壤变体),来自任何使用注册表接口的模组。
TFC Registry API
一个轻量级的库模组,能够自动发现并统一所有由任何模组添加的 TerraFirmaCraft 注册表类型。它适用于任何附属模组,只要它们正确实现了本库的注册表接口或 TFC 自身的接口:
RegistryMetalRegistryRockRegistrySoilVariantRegistryWood
以下接口由本库提供:
RegistryOreRegistrySandRegistrySoil
发现机制如何工作
模组会在以下条件下自动找到所有类型 如果:
- 该类型实现了正确的
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(...)
代码示例:
// 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");
所有 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,你可以安全地将你的 soil 从 RegistrySoil 接口强制转换到它,像这样 (RegistrySoil)(Object)soil(或者你喜欢的任何其他方式),因为我已经让 TFC 的 SoilBlockType 枚举类实现了自定义的 RegistrySoil 接口。
非常适合附属模组、整合包作者,或任何需要与所有 TFC 兼容的金属、木材、岩石、矿石、土壤、沙子或变种一起工作的场景,无论安装了哪些模组。
例如,你可以使用本库创建的注册表类型列表,轻松地为特定类型的所有条目或所需条目创建新的方块、物品、实体等。
正在加载版本记录…
正在加载评论…
评论在新手盒子客户端中发表,这里同步展示。