Merge remote-tracking branch 'origin/main' into 1.18

This commit is contained in:
embeddedt 2023-04-10 15:59:20 -04:00
commit 1163591f8f
2 changed files with 39 additions and 5 deletions

View File

@ -10,9 +10,10 @@ import net.minecraftforge.client.event.ScreenEvent;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.world.entity.Entity;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.client.event.*;
import net.minecraftforge.client.gui.ForgeIngameGui;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.TagsUpdatedEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.eventbus.api.EventPriority;
@ -38,6 +39,8 @@ public class ModernFixClient {
public static float gameStartTimeSeconds = -1;
private static boolean recipesUpdated, tagsUpdated = false;
private String brandingString = null;
public ModernFixClient() {
@ -57,6 +60,8 @@ public class ModernFixClient {
public void resetWorldLoadStateMachine() {
numRenderTicks = 0;
worldLoadStartTime = -1;
recipesUpdated = false;
tagsUpdated = false;
}
@SubscribeEvent(priority = EventPriority.LOWEST)
@ -69,9 +74,25 @@ public class ModernFixClient {
}
}
@SubscribeEvent(priority = EventPriority.LOW)
public void onRecipesUpdated(RecipesUpdatedEvent event) {
recipesUpdated = true;
}
@SubscribeEvent(priority = EventPriority.LOW)
public void onTagsUpdated(TagsUpdatedEvent event) {
tagsUpdated = true;
}
@SubscribeEvent
public void onRenderTickEnd(TickEvent.RenderTickEvent event) {
if(event.phase == TickEvent.Phase.END && !(Minecraft.getInstance().screen instanceof DeferredLevelLoadingScreen) && worldLoadStartTime != -1 && Minecraft.getInstance().player != null && numRenderTicks++ >= 10) {
if(event.phase == TickEvent.Phase.END
&& recipesUpdated
&& tagsUpdated
&& !(Minecraft.getInstance().screen instanceof DeferredLevelLoadingScreen)
&& worldLoadStartTime != -1
&& Minecraft.getInstance().player != null
&& numRenderTicks++ >= 10) {
float timeSpentLoading = ((float)(System.nanoTime() - worldLoadStartTime) / 1000000000f);
ModernFix.LOGGER.warn("Time from main menu to in-game was " + timeSpentLoading + " seconds");
ModernFix.LOGGER.warn("Total time to load game and open world was " + (timeSpentLoading + gameStartTimeSeconds) + " seconds");

View File

@ -91,6 +91,8 @@ public abstract class ModelBakeryMixin {
private Cache<Triple<ResourceLocation, Transformation, Boolean>, BakedModel> loadedBakedModels;
private Cache<ResourceLocation, UnbakedModel> loadedModels;
private HashMap<ResourceLocation, UnbakedModel> smallLoadingCache = new HashMap<>();
@Inject(method = "<init>(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/client/color/block/BlockColors;Z)V", at = @At("RETURN"))
private void replaceTopLevelBakedModels(ResourceManager manager, BlockColors colors, boolean vanillaBakery, CallbackInfo ci) {
@ -229,6 +231,11 @@ public abstract class ModelBakeryMixin {
return unbakedCache.get(rl);
}
@Inject(method = "cacheAndQueueDependencies", at = @At("RETURN"))
private void addToSmallLoadingCache(ResourceLocation location, UnbakedModel model, CallbackInfo ci) {
smallLoadingCache.put(location, model);
}
/**
* @author embeddedt
@ -257,21 +264,27 @@ public abstract class ModelBakeryMixin {
if(debugDynamicModelLoading)
LOGGER.info("Loading {}", resourcelocation);
this.loadModel(resourcelocation);
// TODO: in theory the cache can get evicted right here and we lose the model
// very unlikely to occur though
}
} catch (ModelBakery.BlockStateDefinitionException var9) {
LOGGER.warn(var9.getMessage());
this.unbakedCache.put(resourcelocation, iunbakedmodel);
smallLoadingCache.put(resourcelocation, iunbakedmodel);
} catch (Exception var10) {
LOGGER.warn("Unable to load model: '{}' referenced from: {}: {}", resourcelocation, modelLocation, var10);
this.unbakedCache.put(resourcelocation, iunbakedmodel);
smallLoadingCache.put(resourcelocation, iunbakedmodel);
} finally {
this.loadingStack.remove(resourcelocation);
}
}
return this.unbakedCache.getOrDefault(modelLocation, iunbakedmodel);
// We have to get the result from the temporary cache used for a model load
// As in pathological cases (e.g. Pedestals on 1.19) unbakedCache can lose
// the model immediately
UnbakedModel result = smallLoadingCache.getOrDefault(modelLocation, iunbakedmodel);
// We are done with loading, so clear this cache to allow GC of any unneeded models
smallLoadingCache.clear();
return result;
}
}
}