Skip to content

Commit

Permalink
Fully support shader dimension overrides (Fixes IrisShaders#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
coderbot16 committed Mar 6, 2021
1 parent 5ba442a commit 5592607
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
34 changes: 31 additions & 3 deletions src/main/java/net/coderbot/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
import com.mojang.blaze3d.platform.GlStateManager;
import net.coderbot.iris.config.IrisConfig;
import net.coderbot.iris.pipeline.ShaderPipeline;
import net.coderbot.iris.postprocess.CompositeRenderer;
import net.coderbot.iris.rendertarget.RenderTargets;
import net.coderbot.iris.shaderpack.DimensionId;
import net.coderbot.iris.shaderpack.ShaderPack;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.dimension.DimensionType;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -255,9 +258,34 @@ private static void destroyEverything() {
}
}

private static DimensionId lastDimension = DimensionId.OVERWORLD;

public static ShaderPipeline getPipeline() {
ClientWorld world = MinecraftClient.getInstance().world;

if (world != null) {
DimensionId currentDimension = DimensionId.OVERWORLD;

DimensionType current = world.getDimension();
Registry<DimensionType> dimensionTypes = world.getRegistryManager().getDimensionTypes();
RegistryKey<DimensionType> id = dimensionTypes.getKey(current).orElseThrow(RuntimeException::new);

if (id.equals(DimensionType.THE_END_REGISTRY_KEY)) {
currentDimension = DimensionId.END;
} else if (id.equals(DimensionType.THE_NETHER_REGISTRY_KEY)) {
currentDimension = DimensionId.NETHER;
}

if (currentDimension != lastDimension) {
Iris.logger.info("Reloading shaderpack on dimension change (" + lastDimension + " -> " + currentDimension + ")");

lastDimension = currentDimension;
pipeline = null;
}
}

if (pipeline == null) {
pipeline = new ShaderPipeline(Objects.requireNonNull(currentPack).getProgramSet());
pipeline = new ShaderPipeline(Objects.requireNonNull(currentPack).getProgramSet(lastDimension));
}

return pipeline;
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/net/coderbot/iris/shaderpack/ShaderPack.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,24 @@ private static Optional<Properties> loadProperties(Path shaderPath, String name)
return Optional.of(properties);
}

public ProgramSet getProgramSet() {
return ProgramSet.merged(base, nether);
public ProgramSet getProgramSet(DimensionId dimension) {
ProgramSet overrides;

switch (dimension) {
case OVERWORLD:
overrides = overworld;
break;
case NETHER:
overrides = nether;
break;
case END:
overrides = end;
break;
default:
throw new IllegalArgumentException("Unknown dimension " + dimension);
}

return ProgramSet.merged(base, overrides);
}

public IdMap getIdMap() {
Expand Down

0 comments on commit 5592607

Please sign in to comment.