use of net.coderbot.iris.shaderpack.ShaderPack in project Iris by IrisShaders.
the class IdMapTest method testLoadIdMaps.
@Test
void testLoadIdMaps() {
ShaderPack shaderPack;
// ensure that we can actually load the shader pack
try {
shaderPack = new ShaderPack(IrisTests.getTestShaderPackPath("id_maps"));
} catch (Exception e) {
Assertions.fail("Couldn't load test shader pack id_maps", e);
return;
}
Map<NamespacedId, BlockRenderType> overrides = shaderPack.getIdMap().getBlockRenderTypeMap();
Int2ObjectMap<List<BlockEntry>> blocks = shaderPack.getIdMap().getBlockProperties();
Assertions.assertEquals(EXPECTED_LAYERS, overrides);
Assertions.assertEquals(EXPECTED_BLOCKS, blocks);
}
use of net.coderbot.iris.shaderpack.ShaderPack in project Iris by IrisShaders.
the class LanguageMapTest method testLoadLanguages.
@Test
void testLoadLanguages() {
ShaderPack shaderPack;
// ensure that we can actually load the shader pack
try {
shaderPack = new ShaderPack(IrisTests.getTestShaderPackPath("language_maps"));
} catch (Exception e) {
Assertions.fail("Couldn't load test shader pack language_maps", e);
return;
}
// ensure that we only loaded two language files
LanguageMap languageMap = shaderPack.getLanguageMap();
Assertions.assertEquals(2, languageMap.getLanguages().size(), "number of languages loaded");
// test that en_US.lang was loaded properly
{
Map<String, String> english = languageMap.getTranslations("en_us");
Assertions.assertNotNull(english, "en_us translations");
Assertions.assertEquals(2, english.size(), "number of translations in en_US.lang");
Assertions.assertEquals("Test screen", english.get("screen.TEST"));
Assertions.assertEquals("Test option", english.get("option.TEST_OPTION"));
}
// test that fr_FR.lang was loaded properly
{
Map<String, String> french = languageMap.getTranslations("fr_fr");
Assertions.assertNotNull(french, "fr_fr translations");
Assertions.assertEquals(1, french.size(), "number of translations in fr_FR.lang");
Assertions.assertEquals("Écran de test", french.get("screen.TEST"));
}
}
use of net.coderbot.iris.shaderpack.ShaderPack in project Iris by IrisShaders.
the class OptionApplyTest method testOptions.
// @Test
// TODO: Re-enable this once we can load shader packs in tests without referencing OpenGL / LWJGL / Minecraft.
void testOptions() {
ShaderPack shaderPack;
// ensure that we can actually load the shader pack
try {
shaderPack = new ShaderPack(IrisTests.getTestShaderPackPath("options"));
} catch (Exception e) {
Assertions.fail("Couldn't load test shader pack options", e);
return;
}
ProgramSource basic = shaderPack.getProgramSet(DimensionId.OVERWORLD).getGbuffersBasic().orElseThrow(RuntimeException::new);
String basicVsh = basic.getVertexSource().orElseThrow(RuntimeException::new);
String basicFsh = basic.getFragmentSource().orElseThrow(RuntimeException::new);
OptionAnnotatedSource basicVshAnnotated = new OptionAnnotatedSource(basicVsh);
OptionAnnotatedSource basicFshAnnotated = new OptionAnnotatedSource(basicFsh);
// TODO: Separate includes will need more complex boolean define reference behavior
OptionSet basicVshSet = basicVshAnnotated.getOptionSet(AbsolutePackPath.fromAbsolutePath("/basic.vsh"), basicVshAnnotated.getBooleanDefineReferences().keySet());
OptionSet basicFshSet = basicFshAnnotated.getOptionSet(AbsolutePackPath.fromAbsolutePath("/basic.fsh"), basicFshAnnotated.getBooleanDefineReferences().keySet());
OptionSet.Builder setBuilder = OptionSet.builder();
setBuilder.addAll(basicVshSet);
setBuilder.addAll(basicFshSet);
OptionSet options = setBuilder.build();
Map<String, String> changes = ImmutableMap.of("SHADOWS", "false", "ambientOcclusionLevel", "0.0", "shadowDistance", "64", "ANNOYING_STUFF", "true", "GODRAYS", "16");
OptionValues values = new MutableOptionValues(options, changes);
System.out.println(basicVshAnnotated.apply(values));
System.out.println(basicFshAnnotated.apply(values));
System.out.println(options);
}
use of net.coderbot.iris.shaderpack.ShaderPack in project Iris by IrisShaders.
the class Iris method loadExternalShaderpack.
private static boolean loadExternalShaderpack(String name) {
Path shaderPackRoot;
Path shaderPackConfigTxt;
try {
shaderPackRoot = getShaderpacksDirectory().resolve(name);
shaderPackConfigTxt = getShaderpacksDirectory().resolve(name + ".txt");
} catch (InvalidPathException e) {
logger.error("Failed to load the shaderpack \"{}\" because it contains invalid characters in its path", name);
return false;
}
Path shaderPackPath;
if (shaderPackRoot.toString().endsWith(".zip")) {
Optional<Path> optionalPath;
try {
optionalPath = loadExternalZipShaderpack(shaderPackRoot);
} catch (FileSystemNotFoundException | NoSuchFileException e) {
logger.error("Failed to load the shaderpack \"{}\" because it does not exist in your shaderpacks folder!", name);
return false;
} catch (ZipException e) {
logger.error("The shaderpack \"{}\" appears to be corrupted, please try downloading it again!", name);
return false;
} catch (IOException e) {
logger.error("Failed to load the shaderpack \"{}\"!", name);
logger.error("", e);
return false;
}
if (optionalPath.isPresent()) {
shaderPackPath = optionalPath.get();
} else {
logger.error("Could not load the shaderpack \"{}\" because it appears to lack a \"shaders\" directory", name);
return false;
}
} else {
if (!Files.exists(shaderPackRoot)) {
logger.error("Failed to load the shaderpack \"{}\" because it does not exist!", name);
return false;
}
// If it's a folder-based shaderpack, just use the shaders subdirectory
shaderPackPath = shaderPackRoot.resolve("shaders");
}
if (!Files.exists(shaderPackPath)) {
logger.error("Could not load the shaderpack \"{}\" because it appears to lack a \"shaders\" directory", name);
return false;
}
Map<String, String> changedConfigs = tryReadConfigProperties(shaderPackConfigTxt).map(properties -> (Map<String, String>) (Map) properties).orElse(new HashMap<>());
changedConfigs.putAll(shaderPackOptionQueue);
clearShaderPackOptionQueue();
if (resetShaderPackOptions) {
changedConfigs.clear();
}
resetShaderPackOptions = false;
try {
currentPack = new ShaderPack(shaderPackPath, changedConfigs);
MutableOptionValues changedConfigsValues = currentPack.getShaderPackOptions().getOptionValues().mutableCopy();
// Store changed values from those currently in use by the shader pack
Properties configsToSave = new Properties();
changedConfigsValues.getBooleanValues().forEach((k, v) -> configsToSave.setProperty(k, Boolean.toString(v)));
changedConfigsValues.getStringValues().forEach(configsToSave::setProperty);
tryUpdateConfigPropertiesFile(shaderPackConfigTxt, configsToSave);
} catch (Exception e) {
logger.error("Failed to load the shaderpack \"{}\"!", name);
logger.error("", e);
return false;
}
currentPackName = name;
logger.info("Using shaderpack: " + name);
return true;
}
use of net.coderbot.iris.shaderpack.ShaderPack in project Iris by IrisShaders.
the class Iris method loadExternalZipShaderpack.
private static Optional<Path> loadExternalZipShaderpack(Path shaderpackPath) throws IOException {
FileSystem zipSystem = FileSystems.newFileSystem(shaderpackPath, Iris.class.getClassLoader());
zipFileSystem = zipSystem;
// Should only be one root directory for a zip shaderpack
Path root = zipSystem.getRootDirectories().iterator().next();
Path potentialShaderDir = zipSystem.getPath("shaders");
// Otherwise, manually search through each directory path until it ends with "shaders"
if (Files.exists(potentialShaderDir)) {
return Optional.of(potentialShaderDir);
}
// This makes it hard to determine what is the actual shaders dir
return Files.walk(root).filter(Files::isDirectory).filter(path -> path.endsWith("shaders")).findFirst();
}
Aggregations