Skip to content

Commit

Permalink
Update to simpler mod loading from latest FML (#774)
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n authored Apr 18, 2024
1 parent 21eb1e3 commit a70fa37
Show file tree
Hide file tree
Showing 45 changed files with 189 additions and 125 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ accesstransformers_version=10.0.1
coremods_version=6.0.4
eventbus_version=7.2.0
modlauncher_version=10.1.10
securejarhandler_version=2.1.24
securejarhandler_version=2.1.31
bootstraplauncher_version=1.1.2
asm_version=9.5
installer_version=2.1.+
Expand All @@ -31,7 +31,7 @@ jetbrains_annotations_version=24.0.1
slf4j_api_version=2.0.7
apache_maven_artifact_version=3.8.5
jarjar_version=0.4.0
fancy_mod_loader_version=3.0.10
fancy_mod_loader_version=3.0.14
mojang_logging_version=1.1.1
log4j_version=2.22.1
guava_version=31.1.2-jre
Expand Down
2 changes: 1 addition & 1 deletion patches/net/minecraft/client/Minecraft.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
this.gameRenderer = new GameRenderer(this, this.entityRenderDispatcher.getItemInHandRenderer(), this.resourceManager, this.renderBuffers);
this.resourceManager.registerReloadListener(this.gameRenderer.createReloadListener());
this.levelRenderer = new LevelRenderer(this, this.entityRenderDispatcher, this.blockEntityRenderDispatcher, this.renderBuffers);
+ net.neoforged.fml.ModLoader.get().postEvent(new net.neoforged.neoforge.client.event.RenderLevelStageEvent.RegisterStageEvent());
+ net.neoforged.fml.ModLoader.postEvent(new net.neoforged.neoforge.client.event.RenderLevelStageEvent.RegisterStageEvent());
this.resourceManager.registerReloadListener(this.levelRenderer);
- this.createSearchTrees();
+ // Forge: We delay this to allow registration of modded creative mode tabs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
+ @org.jetbrains.annotations.ApiStatus.Internal
+ public static void init() {
+ var event = new net.neoforged.neoforge.client.event.RegisterMenuScreensEvent(SCREENS);
+ net.neoforged.fml.ModLoader.get().postEvent(event);
+ net.neoforged.fml.ModLoader.postEvent(event);
}

public static boolean selfTest() {
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)
);
this.loadBlurEffect(p_250719_);
+ net.neoforged.fml.ModLoader.get().postEvent(new net.neoforged.neoforge.client.event.RegisterShadersEvent(p_250719_, list1));
+ net.neoforged.fml.ModLoader.postEvent(new net.neoforged.neoforge.client.event.RegisterShadersEvent(p_250719_, list1));
} catch (IOException ioexception) {
list1.forEach(p_172729_ -> p_172729_.getFirst().close());
throw new RuntimeException("could not reload shaders", ioexception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
put((Object2ObjectLinkedOpenHashMap<RenderType, BufferBuilder>)p_307112_, RenderType.waterMask());
ModelBakery.DESTROY_TYPES.forEach(p_173062_ -> put(p_307112_, p_173062_));
});
+ net.neoforged.fml.ModLoader.get().postEvent(new net.neoforged.neoforge.client.event.RegisterRenderBuffersEvent(sortedmap));
+ net.neoforged.fml.ModLoader.postEvent(new net.neoforged.neoforge.client.event.RegisterRenderBuffersEvent(sortedmap));
this.crumblingBufferSource = MultiBufferSource.immediate(new BufferBuilder(1536));
this.bufferSource = MultiBufferSource.immediateWithBuffers(sortedmap, new BufferBuilder(786432));
this.outlineBufferSource = new OutlineBufferSource(this.bufferSource);
2 changes: 1 addition & 1 deletion patches/net/minecraft/client/renderer/Sheets.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
+ }
+
+ static {
+ if (net.neoforged.fml.ModLoader.isLoadingStateValid() && !net.neoforged.fml.ModLoader.get().hasCompletedState("LOAD_REGISTRIES")) {
+ if (net.neoforged.fml.ModLoader.isLoadingStateValid() && !net.neoforged.neoforge.internal.CommonModLoader.areRegistriesLoaded()) {
+ com.mojang.logging.LogUtils.getLogger().error(
+ "net.minecraft.client.renderer.Sheets loaded too early, modded registry-based materials may not work correctly",
+ new IllegalStateException("net.minecraft.client.renderer.Sheets loaded too early")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
builder.put(SkullBlock.Types.CREEPER, new SkullModel(p_173662_.bakeLayer(ModelLayers.CREEPER_HEAD)));
builder.put(SkullBlock.Types.DRAGON, new DragonHeadModel(p_173662_.bakeLayer(ModelLayers.DRAGON_SKULL)));
builder.put(SkullBlock.Types.PIGLIN, new PiglinHeadModel(p_173662_.bakeLayer(ModelLayers.PIGLIN_HEAD)));
+ net.neoforged.fml.ModLoader.get().postEvent(new net.neoforged.neoforge.client.event.EntityRenderersEvent.CreateSkullModels(builder, p_173662_));
+ net.neoforged.fml.ModLoader.postEvent(new net.neoforged.neoforge.client.event.EntityRenderersEvent.CreateSkullModels(builder, p_173662_));
return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
);
this.renderers = EntityRenderers.createEntityRenderers(entityrendererprovider$context);
this.playerRenderers = EntityRenderers.createPlayerRenderers(entityrendererprovider$context);
+ net.neoforged.fml.ModLoader.get().postEvent(new net.neoforged.neoforge.client.event.EntityRenderersEvent.AddLayers(renderers, playerRenderers, entityrendererprovider$context));
+ net.neoforged.fml.ModLoader.postEvent(new net.neoforged.neoforge.client.event.EntityRenderersEvent.AddLayers(renderers, playerRenderers, entityrendererprovider$context));
}
}
4 changes: 2 additions & 2 deletions patches/net/minecraft/client/sounds/SoundEngine.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
this.soundManager = p_120236_;
this.options = p_120237_;
this.soundBuffers = new SoundBufferLibrary(p_249332_);
+ net.neoforged.fml.ModLoader.get().postEvent(new net.neoforged.neoforge.client.event.sound.SoundEngineLoadEvent(this));
+ net.neoforged.fml.ModLoader.postEvent(new net.neoforged.neoforge.client.event.sound.SoundEngineLoadEvent(this));
}

