-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathAnimationConverter.java
More file actions
62 lines (51 loc) · 2.22 KB
/
AnimationConverter.java
File metadata and controls
62 lines (51 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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.pack.Pack;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
public class AnimationConverter extends Converter {
public AnimationConverter(PackConverter packConverter) {
super(packConverter);
}
@Override
public void convert(Pack pack) throws IOException {
Path texturesPath = pack.getMinecraftPath().resolve("textures");
fixAnimations(texturesPath.resolve("block"));
fixAnimations(texturesPath.resolve("item"));
}
protected void fixAnimations(Path animations) throws IOException {
if (!Files.exists(animations)) {
return;
}
Files.list(animations)
.filter(file -> file.toString().endsWith(".png.mcmeta"))
.forEach(file -> {
try {
JsonObject json = Util.readJson(packConverter.getGson(), file);
boolean anyChanges = false;
JsonElement animationElement = json.get("animation");
if (animationElement instanceof JsonObject) {
JsonObject animationObject = (JsonObject) animationElement;
// TODO: Confirm this doesn't break any packs
animationObject.remove("width");
animationObject.remove("height");
anyChanges = true;
}
if (anyChanges) {
Files.write(file, packConverter.getGson().toJson(json).getBytes(StandardCharsets.UTF_8));
if (PackConverter.DEBUG) {
System.out.println(" Converted " + file.getFileName());
}
}
} catch (IOException e) {
Util.propagate(e);
}
});
}
}