Class ShaderPreDefinitions

java.lang.Object
com.hbm_m.client.render.shader.modification.ShaderPreDefinitions

public final class ShaderPreDefinitions extends Object
Wraps a ResourceProvider so that resources matching a target ResourceLocation are intercepted, their content is run through a ShaderModification, and the modified bytes are exposed back to the caller as a synthetic Resource.

This is the entry point used by ClientSetup.onRegisterShaders to compile multiple variants of the same shader source with different preprocessor defines (e.g. with and without #define USE_INSTANCING).

  • Method Details

    • wrap

      public static net.minecraft.server.packs.resources.ResourceProvider wrap(net.minecraft.server.packs.resources.ResourceProvider delegate, net.minecraft.resources.ResourceLocation target, ShaderModification modification)
      Returns a ResourceProvider that delegates to delegate for every resource except target. When target is requested the original bytes are loaded, passed through modification.apply(...), and re-wrapped as a Resource.
    • wrapRedirect

      public static net.minecraft.server.packs.resources.ResourceProvider wrapRedirect(net.minecraft.server.packs.resources.ResourceProvider delegate, net.minecraft.resources.ResourceLocation virtualTarget, net.minecraft.resources.ResourceLocation realSource, ShaderModification modification)
      Same as wrap(net.minecraft.server.packs.resources.ResourceProvider, net.minecraft.resources.ResourceLocation, com.hbm_m.client.render.shader.modification.ShaderModification), but when virtualTarget is requested the bytes are loaded from realSource (which DOES exist in resource packs), then patched and returned as if they were the virtualTarget's content. This is essential when registering multiple ShaderInstances that share the same source but need DIFFERENT compiled programs — vanilla Program.getOrCreate caches by the "vertex"/"fragment" name from the JSON, so two variants pointing at the same name will collide and only the first compilation wins.

      Example: block_lit_simple.json references "vertex": "hbm_m:block_lit", block_lit_instanced.json references "vertex": "hbm_m:block_lit_instanced". Only the latter file does not exist on disk; this provider fabricates it from hbm_m:shaders/core/block_lit.vsh + #define USE_INSTANCING.