public void reload() {
@@ -96,6 +_,7 @@

this.destroy();
this.loadLibrary();
+ net.neoforged.fml.ModLoader.get().postEvent(new net.neoforged.neoforge.client.event.sound.SoundEngineLoadEvent(this));
+ net.neoforged.fml.ModLoader.postEvent(new net.neoforged.neoforge.client.event.sound.SoundEngineLoadEvent(this));
}

private synchronized void loadLibrary() {
Expand Down
2 changes: 1 addition & 1 deletion patches/net/minecraft/data/DataGenerator.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
LOGGER.debug("Generator {} already run for version {}", p_254418_, this.version.getName());
} else {
LOGGER.info("Starting provider: {}", p_254418_);
+ net.neoforged.fml.StartupMessageManager.addModMessage("Generating: " + p_254418_);
+ net.neoforged.fml.loading.progress.StartupNotificationManager.addModMessage("Generating: " + p_254418_);
stopwatch1.start();
hashcache.applyUpdate(hashcache.generateUpdate(p_254418_, p_253750_::run).join());
stopwatch1.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
this.server.getServerResourcePack().ifPresent(p_296496_ -> this.configurationTasks.add(new ServerResourcePackConfigurationTask(p_296496_)));
+
+ this.configurationTasks.add(new net.neoforged.neoforge.network.configuration.ModdedConfigurationPhaseStarted(this));
+ this.configurationTasks.addAll(net.neoforged.fml.ModLoader.get().postEventWithReturn(new net.neoforged.neoforge.network.event.OnGameConfigurationEvent(this)).getConfigurationTasks());
+ this.configurationTasks.addAll(net.neoforged.fml.ModLoader.postEventWithReturn(new net.neoforged.neoforge.network.event.OnGameConfigurationEvent(this)).getConfigurationTasks());
+ this.configurationTasks.add(new net.neoforged.neoforge.network.configuration.ModdedConfigurationPhaseCompleted(this));
+ }
+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
+ {
+ Map<EntityType<?>, net.neoforged.neoforge.event.entity.SpawnPlacementRegisterEvent.MergedSpawnPredicate<?>> map = Maps.newHashMap();
+ DATA_BY_TYPE.forEach((type, data) -> map.put(type, new net.neoforged.neoforge.event.entity.SpawnPlacementRegisterEvent.MergedSpawnPredicate<>(data.predicate, data.placement, data.heightMap)));
+ net.neoforged.fml.ModLoader.get().postEvent(new net.neoforged.neoforge.event.entity.SpawnPlacementRegisterEvent(map));
+ net.neoforged.fml.ModLoader.postEvent(new net.neoforged.neoforge.event.entity.SpawnPlacementRegisterEvent(map));
+ map.forEach(((entityType, merged) -> DATA_BY_TYPE.put(entityType, new SpawnPlacements.Data(merged.getHeightmapType(), merged.getSpawnType(), merged.build()))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void init() {
initialized = true;

var event = new RegisterCapabilitiesEvent();
ModLoader.get().postEventWrapContainerInModOrder(event);
ModLoader.postEventWrapContainerInModOrder(event);

initFinished = true;
}
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/net/neoforged/neoforge/client/ClientHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,15 @@ public static boolean renderSpecificFirstPersonArm(PoseStack poseStack, MultiBuf
}

public static void onTextureAtlasStitched(TextureAtlas atlas) {
ModLoader.get().postEvent(new TextureAtlasStitchedEvent(atlas));
ModLoader.postEvent(new TextureAtlasStitchedEvent(atlas));
}

public static void onBlockColorsInit(BlockColors blockColors) {
ModLoader.get().postEvent(new RegisterColorHandlersEvent.Block(blockColors));
ModLoader.postEvent(new RegisterColorHandlersEvent.Block(blockColors));
}

public static void onItemColorsInit(ItemColors itemColors, BlockColors blockColors) {
ModLoader.get().postEvent(new RegisterColorHandlersEvent.Item(itemColors, blockColors));
ModLoader.postEvent(new RegisterColorHandlersEvent.Item(itemColors, blockColors));
}

public static Model getArmorModel(LivingEntity entityLiving, ItemStack itemStack, EquipmentSlot slot, HumanoidModel<?> _default) {
Expand Down Expand Up @@ -440,11 +440,11 @@ public static void onModifyBakingResult(Map<ResourceLocation, BakedModel> models
LOGGER.warn("Failed to retrieve texture '{}' from atlas '{}'", material.texture(), material.atlasLocation(), new Throwable());
return stitchResult.missing();
};
ModLoader.get().postEvent(new ModelEvent.ModifyBakingResult(models, textureGetter, modelBakery));
ModLoader.postEvent(new ModelEvent.ModifyBakingResult(models, textureGetter, modelBakery));
}

public static void onModelBake(ModelManager modelManager, Map<ResourceLocation, BakedModel> models, ModelBakery modelBakery) {
ModLoader.get().postEvent(new ModelEvent.BakingCompleted(modelManager, Collections.unmodifiableMap(models), modelBakery));
ModLoader.postEvent(new ModelEvent.BakingCompleted(modelManager, Collections.unmodifiableMap(models), modelBakery));
}

public static BakedModel handleCameraTransforms(PoseStack poseStack, BakedModel model, ItemDisplayContext cameraTransformType, boolean applyLeftHandTransform) {
Expand Down Expand Up @@ -706,15 +706,15 @@ public static void firePlayerRespawn(MultiPlayerGameMode pc, LocalPlayer oldPlay
}

public static void onRegisterParticleProviders(ParticleEngine particleEngine) {
ModLoader.get().postEvent(new RegisterParticleProvidersEvent(particleEngine));
ModLoader.postEvent(new RegisterParticleProvidersEvent(particleEngine));
}

public static void onRegisterKeyMappings(Options options) {
ModLoader.get().postEvent(new RegisterKeyMappingsEvent(options));
ModLoader.postEvent(new RegisterKeyMappingsEvent(options));
}

public static void onRegisterAdditionalModels(Set<ResourceLocation> additionalModels) {
ModLoader.get().postEvent(new ModelEvent.RegisterAdditional(additionalModels));
ModLoader.postEvent(new ModelEvent.RegisterAdditional(additionalModels));
}

@Nullable
Expand Down Expand Up @@ -909,7 +909,7 @@ public static BiMap<ResourceLocation, SpriteSourceType> makeSpriteSourceTypesMap

@ApiStatus.Internal
public static void registerSpriteSourceTypes() {
ModLoader.get().postEvent(new RegisterSpriteSourceTypesEvent(SPRITE_SOURCE_TYPES_MAP));
ModLoader.postEvent(new RegisterSpriteSourceTypesEvent(SPRITE_SOURCE_TYPES_MAP));
}

@ApiStatus.Internal
Expand Down Expand Up @@ -992,9 +992,9 @@ public static void initClientHooks(Minecraft mc, ReloadableResourceManager resou
GameTestHooks.registerGametests();
registerSpriteSourceTypes();
MenuScreens.init();
ModLoader.get().postEvent(new RegisterClientReloadListenersEvent(resourceManager));
ModLoader.get().postEvent(new EntityRenderersEvent.RegisterLayerDefinitions());
ModLoader.get().postEvent(new EntityRenderersEvent.RegisterRenderers());
ModLoader.postEvent(new RegisterClientReloadListenersEvent(resourceManager));
ModLoader.postEvent(new EntityRenderersEvent.RegisterLayerDefinitions());
ModLoader.postEvent(new EntityRenderersEvent.RegisterRenderers());
ClientTooltipComponentManager.init();
EntitySpectatorShaderManager.init();
ClientHooks.onRegisterKeyMappings(mc.options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public final class ColorResolverManager {
@ApiStatus.Internal
public static void init() {
ImmutableList.Builder<ColorResolver> builder = ImmutableList.builder();
ModLoader.get().postEvent(new RegisterColorHandlersEvent.ColorResolvers(builder));
ModLoader.postEvent(new RegisterColorHandlersEvent.ColorResolvers(builder));
colorResolvers = builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void init() {
var effects = new HashMap<ResourceLocation, DimensionSpecialEffects>();
DEFAULT_EFFECTS = preRegisterVanillaEffects(effects);
var event = new RegisterDimensionSpecialEffectsEvent(effects);
ModLoader.get().postEventWrapContainerInModOrder(event);
ModLoader.postEventWrapContainerInModOrder(event);
EFFECTS = ImmutableMap.copyOf(effects);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static ResourceLocation get(EntityType<?> entityType) {
public static void init() {
var shaders = new HashMap<EntityType<?>, ResourceLocation>();
var event = new RegisterEntitySpectatorShadersEvent(shaders);
ModLoader.get().postEventWrapContainerInModOrder(event);
ModLoader.postEventWrapContainerInModOrder(event);
SHADERS = ImmutableMap.copyOf(shaders);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private ItemDecoratorHandler(List<IItemDecorator> itemDecorators) {
public static void init() {
var decorators = new HashMap<Item, List<IItemDecorator>>();
var event = new RegisterItemDecorationsEvent(decorators);
ModLoader.get().postEventWrapContainerInModOrder(event);
ModLoader.postEventWrapContainerInModOrder(event);
var builder = new ImmutableMap.Builder<Item, ItemDecoratorHandler>();
decorators.forEach((item, itemDecorators) -> builder.put(item, new ItemDecoratorHandler(itemDecorators)));
DECORATOR_LOOKUP = builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static void init() {
var renderTypes = new HashMap<ResourceLocation, RenderTypeGroup>();
preRegisterVanillaRenderTypes(renderTypes);
var event = new RegisterNamedRenderTypesEvent(renderTypes);
ModLoader.get().postEventWrapContainerInModOrder(event);
ModLoader.postEventWrapContainerInModOrder(event);
RENDER_TYPES = ImmutableMap.copyOf(renderTypes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void init() {

// Gather mods' entries
RegisterPresetEditorsEvent event = new RegisterPresetEditorsEvent(gatheredEditors);
ModLoader.get().postEventWrapContainerInModOrder(event);
ModLoader.postEventWrapContainerInModOrder(event);

editors = gatheredEditors;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static void init() {
var typeCategories = new HashMap<RecipeBookType, ImmutableList<RecipeBookCategories>>();
var recipeCategoryLookups = new HashMap<RecipeType<?>, Function<RecipeHolder<?>, RecipeBookCategories>>();
var event = new RegisterRecipeBookCategoriesEvent(aggregateCategories, typeCategories, recipeCategoryLookups);
ModLoader.get().postEventWrapContainerInModOrder(event);
ModLoader.postEventWrapContainerInModOrder(event);
AGGREGATE_CATEGORIES.putAll(aggregateCategories);
TYPE_CATEGORIES.putAll(typeCategories);
RECIPE_CATEGORY_LOOKUPS.putAll(recipeCategoryLookups);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static ClientTooltipComponent createClientTooltipComponent(TooltipCompone
public static void init() {
var factories = new HashMap<Class<? extends TooltipComponent>, Function<TooltipComponent, ClientTooltipComponent>>();
var event = new RegisterClientTooltipComponentFactoriesEvent(factories);
ModLoader.get().postEventWrapContainerInModOrder(event);
ModLoader.postEventWrapContainerInModOrder(event);
FACTORIES = ImmutableMap.copyOf(factories);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ public void initModdedLayers() {
throw new IllegalStateException("Duplicate initialization of NamedLayeredDraw");
}
initialized = true;
ModLoader.get().postEvent(new RegisterGuiLayersEvent(this.layers));
ModLoader.postEvent(new RegisterGuiLayersEvent(this.layers));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,21 @@
import net.neoforged.neoforge.common.I18nExtension;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable;

public class LoadingErrorScreen extends ErrorScreen {
private static final Logger LOGGER = LogManager.getLogger();
private final Path modsDir;
private final Path logFile;
private final List<ModLoadingException> modLoadErrors;
private final List<ModLoadingWarning> modLoadWarnings;
@Nullable
private final Path dumpedLocation;
private LoadingEntryList entryList;
private Component errorHeader;
private Component warningHeader;

public LoadingErrorScreen(LoadingFailedException loadingException, List<ModLoadingWarning> warnings, final File dumpedLocation) {
public LoadingErrorScreen(@Nullable LoadingFailedException loadingException, List<ModLoadingWarning> warnings, @Nullable File dumpedLocation) {
super(Component.literal("Loading Error"), null);
this.modLoadWarnings = warnings;
this.modLoadErrors = loadingException == null ? Collections.emptyList() : loadingException.getErrors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import net.minecraft.server.packs.repository.PackSource;
import net.minecraft.server.packs.resources.IoSupplier;
import net.minecraft.util.FormattedCharSequence;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModList;
import net.neoforged.fml.VersionChecker;
import net.neoforged.fml.loading.FMLPaths;
Expand Down Expand Up @@ -402,7 +401,7 @@ public void upload() {

lines.add(I18nExtension.getDisplayName(selectedMod));
lines.add(I18nExtension.parseMessage("fml.menu.mods.info.version", MavenVersionStringHelper.artifactVersionToString(selectedMod.getVersion())));
lines.add(I18nExtension.parseMessage("fml.menu.mods.info.idstate", selectedMod.getModId(), ModList.get().getModContainerById(selectedMod.getModId()).map(ModContainer::getCurrentState).map(Object::toString).orElse("NONE")));
lines.add(I18nExtension.parseMessage("fml.menu.mods.info.idstate", selectedMod.getModId(), "LOADED")); // TODO: remove mod loading stages from here too

selectedMod.getConfig().getConfigElement("credits").ifPresent(credits -> lines.add(I18nExtension.parseMessage("fml.menu.mods.info.credits", credits)));
selectedMod.getConfig().getConfigElement("authors").ifPresent(authors -> lines.add(I18nExtension.parseMessage("fml.menu.mods.info.authors", authors)));
Expand Down
Loading

0 comments on commit a70fa37

Please sign in to comment.