This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Construct Forge mods at the correct place * Remove the unused Fabric mod entry * Remove debug outputs & add comments * Fix the order of events on client * Fix crashing on dedicated server * Fix FMLServerStartingEvent to accommodate the new mod loading procedure * Fix a mixin applied on the wrong side
- Loading branch information
Showing
17 changed files
with
290 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
patchwork-dispatcher/src/main/java/net/patchworkmc/impl/PatchworkClientModLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Minecraft Forge, Patchwork Project | ||
* Copyright (c) 2016-2020, 2019-2020 | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation version 2.1 | ||
* of the License. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
package net.patchworkmc.impl; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.Executor; | ||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import net.minecraftforge.client.event.ModelRegistryEvent; | ||
import net.minecraftforge.common.MinecraftForge; | ||
import net.minecraftforge.eventbus.api.Event; | ||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; | ||
|
||
import net.minecraft.resource.ResourceManager; | ||
import net.minecraft.resource.ResourceReloadListener; | ||
import net.minecraft.util.profiler.Profiler; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.resource.ClientBuiltinResourcePackProvider; | ||
import net.minecraft.client.resource.ClientResourcePackProfile; | ||
import net.minecraft.resource.ReloadableResourceManager; | ||
import net.minecraft.resource.ResourcePackManager; | ||
|
||
public class PatchworkClientModLoader { | ||
private static final Logger LOGGER = LogManager.getLogger(PatchworkClientModLoader.class); | ||
private static boolean loading; | ||
private static MinecraftClient mc; | ||
|
||
public static void begin(final MinecraftClient minecraft, final ResourcePackManager<ClientResourcePackProfile> defaultResourcePacks, | ||
final ReloadableResourceManager mcResourceManager, ClientBuiltinResourcePackProvider metadataSerializer) { | ||
loading = true; | ||
PatchworkClientModLoader.mc = minecraft; | ||
Patchwork.gatherAndInitializeMods(); | ||
mcResourceManager.registerListener(PatchworkClientModLoader::onReload); | ||
} | ||
|
||
/** | ||
* @param syncExecutor The main thread executor | ||
*/ | ||
private static CompletableFuture<Void> onReload(final ResourceReloadListener.Synchronizer stage, final ResourceManager resourceManager, | ||
final Profiler prepareProfiler, final Profiler executeProfiler, final Executor asyncExecutor, final Executor syncExecutor) { | ||
return CompletableFuture.runAsync(() -> startModLoading(syncExecutor), asyncExecutor) | ||
.thenCompose(stage::whenPrepared) | ||
.thenRunAsync(() -> finishModLoading(syncExecutor), asyncExecutor); | ||
} | ||
|
||
private static void startModLoading(Executor mainThreadExecutor) { | ||
LOGGER.debug("Patchwork Client Mod Loader: Start mod loading."); | ||
mainThreadExecutor.execute(() -> Patchwork.loadMods(container -> new FMLClientSetupEvent(() -> PatchworkClientModLoader.mc, container), | ||
PatchworkClientModLoader::preSidedRunnable, PatchworkClientModLoader::postSidedRunnable)); | ||
} | ||
|
||
private static void preSidedRunnable(Consumer<Supplier<Event>> perModContainerEventProcessor) { | ||
perModContainerEventProcessor.accept(ModelRegistryEvent::new); | ||
} | ||
|
||
private static void postSidedRunnable(Consumer<Supplier<Event>> perModContainerEventProcessor) { | ||
} | ||
|
||
private static void finishModLoading(Executor executor) { | ||
LOGGER.debug("Patchwork Client Mod Loader: Finish mod loading."); | ||
Patchwork.finishMods(); | ||
loading = false; | ||
// reload game settings on main thread | ||
executor.execute(() -> mc.options.load()); | ||
} | ||
|
||
/** | ||
* @return true if an error occurred so that we can cancel the normal title screen. | ||
*/ | ||
public static boolean completeModLoading() { | ||
LOGGER.debug("Patchwork Client Mod Loader: Complete mod loading"); | ||
// Assume there's no error. | ||
MinecraftForge.EVENT_BUS.start(); | ||
return false; | ||
} | ||
|
||
// TODO: Reserved for future use | ||
public static void onResourceReloadComplete(boolean errorFree) { | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
patchwork-dispatcher/src/main/java/net/patchworkmc/mixin/MixinMinecraftClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Minecraft Forge, Patchwork Project | ||
* Copyright (c) 2016-2020, 2019-2020 | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation version 2.1 | ||
* of the License. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
package net.patchworkmc.mixin; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.At.Shift; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.resource.ReloadableResourceManager; | ||
|
||
import net.patchworkmc.impl.PatchworkClientModLoader; | ||
|
||
@Mixin(MinecraftClient.class) | ||
public abstract class MixinMinecraftClient { | ||
@Shadow | ||
private ReloadableResourceManager resourceManager; | ||
|
||
@Inject(method = "init", at = @At(value = "INVOKE", shift = Shift.BEFORE, ordinal = 0, target = "net/minecraft/resource/ResourcePackManager.scanPacks()V")) | ||
private void initForgeModsOnClient(CallbackInfo ci) { | ||
MinecraftClient me = (MinecraftClient) (Object) this; | ||
PatchworkClientModLoader.begin(me, me.getResourcePackManager(), resourceManager, me.getResourcePackDownloader()); | ||
} | ||
|
||
// this.setOverlay(new SplashScreen(this, this.resourceManager.beginInitialMonitoredReload(SystemUtil.getServerWorkerExecutor(), this, voidFuture), () -> { | ||
// if (SharedConstants.isDevelopment) this.checkGameData(); | ||
// + if (net.minecraftforge.fml.client.ClientModLoader.completeModLoading()) return; // Do not overwrite the error sceen | ||
// + // Show either ConnectScreen or TitleScreen | ||
// } | ||
@Inject(method = "method_18504", at = @At("RETURN")) | ||
private void onResourceReloadComplete(CallbackInfo ci) { | ||
PatchworkClientModLoader.onResourceReloadComplete(!PatchworkClientModLoader.completeModLoading()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.