1
0
mirror of https://github.com/GeyserMC/PackConverter.git synced 2025-12-30 20:29:24 +00:00

Clean-up of custom model conversion

This commit is contained in:
rtm516
2020-10-14 20:08:48 +01:00
parent d2bfc915a2
commit 9264d02f26
4 changed files with 20 additions and 56 deletions

View File

@@ -68,13 +68,16 @@ public class ConverterHandler {
converterList.add(ColorizeOverlayConverter.class);
converterList.add(PlaceholderConverter.class);
converterList.add(CustomModelDataConverter.class);
//converterList.add(ArrowConverter.class); // This is disabled as its broken and the intended output it just the original
converterList.add(EnchantedItemGlintConverter.class);
converterList.add(PngToTgaConverter.class);
converterList.add(CopyConverter.class);
// Custom, not part of the original lib
converterList.add(CustomModelDataConverter.class);
converterList.add(DeleteConverter.class);
}
}

View File

@@ -50,7 +50,7 @@ public class CustomModelDataConverter extends AbstractConverter {
public static final List<Object[]> defaultData = new ArrayList<>();
static {
defaultData.add(new String[] {""});
defaultData.add(new String[] {"assets/minecraft/models/item", "textures/item_texture.json"});
}
public CustomModelDataConverter(PackConverter packConverter, Path storage, Object[] data) {
@@ -61,6 +61,9 @@ public class CustomModelDataConverter extends AbstractConverter {
public List<AbstractConverter> convert() {
System.out.println("Checking for custom model data");
try {
String from = (String) this.data[0];
String to = (String) this.data[1];
ObjectMapper mapper = new ObjectMapper();
// Create the texture_data file that will map all textures
@@ -68,12 +71,11 @@ public class CustomModelDataConverter extends AbstractConverter {
textureData.put("resource_pack_name", "geysercmd");
textureData.put("texture_name", "atlas.items");
ObjectNode allTextures = mapper.createObjectNode();
for (File file : storage.resolve("assets/minecraft/models/item").toFile().listFiles()) {
for (File file : storage.resolve(from).toFile().listFiles()) {
InputStream stream = new FileInputStream(file);
JsonNode node = mapper.readTree(stream);
if (node.has("overrides")) {
System.out.println(node.get("overrides"));
for (JsonNode override : node.get("overrides")) {
JsonNode predicate = override.get("predicate");
if (predicate.has("custom_model_data")) {
@@ -83,8 +85,7 @@ public class CustomModelDataConverter extends AbstractConverter {
if (data == null) {
Int2ObjectMap<String> map = new Int2ObjectOpenHashMap<>();
map.put(id, identifier);
packConverter.getCustomModelData().put(file.getName().replace(".json", ""),
map);
packConverter.getCustomModelData().put(file.getName().replace(".json", ""), map);
} else {
data.put(id, identifier);
}
@@ -97,17 +98,17 @@ public class CustomModelDataConverter extends AbstractConverter {
}
}
}
textureData.set("texture_data", allTextures);
try (OutputStream outputStream = Files.newOutputStream(storage.resolve("textures/item_texture.json"),
StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE)) {
mapper.writer(new DefaultPrettyPrinter()).writeValue(outputStream, textureData);
} catch (IOException e) {
e.printStackTrace();
return null;
}
OutputStream outputStream = Files.newOutputStream(storage.resolve(to), StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE);
mapper.writer(new DefaultPrettyPrinter()).writeValue(outputStream, textureData);
System.out.println(String.format("Converted models %s", from));
} catch (Exception e) {
e.printStackTrace();
}
return new ArrayList<>();
}
}

View File

@@ -1,42 +0,0 @@
/*
* Copyright (c) 2019-2020 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/PackConverter
*
*/
package org.geysermc.packconverter.api.utils;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
@Getter
@AllArgsConstructor
public class CustomModelData {
private final int dataId;
private final String identifier;
}

View File

@@ -42,6 +42,7 @@ public class CustomModelDataHandler {
item.put("format_version", "1.16.0");
ObjectNode itemData = mapper.createObjectNode();
ObjectNode itemDescription = mapper.createObjectNode();
// Full identifier with geysercmd prefix
String identifier = "geysercmd:" + filePath.replace("item/", "");
itemDescription.put("identifier", identifier);
@@ -51,10 +52,12 @@ public class CustomModelDataHandler {
itemComponent.put("minecraft:render_offsets", "tools");
itemData.set("components", itemComponent);
item.set("minecraft:item", itemData);
File itemJsonFile = storage.resolve("items").toFile();
if (!itemJsonFile.exists()) {
itemJsonFile.mkdir();
}
Path path = itemJsonFile.toPath().resolve(filePath.replace("item/", "") + ".json");
try (OutputStream outputStream = Files.newOutputStream(path,
StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE)) {
@@ -80,7 +83,6 @@ public class CustomModelDataHandler {
return null;
}
System.out.println(textureFile);
// TODO: Don't rely on getting the 0 texture
if (textureFile.has("textures")) {
if (textureFile.get("textures").has("0") || textureFile.get("textures").has("layer0")) {