Update mappings, move mod initialization to the async loader.

Signed-off-by: cpw <[email protected]>
This commit is contained in:
cpw committed 2019-06-21 22:42:16 -04:00
1 parent a14c2233e0
commit c10174d50d
35 files changed
+166 -214

No files matched your search

@@ -23,26 +23,14 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Predicate;
import java.util.stream.IntStream;
import net.minecraft.resources.IResourceManager;
import net.minecraftforge.resource.IResourceType;
import net.minecraftforge.resource.VanillaResourceType;
import net.minecraft.resources.IResourceManagerReloadListener;
import net.minecraftforge.versions.forge.ForgeVersion;
import net.minecraftforge.versions.mcp.MCPVersion;
import net.minecraft.resources.IResourceManager;
import net.minecraftforge.resource.IResourceType;
import net.minecraftforge.resource.VanillaResourceType;
import net.minecraftforge.versions.forge.ForgeVersion;
import net.minecraftforge.versions.mcp.MCPVersion;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Predicate;
import java.util.stream.IntStream;
public class BrandingControl
{
private static List<String> brandings;
@@ -86,10 +74,12 @@ public class BrandingControl
return "forge";
}
public static void clearCaches(IResourceManager resourceManager, Predicate<IResourceType> resourcePredicate) {
if (resourcePredicate.test(VanillaResourceType.LANGUAGES)) {
brandings = null;
brandingsNoMC = null;
}
public static IResourceManagerReloadListener resourceManagerReloadListener() {
return BrandingControl::onResourceManagerReload;
}
private static void onResourceManagerReload(IResourceManager resourceManager) {
brandings = null;
brandingsNoMC = null;
}
}
@@ -124,7 +124,6 @@ public class ModLoader
}
public void loadMods() {
gatherAndInitializeMods();
DistExecutor.runWhenOn(Dist.CLIENT, ()->()-> ConfigTracker.INSTANCE.loadConfigs(ModConfig.Type.CLIENT, FMLPaths.CONFIGDIR.get()));
ConfigTracker.INSTANCE.loadConfigs(ModConfig.Type.COMMON, FMLPaths.CONFIGDIR.get());
dispatchAndHandleError(LifecycleEventProvider.SETUP);
@@ -132,7 +131,7 @@ public class ModLoader
dispatchAndHandleError(LifecycleEventProvider.SIDED_SETUP);
}
private void gatherAndInitializeMods() {
public void gatherAndInitializeMods() {
final ModList modList = ModList.of(loadingModList.getModFiles().stream().map(ModFileInfo::getFile).collect(Collectors.toList()), loadingModList.getMods());
if (!this.loadingExceptions.isEmpty()) {
throw new LoadingFailedException(loadingExceptions);
@@ -226,7 +226,7 @@ public class StartupQuery {
}
if (query.isSynchronous()) {
while (client.field_71462_r instanceof GuiNotification) {
while (client.currentScreen instanceof GuiNotification) {
if (Thread.interrupted()) {
query.exception = new InterruptedException();
throw new RuntimeException();
@@ -22,18 +22,14 @@ package net.minecraftforge.fml.client;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.DownloadingPackFinder;
import net.minecraft.client.resources.ClientResourcePackInfo;
import net.minecraft.resources.IReloadableResourceManager;
import net.minecraft.resources.ResourcePackList;
import net.minecraft.profiler.IProfiler;
import net.minecraft.resources.*;
import net.minecraft.util.Unit;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.common.ForgeConfig;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.LoadingFailedException;
import net.minecraftforge.fml.LogicalSidedProvider;
import net.minecraftforge.fml.ModLoader;
import net.minecraftforge.fml.ModLoadingWarning;
import net.minecraftforge.fml.SidedProvider;
import net.minecraftforge.fml.VersionChecker;
import net.minecraftforge.fml.*;
import net.minecraftforge.fml.client.gui.LoadingErrorScreen;
import net.minecraftforge.fml.packs.ResourcePackLoader;
import org.apache.logging.log4j.LogManager;
@@ -43,6 +39,8 @@ import com.mojang.blaze3d.platform.GlStateManager;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import static net.minecraftforge.fml.loading.LogMarkers.LOADING;
@@ -61,15 +59,31 @@ public class ClientModLoader
SidedProvider.setClient(()->minecraft);
LogicalSidedProvider.setClient(()->minecraft);
try {
ModLoader.get().loadMods();
ModLoader.get().gatherAndInitializeMods();
} catch (LoadingFailedException e) {
MinecraftForge.EVENT_BUS.shutdown();
error = e;
TEMP_printLoadingExceptions(e);
}
ResourcePackLoader.loadResourcePacks(defaultResourcePacks);
mcResourceManager.addReloadListener(ClientModLoader::onreload);
mcResourceManager.addReloadListener(BrandingControl.resourceManagerReloadListener());
}
private static CompletableFuture<Void> onreload(final IFutureReloadListener.IStage stage, final IResourceManager resourceManager, final IProfiler prepareProfiler, final IProfiler executeProfiler, final Executor asyncExecutor, final Executor syncExecutor) {
return CompletableFuture.runAsync(runTaskWithCatch(ModLoader.get()::loadMods), syncExecutor).thenCompose(stage::markCompleteAwaitingOthers).thenRunAsync(runTaskWithCatch(ModLoader.get()::finishMods));
}
private static Runnable runTaskWithCatch(Runnable r) {
return ()-> {
try {
r.run();
} catch (LoadingFailedException e) {
MinecraftForge.EVENT_BUS.shutdown();
error = e;
}
};
}
public static void end()
{
try {
@@ -34,14 +34,14 @@ public class GuiConfirmation extends GuiNotification
{
this.addButton(new Button(this.width / 2 - 104, this.height - 38, 100, 20, ForgeI18n.parseMessage("gui.yes"), b ->
{
GuiConfirmation.this.minecraft.field_71462_r = null;
GuiConfirmation.this.minecraft.currentScreen = null;
query.setResult(true);
query.finish();
}
));
this.addButton(new Button(this.width / 2 + 4, this.height - 38, 100, 20, ForgeI18n.parseMessage("gui.no"), b ->
{
GuiConfirmation.this.minecraft.field_71462_r = null;
GuiConfirmation.this.minecraft.currentScreen = null;
query.setResult(false);
query.finish();
}
@@ -68,7 +68,7 @@ public class FMLPlayMessages
SpawnEntity(Entity e)
{
this.entity = e;
this.typeId = Registry.field_212629_r.getId(e.getType());
this.typeId = Registry.ENTITY_TYPE.getId(e.getType());
this.entityId = e.getEntityId();
this.uuid = e.getUniqueID();
this.posX = e.posX;
@@ -143,7 +143,7 @@ public class FMLPlayMessages
public static void handle(SpawnEntity msg, Supplier<NetworkEvent.Context> ctx)
{
ctx.get().enqueueWork(() -> {
EntityType<?> type = Registry.field_212629_r.getByValue(msg.typeId);
EntityType<?> type = Registry.ENTITY_TYPE.getByValue(msg.typeId);
if (type == null)
{
throw new RuntimeException(String.format("Could not spawn entity (id %d) with unknown type at (%f, %f, %f)", msg.entityId, msg.posX, msg.posY, msg.posZ));
@@ -163,7 +163,7 @@ public class FMLPlayMessages
e.setEntityId(msg.entityId);
e.setUniqueId(msg.uuid);
world.filter(ClientWorld.class::isInstance).ifPresent(w->((ClientWorld)w).func_217411_a(msg.entityId, e));
world.filter(ClientWorld.class::isInstance).ifPresent(w->((ClientWorld)w).addEntity(msg.entityId, e));
e.setVelocity(msg.velX / 8000.0, msg.velY / 8000.0, msg.velZ / 8000.0);
if (e instanceof IEntityAdditionalSpawnData)
{
@@ -183,7 +183,7 @@ public class FMLPlayMessages
OpenContainer(ContainerType<?> id, int windowId, ITextComponent name, PacketBuffer additionalData)
{
this(Registry.field_218366_G.getId(id), windowId, name, additionalData);
this(Registry.MENU.getId(id), windowId, name, additionalData);
}
private OpenContainer(int id, int windowId, ITextComponent name, PacketBuffer additionalData)
@@ -223,7 +223,7 @@ public class FMLPlayMessages
}
public final ContainerType<?> getType() {
return Registry.field_218366_G.getByValue(this.id);
return Registry.MENU.getByValue(this.id);
}
public int getWindowId() {
@@ -180,7 +180,7 @@ public class NetworkEvent extends Event
// Must check ourselves as Minecraft will sometimes delay tasks even when they are received on the client thread
// Same logic as ThreadTaskExecutor#runImmediately without the join
if (!executor.isOnExecutionThread()) {
return executor.func_213165_a(runnable); // Use the internal method so thread check isn't done twice
return executor.deferTask(runnable); // Use the internal method so thread check isn't done twice
} else {
runnable.run();
return CompletableFuture.completedFuture(null);
@@ -197,7 +197,7 @@ public class NetworkEvent extends Event
if (netHandler instanceof ServerPlayNetHandler)
{
ServerPlayNetHandler netHandlerPlayServer = (ServerPlayNetHandler) netHandler;
return netHandlerPlayServer.field_147369_b;
return netHandlerPlayServer.player;
}
return null;
}
@@ -237,21 +237,21 @@ public class PacketDistributor<T> {
private Consumer<IPacket<?>> trackingEntity(final Supplier<Entity> entitySupplier) {
return p-> {
final Entity entity = entitySupplier.get();
((ServerChunkProvider)entity.getEntityWorld().getChunkProvider()).func_217218_b(entity, p);
((ServerChunkProvider)entity.getEntityWorld().getChunkProvider()).sendToAllTracking(entity, p);
};
}
private Consumer<IPacket<?>> trackingEntityAndSelf(final Supplier<Entity> entitySupplier) {
return p-> {
final Entity entity = entitySupplier.get();
((ServerChunkProvider)entity.getEntityWorld().getChunkProvider()).func_217216_a(entity, p);
((ServerChunkProvider)entity.getEntityWorld().getChunkProvider()).sendToTrackingAndSelf(entity, p);
};
}
private Consumer<IPacket<?>> trackingChunk(final Supplier<Chunk> chunkPosSupplier) {
return p -> {
final Chunk chunk = chunkPosSupplier.get();
((ServerChunkProvider)chunk.getWorld().getChunkProvider()).field_217237_a.func_219097_a(chunk.getPos(), false).forEach(e -> e.connection.sendPacket(p));
((ServerChunkProvider)chunk.getWorld().getChunkProvider()).chunkManager.getTrackingPlayers(chunk.getPos(), false).forEach(e -> e.connection.sendPacket(p));
};
}