Jump to content

Recommended Posts

Posted (edited)

Hello - I'm having some issues with retrieving and operating on data in a Stream of biome tags and not sure if my issue is with my dated knowledge of Java or my usage of Forge code - so I would appreciate some help.

I'm running this method - the stuff inside doesn't really matter here, because nothing inside this method is ever run. I've added print statements to debug and they are never executed. .getTagNames() should return a stream of biome keys which are then operated on.


			AmbienceMod.biomekeys.getTagNames().forEach(t -> {
				if (world.getBiomeManager().getBiome(pos).is(t)) {
				if (primaryTagMap.containsKey(t.location()) ) {
					biomereturn = t.location();
					secondaryreturn = false;
				}
				if (secondaryTagMap.containsKey(t.location()) ) {
					biomereturn = t.location();
					secondaryreturn = true;
				}
				}});
			}

And this is my definition of "biomekeys":


	static @Nullable ITagManager<Biome> biomekeys;
      
     <irrelevant code here>
      
      

		biomekeys = ForgeRegistries.BIOMES.tags();

This could be something really trivial I've missed but it's had me scratching my head for a while now.

Edited by SpectralGerbil
Posted

I already showed you how to get the biomes loaded from datapacks by using the server's RegistryAccess.

Look at this code:

@EventBusSubscriber(modid = MODID)
public class Test {

    @SubscribeEvent
    public static void listBiomes(ServerStartingEvent event) {
        var biomes = event.getServer().registryAccess().registryOrThrow(Registries.BIOME);
        LOG.info("Datapack: " + biomes.stream().toList().size());
        LOG.info("Forge: " + ForgeRegistries.BIOMES.getValues().size());
    }
}

Which when run against 1.19.4 produces:

Datapack: 63
Forge: 0

I don't know why that Forge Biome registry still exists? All the other dynamic registries were removed when Mojang changed how datapack registries work in 1.19.3

https://gist.github.com/ChampionAsh5357/c21724bafbc630da2ed8899fe0c1d226#registries

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted

Ok, so to elaborate - I'm currently on 1.19.2, not 1.19.4 - so "Registries" doesn't exist - going backwards off the link you sent, it seems BuiltInRegistries should work, but that doesn't work with RegistryorThrow or any similar methods I'm aware of within registry access. That's also why the old Forge registry still existed. Any idea how to do this for 1.19.2?

Posted (edited)

All the ResourceKeys where defined in the Registry inteface class before Mojang's refactoring.

I think it was Registry.BIOME_REGISTRY

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted

So something like this should work for getting the biome tags, saving them, and then checking them against a biome and map?
 

//In main class:
//(Just to be sure, does ServerStartingEvent fire on the client or do I need something else? - this mod is client only)
static List<TagKey<Biome>> biomes = null;
static Registry<Biome> biomeregistry = null;

	@SubscribeEvent
	public static void listBiomes(ServerStartingEvent event) {
		biomeregistry = event.getServer().registryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
		biomes = biomeregistry.getTagNames().toList();
	}

//And then retrieve in another class:

                Main.biomes.forEach(t -> {
				if (world.getBiomeManager().getBiome(pos).is(t)) {
				if (primaryTagMap.containsKey(t.location()) ) {
					biomereturn = t.location();
					secondaryreturn = false;
				}
				if (secondaryTagMap.containsKey(t.location()) ) {
					biomereturn = t.location();
					secondaryreturn = true;
				}
				}});

 

Posted

  Got it working - thanks for the brilliant help!! Will post here how I did it in case others need the same information:

//In main class:

	static List<TagKey<Biome>> biomes = null;
	static Registry<Biome> biomeregistry = null;
      
	@SubscribeEvent
	public void listBiomes(TagsUpdatedEvent event) {
		biomeregistry = event.getRegistryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
		biomes = biomeregistry.getTagNames().toList();
	}

//In retrieving class:
      
			if (Main.biomes != null) {
			Main.biomes.forEach(t -> {
				if (world.getBiomeManager().getBiome(pos).is(t)) {
				if (primaryTagMap.containsKey(t.location()) ) {
					biomereturn = t.location();
					secondaryreturn = false;
				}
				if (secondaryTagMap.containsKey(t.location()) ) {
					biomereturn = t.location();
					secondaryreturn = true;
				}
				}});
			}
Posted

You shouldn't be caching the registry like that. You should just retrieve the data when you need it.

At best you will have the wrong registry if somebody reloads the datapacks.

At worst you will cause memory leaks or weird bugs.

Caching data in static fields is a major cause of memory leaks in java and/or data leaking into contexts where it is not valid.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.