Skip to content

Commit

Permalink
Correct the loading of the block registries and the common registries
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim203 committed Oct 27, 2024
1 parent d6d19b0 commit 8f7a0d0
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
12 changes: 9 additions & 3 deletions core/src/main/java/org/geysermc/geyser/GeyserImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,15 @@ public void initialize() {
}
logger.info("******************************************");

/* Initialize registries */
Registries.init();
BlockRegistries.init();
/*
First load the registries and then populate them.
Both the block registries and the common registries depend on each other,
so maintaining this order is crucial for Geyser to load.
*/
BlockRegistries.load();
Registries.load();
BlockRegistries.populate();
Registries.populate();

RegistryCache.init();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class BlockRegistries {
/**
* A mapped registry containing which holds block IDs to its {@link BlockCollision}.
*/
public static final ListRegistry<BlockCollision> COLLISIONS;
public static final ListRegistry<BlockCollision> COLLISIONS = ListRegistry.create(Pair.of("org.geysermc.geyser.translator.collision.CollisionRemapper", "mappings/collisions.nbt"), CollisionRegistryLoader::new);

/**
* A registry which stores Java IDs to {@link Block}, containing miscellaneous information about
Expand Down Expand Up @@ -130,22 +130,36 @@ public class BlockRegistries {
*/
public static final SimpleMappedRegistry<String, CustomSkull> CUSTOM_SKULLS = SimpleMappedRegistry.create(RegistryLoaders.empty(Object2ObjectOpenHashMap::new));

static {
public static void load() {
BLOCKS.load();
BLOCK_STATES.load();
// collisions are loaded later, because they are initialized later
JAVA_BLOCKS.load();
JAVA_IDENTIFIER_TO_ID.load();
WATERLOGGED.load();
INTERACTIVE.load();
INTERACTIVE_MAY_BUILD.load();
CUSTOM_BLOCKS.load();
CUSTOM_BLOCK_STATE_OVERRIDES.load();
NON_VANILLA_BLOCK_STATE_OVERRIDES.load();
CUSTOM_BLOCK_ITEM_OVERRIDES.load();
EXTENDED_COLLISION_BOXES.load();
CUSTOM_SKULLS.load();

COLLISIONS.load();
}

public static void populate() {
Blocks.VAULT.javaId(); // FIXME
CustomSkullRegistryPopulator.populate();
BlockRegistryPopulator.populate(BlockRegistryPopulator.Stage.PRE_INIT);
CustomBlockRegistryPopulator.populate(CustomBlockRegistryPopulator.Stage.DEFINITION);
CustomBlockRegistryPopulator.populate(CustomBlockRegistryPopulator.Stage.NON_VANILLA_REGISTRATION);
BlockRegistryPopulator.populate(BlockRegistryPopulator.Stage.INIT_JAVA);
COLLISIONS = ListRegistry.create(Pair.of("org.geysermc.geyser.translator.collision.CollisionRemapper", "mappings/collisions.nbt"), CollisionRegistryLoader::new);
CustomBlockRegistryPopulator.populate(CustomBlockRegistryPopulator.Stage.VANILLA_REGISTRATION);
CustomBlockRegistryPopulator.populate(CustomBlockRegistryPopulator.Stage.CUSTOM_REGISTRATION);
BlockRegistryPopulator.populate(BlockRegistryPopulator.Stage.INIT_BEDROCK);
BlockRegistryPopulator.populate(BlockRegistryPopulator.Stage.POST_INIT);
}

public static void init() {
// no-op
}

}
}
10 changes: 6 additions & 4 deletions core/src/main/java/org/geysermc/geyser/registry/Registries.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
* Holds all the common registries in Geyser.
*/
public final class Registries {
private static boolean initialized = false;
private static boolean loaded = false;

/**
* A registry holding all the providers.
Expand Down Expand Up @@ -167,9 +167,9 @@ public final class Registries {
*/
public static final SimpleMappedRegistry<SoundTranslator, SoundInteractionTranslator<?>> SOUND_TRANSLATORS = SimpleMappedRegistry.create("org.geysermc.geyser.translator.sound.SoundTranslator", SoundTranslatorRegistryLoader::new);

public static void init() {
if (initialized) return;
initialized = true;
public static void load() {
if (loaded) return;
loaded = true;

PROVIDERS.load();
BEDROCK_ENTITY_IDENTIFIERS.load();
Expand All @@ -191,7 +191,9 @@ public static void init() {
SOUNDS.load();
SOUND_LEVEL_EVENTS.load();
SOUND_TRANSLATORS.load();
}

public static void populate() {
PacketRegistryPopulator.populate();
ItemRegistryPopulator.populate();

Expand Down

0 comments on commit 8f7a0d0

Please sign in to comment.