|
| 1 | +/* |
| 2 | + * Copyright (c) 2016, 2017, 2018, 2019 FabricMC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package net.fabricmc.fabric.impl.client.rendering; |
| 18 | + |
| 19 | +import java.io.IOException; |
| 20 | + |
| 21 | +import com.mojang.blaze3d.vertex.VertexFormat; |
| 22 | +import net.minecraft.client.renderer.ShaderInstance; |
| 23 | +import net.minecraft.resources.ResourceLocation; |
| 24 | +import net.minecraft.server.packs.resources.ResourceProvider; |
| 25 | + |
| 26 | +public final class FabricShaderProgram extends ShaderInstance { |
| 27 | + public FabricShaderProgram(ResourceProvider factory, ResourceLocation name, VertexFormat format) throws IOException { |
| 28 | + super(factory, name, format); |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * Rewrites the input string containing an identifier |
| 33 | + * with the namespace of the id in the front instead of in the middle. |
| 34 | + * |
| 35 | + * <p>Example: {@code shaders/core/my_mod:xyz} -> {@code my_mod:shaders/core/xyz} |
| 36 | + * |
| 37 | + * @param input the raw input string |
| 38 | + * @param containedId the ID contained within the input string |
| 39 | + * @return the corrected full ID string |
| 40 | + */ |
| 41 | + public static ResourceLocation rewriteAsId(String input, String containedId) { |
| 42 | + ResourceLocation contained = ResourceLocation.parse(containedId); |
| 43 | + return contained.withPath(path -> input.replace(containedId, path)); |
| 44 | + } |
| 45 | +} |
0 commit comments