Skip to content

Commit

Permalink
Fix the remaining places where identifiers are constructed with user …
Browse files Browse the repository at this point in the history
…input data.
  • Loading branch information
kvverti committed May 8, 2022
1 parent 9d11b55 commit 3306373
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ org.gradle.jvmargs=-Xmx1G
yarn_mappings=1.18.2+build.2
loader_version=0.13.3
# Mod Properties
mod_version = 3.1.1
mod_version = 3.1.2-snapshot
maven_group = io.github.kvverti
archives_base_name = colormatic

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public class ColormapProperties {
private final Collection<ApplicableBlockStates> blocks;

/**
* s
* The colormap image. If not specified, it is taken from the file name
* of the properties file.
*/
Expand Down Expand Up @@ -134,7 +133,12 @@ private ColormapProperties(Identifier id, Settings settings) {
this.optifine = this.id.getPath().endsWith(".properties");
this.format = settings.format;
this.blocks = settings.blocks;
this.source = new Identifier(settings.source);
Identifier source = Identifier.tryParse(settings.source);
if(source == null) {
log.error("{}: Invalid source location '{}', using file name as fallback", id, settings.source);
source = new Identifier(makeSourceFromFileName(id));
}
this.source = source;
this.color = settings.color;
this.layout = Objects.requireNonNullElse(settings.layout, this.optifine ? ColumnLayout.OPTIFINE : ColumnLayout.DEFAULT);
this.yVariance = settings.yVariance;
Expand Down Expand Up @@ -371,14 +375,18 @@ private static ColormapProperties loadFromJson(Reader json, Identifier id, boole
settings.blocks = Collections.emptyList();
}
if(settings.source == null) {
String path = id.toString();
path = path.substring(0, path.lastIndexOf('.')) + ".png";
settings.source = path;
settings.source = makeSourceFromFileName(id);
}
settings.source = PropertyUtil.resolve(settings.source, id);
return new ColormapProperties(id, settings);
}

private static String makeSourceFromFileName(Identifier id) {
String path = id.toString();
path = path.substring(0, path.lastIndexOf('.')) + ".png";
return path;
}

private static class Settings {

Format format = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private Map<Identifier, HexColor> convertIdMap(Map<String, HexColor> map) {
private static <T> Map<T, HexColor> convertMap(Map<String, HexColor> initial, Registry<T> registry) {
Map<T, HexColor> res = new HashMap<>();
for(Map.Entry<String, HexColor> entry : initial.entrySet()) {
T key = registry.get(new Identifier(entry.getKey()));
T key = registry.get(Identifier.tryParse(entry.getKey()));
if(key != null) {
res.put(key, entry.getValue());
}
Expand Down Expand Up @@ -164,18 +164,18 @@ private static Map<EntityType<?>, int[]> collateSpawnEggColors(Settings settings
if(settings.egg != null) {
LegacyEggColor legacy = settings.egg;
for(Map.Entry<String, HexColor> entry : legacy.shell.entrySet()) {
EntityType<?> type = registry.get(new Identifier(entry.getKey()));
EntityType<?> type = registry.get(Identifier.tryParse(entry.getKey()));
res.put(type, new int[]{ entry.getValue().rgb(), 0 });
}
for(Map.Entry<String, HexColor> entry : legacy.spots.entrySet()) {
EntityType<?> type = registry.get(new Identifier(entry.getKey()));
EntityType<?> type = registry.get(Identifier.tryParse(entry.getKey()));
int[] colors = res.computeIfAbsent(type, t -> new int[2]);
colors[1] = entry.getValue().rgb();
}
}
// handle colormatic egg colors
for(Map.Entry<String, HexColor[]> entry : settings.spawnegg.entrySet()) {
EntityType<?> type = registry.get(new Identifier(entry.getKey()));
EntityType<?> type = registry.get(Identifier.tryParse(entry.getKey()));
int[] colors = res.computeIfAbsent(type, t -> new int[2]);
HexColor[] hexColors = entry.getValue();
for(int i = 0; i < Math.min(2, hexColors.length); i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"fabric-resource-loader-v0": ">=0.4"
},
"recommends": {
"quilt-loader": "*",
"quilt_loader": "*",
"modmenu": "^3.0.0"
},
"suggests": {
Expand Down

0 comments on commit 3306373

Please sign in to comment.