mirror of
https://github.com/GTNewHorizons/Mantle.git
synced 2026-11-25 06:14:45 +00:00
Update to the latest forge, add caching features to the blockstate and model generators, implement an language generator for blocks and items and remove the unneeded deobf at.
This commit is contained in:
1 parent
77c6c0cbbf
commit
c1c3391e4a
6 files changed
+197
-12
No files matched your search
@@ -0,0 +1,28 @@
|
||||
package slimeknights.mantle.item;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.item.Food;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import slimeknights.mantle.common.IGeneratedJson;
|
||||
|
||||
public class EdibleItem extends Item implements IGeneratedJson {
|
||||
|
||||
public EdibleItem(Food foodIn, ItemGroup itemGroup) {
|
||||
super(new Properties().food(foodIn).group(itemGroup));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParentToUse() {
|
||||
return "item/generated";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject getTexturesToUse() {
|
||||
JsonObject textures = new JsonObject();
|
||||
|
||||
textures.addProperty("layer0", this.getRegistryName().getNamespace() + ":item/" + this.getRegistryName().getPath() + " CHANGEME");
|
||||
|
||||
return textures;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package slimeknights.mantle.item;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import slimeknights.mantle.common.IGeneratedJson;
|
||||
|
||||
public class GeneratedItem extends Item implements IGeneratedJson {
|
||||
|
||||
public GeneratedItem(ItemGroup itemGroup) {
|
||||
super(new Properties().group(itemGroup));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParentToUse() {
|
||||
return "item/generated";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject getTexturesToUse() {
|
||||
JsonObject textures = new JsonObject();
|
||||
|
||||
textures.addProperty("layer0", this.getRegistryName().getNamespace() + ":item/" + this.getRegistryName().getPath() + " CHANGEME");
|
||||
|
||||
return textures;
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,18 @@ package slimeknights.mantle.util;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.DirectoryCache;
|
||||
import net.minecraft.data.IDataProvider;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import slimeknights.mantle.common.IGeneratedJson;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class BlockStateJsonGenerator implements IDataProvider {
|
||||
@@ -28,6 +31,15 @@ public class BlockStateJsonGenerator implements IDataProvider {
|
||||
@Override
|
||||
public void act(DirectoryCache cache) throws IOException {
|
||||
JsonObject blockState = new JsonObject();
|
||||
int generatedEntries = 0;
|
||||
JsonObject blockstateCache = new JsonObject();
|
||||
|
||||
Path cacheP = this.generator.getOutputFolder().resolve("cache/" + this.modId + "/blockstates/blockstates.json");
|
||||
|
||||
if (Files.exists(cacheP)) {
|
||||
String jsonTxt = IOUtils.toString(cacheP.toUri(), "UTF-8");
|
||||
blockstateCache = new JsonParser().parse(jsonTxt).getAsJsonObject();
|
||||
}
|
||||
|
||||
for (Block block : Registry.BLOCK) {
|
||||
blockState = new JsonObject();
|
||||
@@ -40,14 +52,26 @@ public class BlockStateJsonGenerator implements IDataProvider {
|
||||
if (!(block instanceof IGeneratedJson)) {
|
||||
continue;
|
||||
}
|
||||
if (blockstateCache.has(resourcelocation.toString())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
IGeneratedJson block1 = (IGeneratedJson) block;
|
||||
|
||||
blockState.add("variants", block1.getVariants());
|
||||
|
||||
blockstateCache.addProperty(resourcelocation.toString(), "UNUSED");
|
||||
generatedEntries++;
|
||||
|
||||
Path path = this.generator.getOutputFolder().resolve("assets/" + this.modId + "/blockstates/" + resourcelocation.getPath() + ".json");
|
||||
IDataProvider.func_218426_a(GSON, cache, blockState, path);
|
||||
}
|
||||
|
||||
if (generatedEntries != 0) {
|
||||
IDataProvider.func_218426_a(GSON, cache, blockstateCache, cacheP);
|
||||
}
|
||||
|
||||
cache.func_218456_c(cacheP);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package slimeknights.mantle.util;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.DirectoryCache;
|
||||
import net.minecraft.data.IDataProvider;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class LanguageJsonGenerator implements IDataProvider {
|
||||
|
||||
private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().create();
|
||||
private final DataGenerator generator;
|
||||
private final String modId;
|
||||
|
||||
public LanguageJsonGenerator(DataGenerator generatorIn, String modId) {
|
||||
this.generator = generatorIn;
|
||||
this.modId = modId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(DirectoryCache cache) throws IOException {
|
||||
JsonObject names = new JsonObject();
|
||||
int generatedEntries = 0;
|
||||
|
||||
Path cacheP = this.generator.getOutputFolder().resolve("cache/" + this.modId + "/lang/en_us.json");
|
||||
String jsonTxt = IOUtils.toString(cacheP.toUri(), "UTF-8");
|
||||
JsonObject langCache = new JsonParser().parse(jsonTxt).getAsJsonObject();
|
||||
|
||||
for (Block block : Registry.BLOCK) {
|
||||
ResourceLocation resourcelocation = Registry.BLOCK.getKey(block);
|
||||
|
||||
if (!resourcelocation.getNamespace().equals(this.modId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (langCache.has(block.getTranslationKey())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
names.addProperty(block.getTranslationKey(), "RENAME");
|
||||
langCache.addProperty(block.getTranslationKey(), "RENAME");
|
||||
generatedEntries++;
|
||||
}
|
||||
|
||||
for (Item item : Registry.ITEM) {
|
||||
ResourceLocation resourcelocation = Registry.ITEM.getKey(item);
|
||||
|
||||
if (!resourcelocation.getNamespace().equals(this.modId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (langCache.has(item.getTranslationKey())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
names.addProperty(item.getTranslationKey(), "RENAME");
|
||||
langCache.addProperty(item.getTranslationKey(), "RENAME");
|
||||
generatedEntries++;
|
||||
}
|
||||
|
||||
Path path = this.generator.getOutputFolder().resolve("assets/" + this.modId + "/lang/en_us.json");
|
||||
IDataProvider.func_218426_a(GSON, cache, names, path);
|
||||
|
||||
if (generatedEntries != 0) {
|
||||
IDataProvider.func_218426_a(GSON, cache, langCache, cacheP);
|
||||
}
|
||||
|
||||
cache.func_218456_c(cacheP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a name for this provider, to use in logging.
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Language Generator";
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package slimeknights.mantle.util;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.DirectoryCache;
|
||||
@@ -10,9 +11,11 @@ import net.minecraft.data.IDataProvider;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import slimeknights.mantle.common.IGeneratedJson;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -33,6 +36,15 @@ public class ModelJsonGenerator implements IDataProvider {
|
||||
JsonObject blockObject = new JsonObject();
|
||||
JsonObject itemObject = new JsonObject();
|
||||
List<ResourceLocation> resourceLocations = new ArrayList<ResourceLocation>();
|
||||
int generatedEntries = 0;
|
||||
JsonObject modelCache = new JsonObject();
|
||||
|
||||
Path cacheP = this.generator.getOutputFolder().resolve("cache/" + this.modId + "/models/models.json");
|
||||
|
||||
if (Files.exists(cacheP)) {
|
||||
String jsonTxt = IOUtils.toString(cacheP.toUri(), "UTF-8");
|
||||
modelCache = new JsonParser().parse(jsonTxt).getAsJsonObject();
|
||||
}
|
||||
|
||||
for (Block block : Registry.BLOCK) {
|
||||
blockObject = new JsonObject();
|
||||
@@ -44,6 +56,9 @@ public class ModelJsonGenerator implements IDataProvider {
|
||||
if (!(block instanceof IGeneratedJson)) {
|
||||
continue;
|
||||
}
|
||||
if (modelCache.has(resourcelocation.toString())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
IGeneratedJson block1 = (IGeneratedJson) block;
|
||||
|
||||
@@ -53,6 +68,9 @@ public class ModelJsonGenerator implements IDataProvider {
|
||||
|
||||
blockObject.add("textures", block1.getTexturesToUse());
|
||||
|
||||
modelCache.addProperty(resourcelocation.toString(), "UNUSED");
|
||||
generatedEntries++;
|
||||
|
||||
Path path = this.generator.getOutputFolder().resolve("assets/" + this.modId + "/models/block/" + resourcelocation.getPath() + ".json");
|
||||
IDataProvider.func_218426_a(GSON, cache, blockObject, path);
|
||||
}
|
||||
@@ -64,6 +82,9 @@ public class ModelJsonGenerator implements IDataProvider {
|
||||
if (!resourcelocation.getNamespace().equals(this.modId)) {
|
||||
continue;
|
||||
}
|
||||
if (modelCache.has(resourcelocation.toString())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (resourceLocations.contains(resourcelocation)) {
|
||||
itemObject.addProperty("parent", resourcelocation.getNamespace() + ":block/" + resourcelocation.getPath());
|
||||
@@ -82,10 +103,19 @@ public class ModelJsonGenerator implements IDataProvider {
|
||||
|
||||
itemObject.add("textures", item1.getTexturesToUse());
|
||||
|
||||
modelCache.addProperty(resourcelocation.toString(), "UNUSED");
|
||||
generatedEntries++;
|
||||
|
||||
Path path = this.generator.getOutputFolder().resolve("assets/" + this.modId + "/models/item/" + resourcelocation.getPath() + ".json");
|
||||
IDataProvider.func_218426_a(GSON, cache, itemObject, path);
|
||||
}
|
||||
}
|
||||
|
||||
if (generatedEntries != 0) {
|
||||
IDataProvider.func_218426_a(GSON, cache, modelCache, cacheP);
|
||||
}
|
||||
|
||||
cache.func_218456_c(cacheP);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user