Skip to content

Commit

Permalink
Added support for Lang files
Browse files Browse the repository at this point in the history
  • Loading branch information
CoryBorek committed Mar 7, 2020
1 parent 4973c19 commit a8e9c7d
Show file tree
Hide file tree
Showing 4 changed files with 1,722 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/net/hypixel/resourcepack/PackConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ public PackConverter(OptionSet optionSet) {
if (from.equals("1.12")) {
this.registerConverter(new ModelConverter(this, light));
this.registerConverter(new SpacesConverter(this));
this.registerConverter(new LangConverter(this));
this.registerConverter(new SoundsConverter(this));
this.registerConverter(new ParticleConverter(this));
this.registerConverter(new BlockStateConverter(this));
this.registerConverter(new AnimationConverter(this));
this.registerConverter(new MapIconConverter(this));
this.registerConverter(new MCPatcherConverter(this));
}
this.registerConverter(new LangConverter(this));
if (to.equals("1.15")) this.registerConverter(new ChestConverter(this));
}

Expand Down
65 changes: 65 additions & 0 deletions src/main/java/net/hypixel/resourcepack/impl/LangConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package net.hypixel.resourcepack.impl;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.hypixel.resourcepack.Converter;
import net.hypixel.resourcepack.PackConverter;
import net.hypixel.resourcepack.Util;
import net.hypixel.resourcepack.extra.PropertiesEx;
import net.hypixel.resourcepack.pack.Pack;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Enumeration;
import java.util.Map;

public class LangConverter extends Converter {
public LangConverter(PackConverter packConverter) {
super(packConverter);
}

@Override

public void convert(Pack pack) throws IOException {
Path path = pack.getWorkingPath().resolve("assets" + File.separator + "minecraft" + File.separator + "lang");
if (!path.toFile().exists()) return;

Files.list(path)
.filter(path1 -> path1.toString().endsWith(".lang"))
.forEach(model -> {
try (InputStream input = new FileInputStream(model.toString())) {
PropertiesEx prop = new PropertiesEx();
PropertiesEx prop2 = new PropertiesEx();
prop.load(input);
JsonObject id = Util.readJsonResource(packConverter.getGson(), "/lang.json");
try (OutputStream output = new FileOutputStream(model.toString())) {
Enumeration<String> enums = (Enumeration<String>) prop.propertyNames();
while (enums.hasMoreElements()) {
String key = enums.nextElement();
String value = prop.getProperty(key);
for (Map.Entry<String, JsonElement> id2 : id.entrySet()) {
if (key.equals(id2.getKey())) {
prop2.setProperty(id2.getValue().getAsString(), value);
} else prop2.setProperty(key, value);
}
}



//Saves File
prop2.store(output, "");
} catch (IOException io) {
io.printStackTrace();
}


} catch (IOException e) {
throw Util.propagate(e);
}
});
}


}

18 changes: 18 additions & 0 deletions src/main/java/net/hypixel/resourcepack/impl/NameConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class NameConverter extends Converter {
protected final Mapping blockMapping = new BlockMapping();
protected final Mapping itemMapping = new ItemMapping();
protected final Mapping entityMapping = new EntityMapping();
protected final Mapping langMapping = new LangMapping();

public NameConverter(PackConverter packConverter) {
super(packConverter);
Expand Down Expand Up @@ -91,6 +92,9 @@ public Mapping getBlockMapping() {
public Mapping getItemMapping() {
return itemMapping;
}
public Mapping getLangMapping() {
return langMapping;
}

protected abstract static class Mapping {

Expand Down Expand Up @@ -126,6 +130,20 @@ protected void load() {
}



protected class LangMapping extends Mapping {
@Override
protected void load() {
JsonObject entities = Util.readJsonResource(packConverter.getGson(), "/lang.json");
if (entities != null) {
for (Map.Entry<String, JsonElement> entry : entities.entrySet()) {
this.mapping.put(entry.getKey(), entry.getValue().getAsString());
}
}
}
}


protected class EntityMapping extends Mapping {

@Override
Expand Down
Loading

0 comments on commit a8e9c7d

Please sign in to comment.