Skip to content

Commit

Permalink
fix: more registry issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bconlon1 committed Jul 28, 2023
1 parent 8348d60 commit 8987af4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
10 changes: 8 additions & 2 deletions src/main/java/com/aetherteam/cumulus/Cumulus.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,30 @@
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.RegistryBuilder;
import org.slf4j.Logger;

import java.util.Map;
import java.util.function.Supplier;

@Mod(Cumulus.MODID)
public class Cumulus {
public static final String MODID = "cumulus_menus";
public static final Logger LOGGER = LogUtils.getLogger();

public static final ResourceKey<Registry<Menu>> MENU_REGISTRY_KEY = ResourceKey.createRegistryKey(new ResourceLocation(Cumulus.MODID, "menu"));
public static final DeferredRegister<Menu> DEFERRED_MENUS = DeferredRegister.create(Cumulus.MENU_REGISTRY_KEY, Cumulus.MENU_REGISTRY_KEY.location().getNamespace());
public static final Supplier<IForgeRegistry<Menu>> MENU_REGISTRY = DEFERRED_MENUS.makeRegistry(RegistryBuilder::new);

public Cumulus() {
DistExecutor.unsafeRunForDist(() -> () -> {
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
modEventBus.addListener(this::dataSetup);

DeferredRegister<?>[] registers = {
Menus.MENUS
Menus.MENUS,
Cumulus.DEFERRED_MENUS
};

for (DeferredRegister<?> register : registers) {
Expand All @@ -50,7 +56,7 @@ public Cumulus() {

return true;
}, () -> () -> {
LOGGER.info("Disabling Cumulus as it is on server.");
Cumulus.LOGGER.info("Disabling Cumulus as it is on server.");

return false;
});
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/aetherteam/cumulus/api/Menu.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.aetherteam.cumulus.api;

import com.aetherteam.cumulus.Cumulus;
import com.aetherteam.cumulus.mixin.mixins.client.accessor.CreateWorldScreenAccessor;
import com.aetherteam.cumulus.mixin.mixins.client.accessor.GuiComponentAccessor;
import com.aetherteam.cumulus.mixin.mixins.client.accessor.RealmsPlayerScreenAccessor;
Expand Down Expand Up @@ -94,7 +95,7 @@ public Background getBackground() {
* @return The {@link ResourceLocation} of the {@link Menu}'s full registry ID.
*/
public ResourceLocation getId() {
return Menus.MENU_REGISTRY.get().getKey(this);
return Cumulus.MENU_REGISTRY.get().getKey(this);
}

/**
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/aetherteam/cumulus/api/Menus.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.RegistryBuilder;
import net.minecraftforge.registries.RegistryObject;

import java.util.List;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;
import java.util.stream.Collectors;

public class Menus {
public static final DeferredRegister<Menu> MENUS = DeferredRegister.create(Cumulus.MENU_REGISTRY_KEY, Cumulus.MODID);
public static final Supplier<IForgeRegistry<Menu>> MENU_REGISTRY = MENUS.makeRegistry(RegistryBuilder::new);

public static final ResourceLocation MINECRAFT_ICON = new ResourceLocation("textures/block/grass_block_side.png");
public static final Component MINECRAFT_NAME = Component.translatable("cumulus_menus.menu_title.minecraft");
Expand All @@ -26,14 +22,14 @@ public class Menus {
public static final RegistryObject<Menu> MINECRAFT = MENUS.register("minecraft", () -> new Menu(MINECRAFT_ICON, MINECRAFT_NAME, new TitleScreen(true), MINECRAFT_CONDITION));

public static Menu get(String id) {
return MENU_REGISTRY.get().getValue(new ResourceLocation(id));
return Cumulus.MENU_REGISTRY.get().getValue(new ResourceLocation(id));
}

/**
* @return A {@link List} of all registered {@link Menu}s.
*/
public static List<Menu> getMenus() {
return MENU_REGISTRY.get().getValues().stream().toList();
return Cumulus.MENU_REGISTRY.get().getValues().stream().toList();
}

/**
Expand Down

0 comments on commit 8987af4

Please sign in to comment.