1
0
mirror of https://github.com/GeyserMC/PackConverter.git synced 2025-12-27 18:59:13 +00:00

Start on custom model data handling

This commit is contained in:
DoctorMacc
2020-10-13 23:43:27 -04:00
parent 62c43802b8
commit 7c169db8f5
5 changed files with 204 additions and 0 deletions

18
pom.xml
View File

@@ -46,6 +46,19 @@
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>nukkitx-release-repo</id>
<url>https://repo.nukkitx.com/maven-releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
@@ -63,5 +76,10 @@
<artifactId>imageio-tga</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>com.nukkitx.fastutil</groupId>
<artifactId>fastutil-int-object-maps</artifactId>
<version>8.3.1</version>
</dependency>
</dependencies>
</project>

View File

@@ -68,6 +68,7 @@ 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

View File

@@ -0,0 +1,79 @@
/*
* 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.converters;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import org.geysermc.packconverter.api.utils.CustomModelDataHandler;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
public class CustomModelDataConverter extends AbstractConverter {
@Getter
public static final List<Object[]> defaultData = new ArrayList<>();
static {
defaultData.add(new String[] {""});
}
public CustomModelDataConverter(Path storage, Object[] data) {
super(storage, data);
}
@Override
public List<AbstractConverter> convert() {
System.out.println("Checking for custom model data");
try {
ObjectMapper mapper = new ObjectMapper();
for (File file : storage.resolve("assets/minecraft/models/item").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")) {
int id = predicate.get("custom_model_data").asInt();
String identifier = CustomModelDataHandler.handle(mapper, storage, override.get("model").asText());
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return new ArrayList<>();
}
}

View File

@@ -0,0 +1,43 @@
/*
* 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
@Setter
@AllArgsConstructor
public class CustomModelData {
private final String itemId;
//private final Int2ObjectMap<CustomModelDataItem> customModelData = new Int2ObjectOpenHashMap<>();
}

View File

@@ -0,0 +1,63 @@
/*
* 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 com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
public class CustomModelDataHandler {
public static String handle(ObjectMapper mapper, Path storage, String filePath) {
ObjectNode item = mapper.createObjectNode();
item.put("format_version", "1.16.0");
ObjectNode itemData = mapper.createObjectNode();
ObjectNode itemDescription = mapper.createObjectNode();
String identifier = "geysercmd:" + filePath.replace("item/", "");
itemDescription.put("identifier", identifier);
itemData.set("description", itemDescription);
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)) {
mapper.writer().writeValue(outputStream, item);
} catch (IOException e) {
e.printStackTrace();
return null;
}
return identifier;
}
}