Flywheel/src/main/java/com/jozufozu/flywheel/backend/Loader.java

64 lines
2 KiB
Java
Raw Normal View History

package com.jozufozu.flywheel.backend;
import com.jozufozu.flywheel.backend.instancing.InstancedRenderDispatcher;
import com.jozufozu.flywheel.core.GameStateRegistry;
import com.jozufozu.flywheel.core.crumbling.CrumblingRenderer;
import com.jozufozu.flywheel.core.source.Resolver;
import com.jozufozu.flywheel.core.source.ShaderSources;
import com.jozufozu.flywheel.event.GatherContextEvent;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.server.packs.resources.ReloadableResourceManager;
import net.minecraft.server.packs.resources.ResourceManager;
2021-09-15 09:26:51 +02:00
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
import net.minecraftforge.fml.ModLoader;
2021-09-15 09:26:51 +02:00
/**
* The main entity for loading shaders.
*
* <p>
2021-09-15 09:26:51 +02:00
* This class is responsible for invoking the loading, parsing, and compilation stages.
* </p>
*/
2021-09-15 09:26:51 +02:00
public class Loader implements ResourceManagerReloadListener {
private boolean firstLoad = true;
Loader() {
// Can be null when running datagenerators due to the unfortunate time we call this
Minecraft minecraft = Minecraft.getInstance();
if (minecraft != null) {
ResourceManager manager = minecraft.getResourceManager();
if (manager instanceof ReloadableResourceManager) {
((ReloadableResourceManager) manager).registerReloadListener(this);
}
}
}
@Override
2021-09-15 09:26:51 +02:00
public void onResourceManagerReload(ResourceManager manager) {
Backend.refresh();
GameStateRegistry._clear();
Resolver.INSTANCE.invalidate();
ModLoader.get()
.postEvent(new GatherContextEvent(firstLoad));
ShaderSources sources = new ShaderSources(manager);
Resolver.INSTANCE.run(sources);
Backend.LOGGER.info("Loaded all shader sources.");
ClientLevel world = Minecraft.getInstance().level;
if (Backend.canUseInstancing(world)) {
// TODO: looks like it might be good to have another event here
InstancedRenderDispatcher.resetInstanceWorld(world);
CrumblingRenderer.reset();
}
2021-09-15 09:26:51 +02:00
firstLoad = false;
}
}