I'm fiddling with a fork of Create Ore Excavation to tailor it to my tastes, and I've hit an issue. The idea is to separate ore veins from the recipes, to allow for more depth. To this end, I've added a new data-driven registry to store the vein types, which are then used to populate a chunk capability for later use.
When the server starts up, however, the data pack entries are loaded and the registry entry constructor called, but no entries seem to actually be added to the registry. There are no errors in the log, and from debugging it looks like the entries should be being added. Despite that, when I check the size and content of the registry with a debug item, it's empty.
I'm not sure if I horribly misunderstood the way these are set up, or if I'm just missing something; any help would be greatly appreciated.
The code in my main class (irrelevant lines omitted):
//<...>
public static final DeferredRegister<VeinType> VEINS_REGISTRY = DeferredRegister.create(new ResourceLocation(MODID, "vein_types"), MODID);
public static final Supplier<IForgeRegistry<VeinType>> VEINS = VEINS_REGISTRY.makeRegistry(VeinType.class, ()->{
LOGGER.info("Building ore vein registry...");
return new RegistryBuilder<VeinType>()
.onAdd((owner, stage, id, obj, oldObj)->LOGGER.debug("Registered ore vein: " + obj.getRegistryName())) //This is never hit
.dataPackRegistry(VeinType.VeinCodex,VeinType.VeinCodex);
});
public CreateOreExcavation() {
//<...>
MinecraftForge.EVENT_BUS.register(this);
VEINS_REGISTRY.register(FMLJavaModLoadingContext.get().getModEventBus());
}
public static IForgeRegistry<VeinType> getVeinRegistry(){return VEINS.get();}
//<...>
The registry entity class, VeinType:
public class VeinType extends ForgeRegistryEntry<VeinType> {
int weight;
public TagKey<Biome> biomeAllowlist, biomeDenylist;
public VeinType(int weight, Optional<TagKey<Biome>> allowlist, Optional<TagKey<Biome>> denylist){
this.weight = weight;
this.biomeAllowlist=allowlist.orElse(null);
this.biomeDenylist =denylist.orElse(null);
CreateOreExcavation.LOGGER.info("VeinType constructor was called with weight " + weight); // This triggers
}
public int getWeight(){return weight;}
public Optional<TagKey<Biome>> getAllowList(){return Optional.ofNullable(biomeAllowlist);}
public Optional<TagKey<Biome>> getDenyList(){return Optional.ofNullable(biomeDenylist);}
public boolean canGenerate(ServerLevel lvl, Holder<Biome> b) {
if(biomeDenylist != null && isInTag(biomeDenylist, lvl, b))return false;
return biomeAllowlist == null || isInTag(biomeAllowlist, lvl, b);
}
private static boolean isInTag(TagKey<Biome> tag, ServerLevel lvl, Holder<Biome> b) {
return lvl.getServer().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getTag(tag).map(t -> t.contains(b)).orElse(false);
}
public static final Codec<VeinType> VeinCodex = RecordCodecBuilder.create(instance -> instance.group(
Codec.INT.fieldOf("weight").forGetter(VeinType::getWeight),
TagKey.codec(Registry.BIOME_REGISTRY).optionalFieldOf("biome_allowlist").forGetter(VeinType::getAllowList),
TagKey.codec(Registry.BIOME_REGISTRY).optionalFieldOf("biome_denylist") .forGetter(VeinType::getDenyList)
).apply(instance, VeinType::new));
}