From e5a84529e46bbda611df77b056a59372ac374f27 Mon Sep 17 00:00:00 2001 From: wlghdu97 Date: Tue, 14 Jan 2020 14:13:47 +0900 Subject: [PATCH 01/14] added ShapelessOreRecipe --- .../bigbass/recex/recipes/OreDictItem.java | 14 ++-- .../recex/recipes/OreDictShapelessRecipe.java | 15 ++++ .../bigbass/recex/recipes/RecipeExporter.java | 83 ++++++++++++++++--- 3 files changed, 95 insertions(+), 17 deletions(-) create mode 100644 src/main/java/com/bigbass/recex/recipes/OreDictShapelessRecipe.java diff --git a/src/main/java/com/bigbass/recex/recipes/OreDictItem.java b/src/main/java/com/bigbass/recex/recipes/OreDictItem.java index 52d52bd..7a2c177 100644 --- a/src/main/java/com/bigbass/recex/recipes/OreDictItem.java +++ b/src/main/java/com/bigbass/recex/recipes/OreDictItem.java @@ -1,11 +1,15 @@ package com.bigbass.recex.recipes; -public class OreDictItem { +import com.google.common.collect.Lists; - public Item[] replacements; +import java.util.List; - public OreDictItem(Item... replacements){ - this.replacements = replacements; - } +public class OreDictItem { + public String name; + public List reps; + public OreDictItem(String oreDictName, List replacements){ + this.name = oreDictName; + this.reps = Lists.newArrayList(replacements); + } } diff --git a/src/main/java/com/bigbass/recex/recipes/OreDictShapelessRecipe.java b/src/main/java/com/bigbass/recex/recipes/OreDictShapelessRecipe.java new file mode 100644 index 0000000..ec23b99 --- /dev/null +++ b/src/main/java/com/bigbass/recex/recipes/OreDictShapelessRecipe.java @@ -0,0 +1,15 @@ +package com.bigbass.recex.recipes; + +import java.util.ArrayList; +import java.util.List; + +public class OreDictShapelessRecipe { + /** input items */ + public List iI; + /** output item */ + public Item o; + + public OreDictShapelessRecipe(){ + iI = new ArrayList(); + } +} diff --git a/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java b/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java index 44adf06..77da544 100644 --- a/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java +++ b/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java @@ -26,6 +26,7 @@ import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.ShapedOreRecipe; +import net.minecraftforge.oredict.ShapelessOreRecipe; public class RecipeExporter { @@ -61,8 +62,9 @@ public void run(){ sources.add(getShapedRecipes()); sources.add(getShapelessRecipes()); sources.add(getOreDictShapedRecipes()); - //TODO Support Oredicted Shaped and Shapeless Ore recipes - + sources.add(getOreDictShapelessRecipes()); + sources.add(getReplacements()); + root.put("sources", sources); Gson gson = (new GsonBuilder()).serializeNulls().create(); @@ -172,18 +174,14 @@ private Object getOreDictShapedRecipes(){ if (stack instanceof ItemStack) { Item item = RecipeUtil.formatRegularItemStack((ItemStack)stack); rec.iI.add(item); - }else if (stack instanceof String){ - rec.iI.add(new OreDictItem(getReplacements((String)stack).toArray(new Item[0]))); - }else if (stack instanceof String[]){ - Set multipleReplacemetns = new HashSet<>(); - for (String s : (String[]) stack){ - multipleReplacemetns.addAll(getReplacements((String)stack)); - } - rec.iI.add(multipleReplacemetns.toArray(new Item[0])); }else if (stack instanceof net.minecraft.item.Item){ rec.iI.add(RecipeUtil.formatRegularItemStack(new ItemStack((net.minecraft.item.Item)stack))); }else if (stack instanceof Block){ rec.iI.add(RecipeUtil.formatRegularItemStack(new ItemStack((Block)stack,1,Short.MAX_VALUE))); + }else if (stack instanceof ArrayList && !((ArrayList)stack).isEmpty()) { + @SuppressWarnings("unchecked") + ItemStack item = ((ArrayList)stack).get(0); + rec.iI.add(getOreDictNames(item)); } } @@ -197,14 +195,75 @@ private Object getOreDictShapedRecipes(){ return data; } - private Set getReplacements(String name){ + private Object getOreDictShapelessRecipes(){ + HashMap data = new HashMap<>(); + + data.put("type", "shapelessOre"); + + List retRecipes = new ArrayList<>(); + List recipes = CraftingManager.getInstance().getRecipeList(); + for(Object obj : recipes){ + if(obj instanceof ShapelessOreRecipe){ + ShapelessOreRecipe original = (ShapelessOreRecipe) obj; + OreDictShapelessRecipe rec = new OreDictShapelessRecipe(); + + for(Object stack : original.getInput()){ + if (stack instanceof ItemStack) { + Item item = RecipeUtil.formatRegularItemStack((ItemStack)stack); + rec.iI.add(item); + }else if (stack instanceof net.minecraft.item.Item){ + rec.iI.add(RecipeUtil.formatRegularItemStack(new ItemStack((net.minecraft.item.Item)stack))); + }else if (stack instanceof Block){ + rec.iI.add(RecipeUtil.formatRegularItemStack(new ItemStack((Block)stack, 1, Short.MAX_VALUE))); + }else if (stack instanceof ArrayList && !((ArrayList)stack).isEmpty()){ + @SuppressWarnings("unchecked") + ItemStack item = ((ArrayList)stack).get(0); + rec.iI.add(getOreDictNames(item)); + } + } + + rec.o = RecipeUtil.formatRegularItemStack(original.getRecipeOutput()); + + retRecipes.add(rec); + } + } + data.put("recipes", retRecipes); + + return data; + } + + private List getOreDictNames(ItemStack itemStack){ + int[] ids = OreDictionary.getOreIDs(itemStack); + ArrayList names = new ArrayList<>(); + for(int id : ids){ + names.add(OreDictionary.getOreName(id)); + } + return names; + } + + private Object getReplacements(){ + HashMap data = new HashMap<>(); + + data.put("type", "replacements"); + + List oreDictItems = new ArrayList<>(); + String[] oreNames = OreDictionary.getOreNames(); + for(String name : oreNames){ + oreDictItems.add(new OreDictItem(name, getReplacements(name))); + } + data.put("items", oreDictItems); + + return data; + } + + private List getReplacements(String name){ List recipeItemList = OreDictionary.getOres(name); Set replacements = new HashSet<>(); for (ItemStack inList : recipeItemList){ Item item = RecipeUtil.formatRegularItemStack(inList); replacements.add(item); } - return replacements; + return new ArrayList<>(replacements); } private Object getShapedRecipes(){ From 641be7aac92ada7e93581f1c720cc02d9ae23a8a Mon Sep 17 00:00:00 2001 From: wlghdu97 Date: Wed, 6 May 2020 06:00:09 +0900 Subject: [PATCH 02/14] Add gson serializers to order properties --- .../java/com/bigbass/recex/recipes/Fluid.java | 2 +- .../java/com/bigbass/recex/recipes/Item.java | 2 +- .../com/bigbass/recex/recipes/ItemBase.java | 3 + .../com/bigbass/recex/recipes/ItemList.java | 13 +++ .../com/bigbass/recex/recipes/Machine.java | 18 ++++ .../java/com/bigbass/recex/recipes/Mod.java | 13 +++ .../bigbass/recex/recipes/OreDictItem.java | 2 +- .../recex/recipes/OreDictShapedRecipe.java | 2 +- .../recex/recipes/OreDictShapelessRecipe.java | 2 +- .../com/bigbass/recex/recipes/Recipe.java | 3 + .../bigbass/recex/recipes/RecipeExporter.java | 102 +++++++----------- .../bigbass/recex/recipes/ShapedRecipe.java | 2 +- .../recex/recipes/ShapelessRecipe.java | 2 +- .../recipes/gregtech/GregtechMachine.java | 16 --- .../recipes/gregtech/GregtechRecipe.java | 9 +- .../serializers/ItemListSerializer.java | 19 ++++ .../serializers/MachineSerializer.java | 19 ++++ .../recipes/serializers/ModSerializer.java | 19 ++++ 18 files changed, 157 insertions(+), 91 deletions(-) create mode 100644 src/main/java/com/bigbass/recex/recipes/ItemBase.java create mode 100644 src/main/java/com/bigbass/recex/recipes/ItemList.java create mode 100644 src/main/java/com/bigbass/recex/recipes/Machine.java create mode 100644 src/main/java/com/bigbass/recex/recipes/Mod.java create mode 100644 src/main/java/com/bigbass/recex/recipes/Recipe.java delete mode 100644 src/main/java/com/bigbass/recex/recipes/gregtech/GregtechMachine.java create mode 100644 src/main/java/com/bigbass/recex/recipes/serializers/ItemListSerializer.java create mode 100644 src/main/java/com/bigbass/recex/recipes/serializers/MachineSerializer.java create mode 100644 src/main/java/com/bigbass/recex/recipes/serializers/ModSerializer.java diff --git a/src/main/java/com/bigbass/recex/recipes/Fluid.java b/src/main/java/com/bigbass/recex/recipes/Fluid.java index 78e5105..50085bc 100644 --- a/src/main/java/com/bigbass/recex/recipes/Fluid.java +++ b/src/main/java/com/bigbass/recex/recipes/Fluid.java @@ -1,6 +1,6 @@ package com.bigbass.recex.recipes; -public class Fluid { +public class Fluid implements ItemBase { /** amount */ public int a; diff --git a/src/main/java/com/bigbass/recex/recipes/Item.java b/src/main/java/com/bigbass/recex/recipes/Item.java index 82552ee..e43afa1 100644 --- a/src/main/java/com/bigbass/recex/recipes/Item.java +++ b/src/main/java/com/bigbass/recex/recipes/Item.java @@ -1,6 +1,6 @@ package com.bigbass.recex.recipes; -public class Item { +public class Item implements ItemBase { /** amount */ public int a; diff --git a/src/main/java/com/bigbass/recex/recipes/ItemBase.java b/src/main/java/com/bigbass/recex/recipes/ItemBase.java new file mode 100644 index 0000000..1535fba --- /dev/null +++ b/src/main/java/com/bigbass/recex/recipes/ItemBase.java @@ -0,0 +1,3 @@ +package com.bigbass.recex.recipes; + +public interface ItemBase { } diff --git a/src/main/java/com/bigbass/recex/recipes/ItemList.java b/src/main/java/com/bigbass/recex/recipes/ItemList.java new file mode 100644 index 0000000..effbf11 --- /dev/null +++ b/src/main/java/com/bigbass/recex/recipes/ItemList.java @@ -0,0 +1,13 @@ +package com.bigbass.recex.recipes; + +import java.util.List; + +public class ItemList { + public String type; + public List itemList; + + public ItemList(String type, List itemList) { + this.type = type; + this.itemList = itemList; + } +} diff --git a/src/main/java/com/bigbass/recex/recipes/Machine.java b/src/main/java/com/bigbass/recex/recipes/Machine.java new file mode 100644 index 0000000..ee60c91 --- /dev/null +++ b/src/main/java/com/bigbass/recex/recipes/Machine.java @@ -0,0 +1,18 @@ +package com.bigbass.recex.recipes; + +import java.util.ArrayList; +import java.util.List; + +public class Machine { + public String name; + public List recipes; + + public Machine(String name, List recipes) { + this.name = name; + this.recipes = recipes; + } + + public Machine(String name) { + this(name, new ArrayList<>()); + } +} diff --git a/src/main/java/com/bigbass/recex/recipes/Mod.java b/src/main/java/com/bigbass/recex/recipes/Mod.java new file mode 100644 index 0000000..e960344 --- /dev/null +++ b/src/main/java/com/bigbass/recex/recipes/Mod.java @@ -0,0 +1,13 @@ +package com.bigbass.recex.recipes; + +import java.util.List; + +public class Mod { + public String modName; + public List machines; + + public Mod(String modName, List machines) { + this.modName = modName; + this.machines = machines; + } +} diff --git a/src/main/java/com/bigbass/recex/recipes/OreDictItem.java b/src/main/java/com/bigbass/recex/recipes/OreDictItem.java index 7a2c177..98b3275 100644 --- a/src/main/java/com/bigbass/recex/recipes/OreDictItem.java +++ b/src/main/java/com/bigbass/recex/recipes/OreDictItem.java @@ -4,7 +4,7 @@ import java.util.List; -public class OreDictItem { +public class OreDictItem implements ItemBase { public String name; public List reps; diff --git a/src/main/java/com/bigbass/recex/recipes/OreDictShapedRecipe.java b/src/main/java/com/bigbass/recex/recipes/OreDictShapedRecipe.java index 80e3b3a..d13a20c 100644 --- a/src/main/java/com/bigbass/recex/recipes/OreDictShapedRecipe.java +++ b/src/main/java/com/bigbass/recex/recipes/OreDictShapedRecipe.java @@ -3,7 +3,7 @@ import java.util.ArrayList; import java.util.List; -public class OreDictShapedRecipe { +public class OreDictShapedRecipe implements Recipe { /** input items */ public List iI; /** output item */ diff --git a/src/main/java/com/bigbass/recex/recipes/OreDictShapelessRecipe.java b/src/main/java/com/bigbass/recex/recipes/OreDictShapelessRecipe.java index ec23b99..4bbe8db 100644 --- a/src/main/java/com/bigbass/recex/recipes/OreDictShapelessRecipe.java +++ b/src/main/java/com/bigbass/recex/recipes/OreDictShapelessRecipe.java @@ -3,7 +3,7 @@ import java.util.ArrayList; import java.util.List; -public class OreDictShapelessRecipe { +public class OreDictShapelessRecipe implements Recipe { /** input items */ public List iI; /** output item */ diff --git a/src/main/java/com/bigbass/recex/recipes/Recipe.java b/src/main/java/com/bigbass/recex/recipes/Recipe.java new file mode 100644 index 0000000..e745db8 --- /dev/null +++ b/src/main/java/com/bigbass/recex/recipes/Recipe.java @@ -0,0 +1,3 @@ +package com.bigbass.recex.recipes; + +public interface Recipe { } diff --git a/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java b/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java index 77da544..34b4031 100644 --- a/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java +++ b/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java @@ -1,20 +1,13 @@ package com.bigbass.recex.recipes; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import java.util.*; - import com.bigbass.recex.RecipeExporterMod; -import com.bigbass.recex.recipes.gregtech.GregtechMachine; import com.bigbass.recex.recipes.gregtech.GregtechRecipe; import com.bigbass.recex.recipes.gregtech.RecipeUtil; +import com.bigbass.recex.recipes.serializers.ItemListSerializer; +import com.bigbass.recex.recipes.serializers.MachineSerializer; +import com.bigbass.recex.recipes.serializers.ModSerializer; import com.google.gson.Gson; import com.google.gson.GsonBuilder; - import gregtech.api.util.GT_LanguageManager; import gregtech.api.util.GT_Recipe; import gregtech.api.util.GT_Recipe.GT_Recipe_Map; @@ -28,6 +21,14 @@ import net.minecraftforge.oredict.ShapedOreRecipe; import net.minecraftforge.oredict.ShapelessOreRecipe; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.*; + public class RecipeExporter { private static RecipeExporter instance; @@ -67,7 +68,12 @@ public void run(){ root.put("sources", sources); - Gson gson = (new GsonBuilder()).serializeNulls().create(); + Gson gson = new GsonBuilder() + .registerTypeAdapter(Mod.class, new ModSerializer()) + .registerTypeAdapter(Machine.class, new MachineSerializer()) + .registerTypeAdapter(ItemList.class, new ItemListSerializer()) + .serializeNulls() + .create(); try { saveData(gson.toJson(root)); } catch(Exception e){ @@ -84,18 +90,13 @@ public void run(){ *

This format does not impede the process of loading the recipes into NEP.

*/ private Object getGregtechRecipes(){ - Hashtable data = new Hashtable(); - - data.put("type", "gregtech"); - - List machines = new ArrayList(); + List machines = new ArrayList(); for(GT_Recipe_Map map : GT_Recipe_Map.sMappings){ - GregtechMachine mach = new GregtechMachine(); + Machine mach = new Machine(GT_LanguageManager.getTranslation(map.mUnlocalizedName)); // machine name retrieval - mach.n = GT_LanguageManager.getTranslation(map.mUnlocalizedName); - if(mach.n == null || mach.n.isEmpty()){ - mach.n = map.mUnlocalizedName; + if(mach.name == null || mach.name.isEmpty()){ + mach.name = map.mUnlocalizedName; } for(GT_Recipe rec : map.mRecipeList){ @@ -148,22 +149,16 @@ private Object getGregtechRecipes(){ gtr.fO.add(fluid); } - mach.recs.add(gtr); + mach.recipes.add(gtr); } machines.add(mach); } - data.put("machines", machines); - - return data; + return new Mod("gregtech", machines); } - private Object getOreDictShapedRecipes(){ - Hashtable data = new Hashtable<>(); - - data.put("type", "shapedOre"); - - List retRecipes = new ArrayList<>(); + private Machine getOreDictShapedRecipes(){ + List retRecipes = new ArrayList<>(); List recipes = CraftingManager.getInstance().getRecipeList(); for(Object obj : recipes){ if(obj instanceof ShapedOreRecipe){ @@ -190,17 +185,12 @@ private Object getOreDictShapedRecipes(){ retRecipes.add(rec); } } - data.put("recipes", retRecipes); - return data; + return new Machine("shapedOre", retRecipes); } - private Object getOreDictShapelessRecipes(){ - HashMap data = new HashMap<>(); - - data.put("type", "shapelessOre"); - - List retRecipes = new ArrayList<>(); + private Machine getOreDictShapelessRecipes(){ + List retRecipes = new ArrayList<>(); List recipes = CraftingManager.getInstance().getRecipeList(); for(Object obj : recipes){ if(obj instanceof ShapelessOreRecipe){ @@ -227,9 +217,8 @@ private Object getOreDictShapelessRecipes(){ retRecipes.add(rec); } } - data.put("recipes", retRecipes); - return data; + return new Machine("shapelessOre", retRecipes); } private List getOreDictNames(ItemStack itemStack){ @@ -241,19 +230,14 @@ private List getOreDictNames(ItemStack itemStack){ return names; } - private Object getReplacements(){ - HashMap data = new HashMap<>(); - - data.put("type", "replacements"); - - List oreDictItems = new ArrayList<>(); + private ItemList getReplacements(){ + List oreDictItems = new ArrayList<>(); String[] oreNames = OreDictionary.getOreNames(); for(String name : oreNames){ oreDictItems.add(new OreDictItem(name, getReplacements(name))); } - data.put("items", oreDictItems); - return data; + return new ItemList("replacements", oreDictItems); } private List getReplacements(String name){ @@ -266,12 +250,8 @@ private List getReplacements(String name){ return new ArrayList<>(replacements); } - private Object getShapedRecipes(){ - Hashtable data = new Hashtable(); - - data.put("type", "shaped"); - - List retRecipes = new ArrayList(); + private Machine getShapedRecipes(){ + List retRecipes = new ArrayList<>(); List recipes = CraftingManager.getInstance().getRecipeList(); for(Object obj : recipes){ if(obj instanceof ShapedRecipes){ @@ -288,17 +268,12 @@ private Object getShapedRecipes(){ retRecipes.add(rec); } } - data.put("recipes", retRecipes); - return data; + return new Machine("shaped", retRecipes); } - private Object getShapelessRecipes(){ - Hashtable data = new Hashtable(); - - data.put("type", "shapeless"); - - List retRecipes = new ArrayList(); + private Machine getShapelessRecipes(){ + List retRecipes = new ArrayList<>(); List recipes = CraftingManager.getInstance().getRecipeList(); for(Object obj : recipes){ if(obj instanceof ShapelessRecipes){ @@ -321,9 +296,8 @@ private Object getShapelessRecipes(){ retRecipes.add(rec); } } - data.put("recipes", retRecipes); - return data; + return new Machine("shapeless", retRecipes); } private void saveData(String json){ diff --git a/src/main/java/com/bigbass/recex/recipes/ShapedRecipe.java b/src/main/java/com/bigbass/recex/recipes/ShapedRecipe.java index 6a7ce87..12fbc78 100644 --- a/src/main/java/com/bigbass/recex/recipes/ShapedRecipe.java +++ b/src/main/java/com/bigbass/recex/recipes/ShapedRecipe.java @@ -3,7 +3,7 @@ import java.util.ArrayList; import java.util.List; -public class ShapedRecipe { +public class ShapedRecipe implements Recipe { /** input items */ public List iI; diff --git a/src/main/java/com/bigbass/recex/recipes/ShapelessRecipe.java b/src/main/java/com/bigbass/recex/recipes/ShapelessRecipe.java index 5e73d39..be5907e 100644 --- a/src/main/java/com/bigbass/recex/recipes/ShapelessRecipe.java +++ b/src/main/java/com/bigbass/recex/recipes/ShapelessRecipe.java @@ -3,7 +3,7 @@ import java.util.ArrayList; import java.util.List; -public class ShapelessRecipe { +public class ShapelessRecipe implements Recipe { /** input items */ public List iI; diff --git a/src/main/java/com/bigbass/recex/recipes/gregtech/GregtechMachine.java b/src/main/java/com/bigbass/recex/recipes/gregtech/GregtechMachine.java deleted file mode 100644 index 2ba3103..0000000 --- a/src/main/java/com/bigbass/recex/recipes/gregtech/GregtechMachine.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.bigbass.recex.recipes.gregtech; - -import java.util.ArrayList; -import java.util.List; - -public class GregtechMachine { - - /** machine name */ - public String n; - /** recipes */ - public List recs; - - public GregtechMachine(){ - recs = new ArrayList(); - } -} diff --git a/src/main/java/com/bigbass/recex/recipes/gregtech/GregtechRecipe.java b/src/main/java/com/bigbass/recex/recipes/gregtech/GregtechRecipe.java index 49e7732..41f3561 100644 --- a/src/main/java/com/bigbass/recex/recipes/gregtech/GregtechRecipe.java +++ b/src/main/java/com/bigbass/recex/recipes/gregtech/GregtechRecipe.java @@ -1,12 +1,13 @@ package com.bigbass.recex.recipes.gregtech; -import java.util.ArrayList; -import java.util.List; - import com.bigbass.recex.recipes.Fluid; import com.bigbass.recex.recipes.Item; +import com.bigbass.recex.recipes.Recipe; + +import java.util.ArrayList; +import java.util.List; -public class GregtechRecipe { +public class GregtechRecipe implements Recipe { /** enabled */ public boolean en; diff --git a/src/main/java/com/bigbass/recex/recipes/serializers/ItemListSerializer.java b/src/main/java/com/bigbass/recex/recipes/serializers/ItemListSerializer.java new file mode 100644 index 0000000..ee5f8d5 --- /dev/null +++ b/src/main/java/com/bigbass/recex/recipes/serializers/ItemListSerializer.java @@ -0,0 +1,19 @@ +package com.bigbass.recex.recipes.serializers; + +import com.bigbass.recex.recipes.ItemList; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; + +public class ItemListSerializer implements JsonSerializer { + @Override + public JsonElement serialize(ItemList src, Type typeOfSrc, JsonSerializationContext context) { + JsonObject object = new JsonObject(); + object.add("type", context.serialize(src.type)); + object.add("items", context.serialize(src.itemList)); + return object; + } +} diff --git a/src/main/java/com/bigbass/recex/recipes/serializers/MachineSerializer.java b/src/main/java/com/bigbass/recex/recipes/serializers/MachineSerializer.java new file mode 100644 index 0000000..bfc4a2b --- /dev/null +++ b/src/main/java/com/bigbass/recex/recipes/serializers/MachineSerializer.java @@ -0,0 +1,19 @@ +package com.bigbass.recex.recipes.serializers; + +import com.bigbass.recex.recipes.Machine; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; + +public class MachineSerializer implements JsonSerializer { + @Override + public JsonElement serialize(Machine src, Type typeOfSrc, JsonSerializationContext context) { + JsonObject object = new JsonObject(); + object.add("n", context.serialize(src.name)); + object.add("recs", context.serialize(src.recipes)); + return object; + } +} diff --git a/src/main/java/com/bigbass/recex/recipes/serializers/ModSerializer.java b/src/main/java/com/bigbass/recex/recipes/serializers/ModSerializer.java new file mode 100644 index 0000000..17ee891 --- /dev/null +++ b/src/main/java/com/bigbass/recex/recipes/serializers/ModSerializer.java @@ -0,0 +1,19 @@ +package com.bigbass.recex.recipes.serializers; + +import com.bigbass.recex.recipes.Mod; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; + +public class ModSerializer implements JsonSerializer { + @Override + public JsonElement serialize(Mod src, Type typeOfSrc, JsonSerializationContext context) { + JsonObject object = new JsonObject(); + object.add("type", context.serialize(src.modName)); + object.add("machines", context.serialize(src.machines)); + return object; + } +} From 2fb2596d327254349899d21bff45cd5812a0f846 Mon Sep 17 00:00:00 2001 From: wlghdu97 Date: Thu, 7 May 2020 03:39:57 +0900 Subject: [PATCH 03/14] Add forestry recipe exporter --- .../bigbass/recex/recipes/ItemMetaData.java | 10 + .../com/bigbass/recex/recipes/ItemRandom.java | 10 + .../bigbass/recex/recipes/RecipeExporter.java | 2 + .../exporters/ForestryRecipeExporter.java | 267 ++++++++++++++++++ .../recex/recipes/forestry/RfRecipe.java | 25 ++ .../recex/recipes/gregtech/RecipeUtil.java | 18 ++ 6 files changed, 332 insertions(+) create mode 100644 src/main/java/com/bigbass/recex/recipes/ItemMetaData.java create mode 100644 src/main/java/com/bigbass/recex/recipes/ItemRandom.java create mode 100644 src/main/java/com/bigbass/recex/recipes/exporters/ForestryRecipeExporter.java create mode 100644 src/main/java/com/bigbass/recex/recipes/forestry/RfRecipe.java diff --git a/src/main/java/com/bigbass/recex/recipes/ItemMetaData.java b/src/main/java/com/bigbass/recex/recipes/ItemMetaData.java new file mode 100644 index 0000000..7737e5e --- /dev/null +++ b/src/main/java/com/bigbass/recex/recipes/ItemMetaData.java @@ -0,0 +1,10 @@ +package com.bigbass.recex.recipes; + +public class ItemMetaData extends Item { + public String meta; + + public ItemMetaData(Item item, String metaData) { + super(item.a, item.uN, item.lN); + this.meta = metaData; + } +} diff --git a/src/main/java/com/bigbass/recex/recipes/ItemRandom.java b/src/main/java/com/bigbass/recex/recipes/ItemRandom.java new file mode 100644 index 0000000..15e96b5 --- /dev/null +++ b/src/main/java/com/bigbass/recex/recipes/ItemRandom.java @@ -0,0 +1,10 @@ +package com.bigbass.recex.recipes; + +public class ItemRandom extends Item { + public float percentage; + + public ItemRandom(Item item, float percentage) { + super(item.a, item.uN, item.lN); + this.percentage = percentage; + } +} diff --git a/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java b/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java index 34b4031..a949110 100644 --- a/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java +++ b/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java @@ -1,6 +1,7 @@ package com.bigbass.recex.recipes; import com.bigbass.recex.RecipeExporterMod; +import com.bigbass.recex.recipes.exporters.ForestryRecipeExporter; import com.bigbass.recex.recipes.gregtech.GregtechRecipe; import com.bigbass.recex.recipes.gregtech.RecipeUtil; import com.bigbass.recex.recipes.serializers.ItemListSerializer; @@ -60,6 +61,7 @@ public void run(){ List sources = new ArrayList(); sources.add(getGregtechRecipes()); + sources.add(new ForestryRecipeExporter().getForestryRecipes()); sources.add(getShapedRecipes()); sources.add(getShapelessRecipes()); sources.add(getOreDictShapedRecipes()); diff --git a/src/main/java/com/bigbass/recex/recipes/exporters/ForestryRecipeExporter.java b/src/main/java/com/bigbass/recex/recipes/exporters/ForestryRecipeExporter.java new file mode 100644 index 0000000..e48508d --- /dev/null +++ b/src/main/java/com/bigbass/recex/recipes/exporters/ForestryRecipeExporter.java @@ -0,0 +1,267 @@ +package com.bigbass.recex.recipes.exporters; + +import com.bigbass.recex.recipes.*; +import com.bigbass.recex.recipes.forestry.RfRecipe; +import com.bigbass.recex.recipes.gregtech.RecipeUtil; +import forestry.api.fuels.FermenterFuel; +import forestry.api.fuels.FuelManager; +import forestry.api.recipes.*; +import forestry.energy.EnergyManager; +import net.minecraft.item.ItemStack; +import net.minecraft.util.StatCollector; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class ForestryRecipeExporter { + + public Mod getForestryRecipes() { + List machines = new ArrayList<>(); + machines.add(getCarpenterRecipes()); + machines.add(getCentrifugeRecipes()); + machines.add(getFermenterRecipes()); + machines.add(getMoistenerRecipes()); + machines.add(getSqueezerRecipes()); + machines.add(getStillRecipes()); + machines.add(getFabricatorRecipes()); + return new Mod("forestry", machines); + } + + private Machine getCarpenterRecipes() { + Machine machine = new Machine(StatCollector.translateToLocal("tile.for.factory.1.name")); + + for (ICarpenterRecipe recipe : RecipeManagers.carpenterManager.recipes()) { + RfRecipe rfRecipe = new RfRecipe(); + rfRecipe.en = true; + rfRecipe.dur = recipe.getPackagingTime(); + rfRecipe.rft = EnergyManager.scaleForDifficulty(2040 / 10) / 4; + + for (Object ingredient : recipe.getCraftingGridRecipe().getIngredients()) { + if (ingredient instanceof ItemStack) { + rfRecipe.iI.add(RecipeUtil.formatRegularItemStack((ItemStack) ingredient)); + } else if (ingredient instanceof ItemStack[]) { + for (ItemStack stack : (ItemStack[]) ingredient) { + rfRecipe.iI.add(RecipeUtil.formatRegularItemStack(stack)); + } + } else if (ingredient instanceof List) { + for (ItemStack stack : (List) ingredient) { + rfRecipe.iI.add(RecipeUtil.formatRegularItemStack(stack)); + } + } + } + + if (recipe.getBox() != null) { + rfRecipe.iI.add(RecipeUtil.formatRegularItemStack(recipe.getBox())); + } + + if (recipe.getFluidResource() != null) { + rfRecipe.fI.add(RecipeUtil.formatRegularFluidStack(recipe.getFluidResource())); + } + + ItemStack output = recipe.getCraftingGridRecipe().getRecipeOutput(); + if (output != null) { + rfRecipe.iO.add(RecipeUtil.formatRegularItemStack(output)); + } + + machine.recipes.add(rfRecipe); + } + + return machine; + } + + private Machine getCentrifugeRecipes() { + Machine machine = new Machine(StatCollector.translateToLocal("tile.for.factory.2.name")); + + for (ICentrifugeRecipe recipe : RecipeManagers.centrifugeManager.recipes()) { + RfRecipe rfRecipe = new RfRecipe(); + rfRecipe.en = true; + rfRecipe.dur = recipe.getProcessingTime(); + rfRecipe.rft = EnergyManager.scaleForDifficulty(3200 / 20) / 4; + + ItemStack input = recipe.getInput(); + if (input != null) { + rfRecipe.iI.add(RecipeUtil.formatRegularItemStack(input)); + } + + for (Map.Entry output : recipe.getAllProducts().entrySet()) { + if (output != null && output.getKey() != null) { + Item item = RecipeUtil.formatRegularItemStack(output.getKey()); + ItemRandom itemRandom = new ItemRandom(item, output.getValue()); + rfRecipe.iO.add(itemRandom); + } + } + + machine.recipes.add(rfRecipe); + } + + return machine; + } + + private Machine getFermenterRecipes() { + Machine machine = new Machine(StatCollector.translateToLocal("tile.for.factory.3.name")); + + for (Map.Entry entry : FuelManager.fermenterFuel.entrySet()) { + int fermentPerCycle = entry.getValue().fermentPerCycle; + + Item fuelItem = RecipeUtil.formatGregtechItemStack(entry.getKey()); + ItemMetaData fuel = null; + if (fuelItem != null) { + fuel = new ItemMetaData(fuelItem, "catalyst"); + } + + for (IFermenterRecipe recipe : RecipeManagers.fermenterManager.recipes()) { + int extractionDuration = (int) Math.ceil((double) recipe.getFermentationValue() / fermentPerCycle); + + RfRecipe rfRecipe = new RfRecipe(); + rfRecipe.en = true; + rfRecipe.dur = 20 + (extractionDuration * 5); + rfRecipe.rft = EnergyManager.scaleForDifficulty(4200) / 4; + + if (fuel != null) { + rfRecipe.iI.add(fuel); + } + + ItemStack input = recipe.getResource(); + if (input != null) { + rfRecipe.iI.add(RecipeUtil.formatRegularItemStack(input)); + } + + FluidStack fluidInput = recipe.getFluidResource(); + if (fluidInput != null) { + fluidInput.amount = fermentPerCycle * extractionDuration; + rfRecipe.fI.add(RecipeUtil.formatRegularFluidStack(fluidInput)); + } + + if (recipe.getOutput() != null) { + int amount = Math.round(recipe.getFermentationValue() * recipe.getModifier()); + Fluid output = RecipeUtil.formatRegularFluidStack(new FluidStack(recipe.getOutput(), amount)); + rfRecipe.fO.add(output); + } + + machine.recipes.add(rfRecipe); + } + } + + return machine; + } + + private Machine getMoistenerRecipes() { + Machine machine = new Machine(StatCollector.translateToLocal("tile.for.factory.4.name")); + + for (IMoistenerRecipe recipe : RecipeManagers.moistenerManager.recipes()) { + RfRecipe rfRecipe = new RfRecipe(); + rfRecipe.en = true; + rfRecipe.dur = recipe.getTimePerItem() / 4; // assume full efficiency + rfRecipe.rft = 0; + + ItemStack input = recipe.getResource(); + if (input != null) { + rfRecipe.iI.add(RecipeUtil.formatRegularItemStack(input)); + } + + rfRecipe.fI.add(RecipeUtil.formatRegularFluidStack(new FluidStack(FluidRegistry.WATER, rfRecipe.dur))); + + ItemStack output = recipe.getProduct(); + if (output != null) { + rfRecipe.iO.add(RecipeUtil.formatRegularItemStack(output)); + } + + machine.recipes.add(rfRecipe); + } + + return machine; + } + + private Machine getSqueezerRecipes() { + Machine machine = new Machine(StatCollector.translateToLocal("tile.for.factory.5.name")); + + for (ISqueezerRecipe recipe : RecipeManagers.squeezerManager.recipes()) { + RfRecipe rfRecipe = new RfRecipe(); + rfRecipe.en = true; + rfRecipe.dur = recipe.getProcessingTime(); + rfRecipe.rft = EnergyManager.scaleForDifficulty(1100 / 10) / 4; + + for (ItemStack input : recipe.getResources()) { + if (input != null) { + rfRecipe.iI.add(RecipeUtil.formatRegularItemStack(input)); + } + } + + if (recipe.getRemnants() != null) { + Item item = RecipeUtil.formatRegularItemStack(recipe.getRemnants()); + rfRecipe.iO.add(new ItemRandom(item, recipe.getRemnantsChance())); + } + + if (recipe.getFluidOutput() != null) { + rfRecipe.fO.add(RecipeUtil.formatRegularFluidStack(recipe.getFluidOutput())); + } + + machine.recipes.add(rfRecipe); + } + + return machine; + } + + private Machine getStillRecipes() { + Machine machine = new Machine(StatCollector.translateToLocal("tile.for.factory.6.name")); + + for (IStillRecipe recipe : RecipeManagers.stillManager.recipes()) { + RfRecipe rfRecipe = new RfRecipe(); + rfRecipe.en = true; + rfRecipe.dur = recipe.getCyclesPerUnit(); + rfRecipe.rft = EnergyManager.scaleForDifficulty(200) / 4; + + if (recipe.getInput() != null) { + rfRecipe.fI.add(RecipeUtil.formatRegularFluidStack(recipe.getInput())); + } + + if (recipe.getOutput() != null) { + rfRecipe.fO.add(RecipeUtil.formatRegularFluidStack(recipe.getOutput())); + } + + machine.recipes.add(rfRecipe); + } + + return machine; + } + + private Machine getFabricatorRecipes() { + Machine machine = new Machine(StatCollector.translateToLocal("tile.for.factory2.0.name")); + + for (IFabricatorRecipe recipe : RecipeManagers.fabricatorManager.recipes()) { + RfRecipe rfRecipe = new RfRecipe(); + rfRecipe.en = true; + rfRecipe.dur = 5; + rfRecipe.rft = EnergyManager.scaleForDifficulty(200) / 4; + + for (Object ingredient : recipe.getIngredients()) { + if (ingredient instanceof ItemStack) { + rfRecipe.iI.add(RecipeUtil.formatRegularItemStack((ItemStack) ingredient)); + } else if (ingredient instanceof ItemStack[]) { + for (ItemStack stack : (ItemStack[]) ingredient) { + rfRecipe.iI.add(RecipeUtil.formatRegularItemStack(stack)); + } + } else if (ingredient instanceof List) { + for (ItemStack stack : (List) ingredient) { + rfRecipe.iI.add(RecipeUtil.formatRegularItemStack(stack)); + } + } + } + + if (recipe.getLiquid() != null) { + rfRecipe.fI.add(RecipeUtil.formatRegularFluidStack(recipe.getLiquid())); + } + + if (recipe.getRecipeOutput() != null) { + rfRecipe.iO.add(RecipeUtil.formatRegularItemStack(recipe.getRecipeOutput())); + } + + machine.recipes.add(rfRecipe); + } + + return machine; + } +} diff --git a/src/main/java/com/bigbass/recex/recipes/forestry/RfRecipe.java b/src/main/java/com/bigbass/recex/recipes/forestry/RfRecipe.java new file mode 100644 index 0000000..54ce2d1 --- /dev/null +++ b/src/main/java/com/bigbass/recex/recipes/forestry/RfRecipe.java @@ -0,0 +1,25 @@ +package com.bigbass.recex.recipes.forestry; + +import com.bigbass.recex.recipes.Fluid; +import com.bigbass.recex.recipes.Item; +import com.bigbass.recex.recipes.Recipe; + +import java.util.ArrayList; +import java.util.List; + +public class RfRecipe implements Recipe { + public boolean en; + public int dur; + public int rft; + public List iI; + public List iO; + public List fI; + public List fO; + + public RfRecipe() { + iI = new ArrayList<>(); + iO = new ArrayList<>(); + fI = new ArrayList<>(); + fO = new ArrayList<>(); + } +} diff --git a/src/main/java/com/bigbass/recex/recipes/gregtech/RecipeUtil.java b/src/main/java/com/bigbass/recex/recipes/gregtech/RecipeUtil.java index 04cc2cc..adbda95 100644 --- a/src/main/java/com/bigbass/recex/recipes/gregtech/RecipeUtil.java +++ b/src/main/java/com/bigbass/recex/recipes/gregtech/RecipeUtil.java @@ -27,6 +27,24 @@ public static Item formatRegularItemStack(ItemStack stack){ return item; } + + public static Fluid formatRegularFluidStack(FluidStack stack) { + if (stack == null) { + return null; + } + + Fluid fluid = new Fluid(); + + fluid.a = stack.amount; + try { + fluid.uN = stack.getUnlocalizedName(); + } catch (Exception e) {} + try { + fluid.lN = stack.getLocalizedName(); + } catch (Exception e) {} + + return fluid; + } public static Item formatGregtechItemStack(ItemStack stack){ if(stack == null){ From eebe7f4e651ede72aa13ab8228673546171de33b Mon Sep 17 00:00:00 2001 From: wlghdu97 Date: Tue, 26 May 2020 00:19:40 +0900 Subject: [PATCH 04/14] Add item icon export squash --- .../bigbass/recex/recipes/RecipeExporter.java | 5 + .../recex/recipes/gregtech/RecipeUtil.java | 12 +- .../recex/recipes/renderer/IconRenderer.java | 462 ++++++++++++++++++ 3 files changed, 475 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java diff --git a/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java b/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java index a949110..91a2a1a 100644 --- a/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java +++ b/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java @@ -4,6 +4,7 @@ import com.bigbass.recex.recipes.exporters.ForestryRecipeExporter; import com.bigbass.recex.recipes.gregtech.GregtechRecipe; import com.bigbass.recex.recipes.gregtech.RecipeUtil; +import com.bigbass.recex.recipes.renderer.IconRenderer; import com.bigbass.recex.recipes.serializers.ItemListSerializer; import com.bigbass.recex.recipes.serializers.MachineSerializer; import com.bigbass.recex.recipes.serializers.ModSerializer; @@ -58,6 +59,8 @@ public static RecipeExporter getInst(){ */ public void run(){ Hashtable root = new Hashtable(); + + IconRenderer.getInstance().init(); List sources = new ArrayList(); sources.add(getGregtechRecipes()); @@ -68,6 +71,8 @@ public void run(){ sources.add(getOreDictShapelessRecipes()); sources.add(getReplacements()); + IconRenderer.getInstance().dispose(); + root.put("sources", sources); Gson gson = new GsonBuilder() diff --git a/src/main/java/com/bigbass/recex/recipes/gregtech/RecipeUtil.java b/src/main/java/com/bigbass/recex/recipes/gregtech/RecipeUtil.java index adbda95..5f60c59 100644 --- a/src/main/java/com/bigbass/recex/recipes/gregtech/RecipeUtil.java +++ b/src/main/java/com/bigbass/recex/recipes/gregtech/RecipeUtil.java @@ -3,7 +3,7 @@ import com.bigbass.recex.recipes.Fluid; import com.bigbass.recex.recipes.Item; import com.bigbass.recex.recipes.ItemProgrammedCircuit; - +import com.bigbass.recex.recipes.renderer.IconRenderer; import gregtech.api.util.GT_LanguageManager; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; @@ -24,7 +24,8 @@ public static Item formatRegularItemStack(ItemStack stack){ try { item.lN = stack.getDisplayName(); } catch(Exception e){} - + + IconRenderer.getInstance().printItemStack(stack, item.uN); return item; } @@ -43,6 +44,7 @@ public static Fluid formatRegularFluidStack(FluidStack stack) { fluid.lN = stack.getLocalizedName(); } catch (Exception e) {} + IconRenderer.getInstance().printFluidStack(stack, fluid.uN); return fluid; } @@ -68,7 +70,8 @@ public static Item formatGregtechItemStack(ItemStack stack){ if(item.uN != null && !item.uN.isEmpty() && item.uN.equalsIgnoreCase("gt.integrated_circuit")){ // Programmed Circuit item = new ItemProgrammedCircuit(item, stack.getItemDamage()); } - + + IconRenderer.getInstance().printItemStack(stack, item.uN); return item; } @@ -94,7 +97,8 @@ public static Fluid formatGregtechFluidStack(FluidStack stack){ } catch(Exception e3){} } } - + + IconRenderer.getInstance().printFluidStack(stack, fluid.uN); return fluid; } } diff --git a/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java b/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java new file mode 100644 index 0000000..8e48682 --- /dev/null +++ b/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java @@ -0,0 +1,462 @@ +package com.bigbass.recex.recipes.renderer; + +import ar.com.hjg.pngj.ImageInfo; +import ar.com.hjg.pngj.ImageLineHelper; +import ar.com.hjg.pngj.ImageLineInt; +import ar.com.hjg.pngj.PngWriter; +import com.bigbass.recex.RecipeExporterMod; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.IItemRenderer; +import net.minecraftforge.client.MinecraftForgeClient; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.oredict.OreDictionary; +import org.lwjgl.BufferUtils; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL30; + +import java.io.File; +import java.io.IOException; +import java.nio.ByteBuffer; + +import static net.minecraftforge.client.IItemRenderer.ItemRenderType.INVENTORY; +import static net.minecraftforge.client.IItemRenderer.ItemRendererHelper.INVENTORY_BLOCK; + +public class IconRenderer { + private static IconRenderer INSTANCE; + + public static IconRenderer getInstance() { + if (INSTANCE == null) { + INSTANCE = new IconRenderer(); + } + return INSTANCE; + } + + private int width = 64, height = 64; + + private int frameBufferObject; + private int renderBufferObject; + private int depthBufferObject; + + private boolean bufferInitialized = false; + + public void init() { + frameBufferObject = GL30.glGenFramebuffers(); + GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferObject); + + renderBufferObject = GL30.glGenRenderbuffers(); + GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, renderBufferObject); + GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL11.GL_RGBA8, width, height); + GL30.glFramebufferRenderbuffer(GL30.GL_DRAW_FRAMEBUFFER, GL30.GL_COLOR_ATTACHMENT0, GL30.GL_RENDERBUFFER, renderBufferObject); + + depthBufferObject = GL30.glGenRenderbuffers(); + GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, depthBufferObject); + GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL30.GL_DEPTH_COMPONENT32F, width, height); + GL30.glFramebufferRenderbuffer(GL30.GL_DRAW_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, depthBufferObject); + + if (GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) == GL30.GL_FRAMEBUFFER_COMPLETE) { + bufferInitialized = true; + } else { + throw new RuntimeException("failed to create frame buffer."); + } + // reset binding + GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); + } + + public void printItemStack(ItemStack itemStack, String unlocalizedName) { + checkFrameBuffer(); + File output = getPngFile(unlocalizedName); + if (output == null) return; + before(); + + // draw icon + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glEnable(GL11.GL_ALPHA_TEST); + TextureManager textureManager = Minecraft.getMinecraft().getTextureManager(); + renderItemAndEffectIntoGUI(textureManager, itemStack); + GL11.glDisable(GL11.GL_ALPHA_TEST); + GL11.glDisable(GL11.GL_DEPTH_TEST); + + printPng(output); + after(); + } + + public void printFluidStack(FluidStack fluidStack, String unlocalizedName) { + checkFrameBuffer(); + File output = getPngFile(unlocalizedName); + if (output == null) return; + before(); + + // draw icon + renderFluidIcon(fluidStack); + + printPng(output); + after(); + } + + private void checkFrameBuffer() { + if (!bufferInitialized) { + throw new RuntimeException("frame buffer not initialized."); + } + } + + private File getPngFile(String unlocalizedName) { + File output = new File(RecipeExporterMod.clientConfigDir.getParent() + "/RecEx-Icons/" + unlocalizedName + ".png"); + try { + if(!output.exists()){ + boolean result = output.getParentFile().mkdirs(); + if (!result) { + throw new IOException("failed to create icon folder."); + } + } + if (output.exists()) { + return null; + } + } catch (IOException e) { + e.printStackTrace(); + } + return output; + } + + private void before() { + GL11.glPushMatrix(); + + GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBufferObject); + GL11.glPushAttrib(GL11.GL_VIEWPORT_BIT); + GL11.glViewport(0, 0, width, height); + + GL11.glMatrixMode(GL11.GL_PROJECTION); + GL11.glLoadIdentity(); + GL11.glOrtho(0d, 16f, 16f, 0d, -1000d, 3000d); + + GL11.glMatrixMode(GL11.GL_MODELVIEW); + GL11.glLoadIdentity(); + + GL11.glClearColor(0f, 0f, 0f, 0f); + GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); + } + + private void after() { + GL11.glPopAttrib(); + GL11.glPopMatrix(); + GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); + } + + private void printPng(File output) { + ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * 4); + + GL11.glReadBuffer(GL30.GL_COLOR_ATTACHMENT0); + GL11.glReadPixels(0, 0, width, height, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); + + int[][][] pixels = new int[width][height][4]; + for (int h = 0; h < height; h++) { + for (int w = 0; w < width; w++) { + pixels[height - h - 1][w][0] = (buffer.get()) & 0xff; + pixels[height - h - 1][w][1] = (buffer.get()) & 0xff; + pixels[height - h - 1][w][2] = (buffer.get()) & 0xff; + pixels[height - h - 1][w][3] = (buffer.get()) & 0xff; + } + } + + ImageInfo info = new ImageInfo(width, height, 8, true); + try { + PngWriter pngWriter = new PngWriter(output, info); + ImageLineInt iLine = new ImageLineInt(info); + for (int row = 0; row < info.rows; row++) { + for (int col = 0; col < info.cols; col++) { + int r = pixels[row][col][0]; + int g = pixels[row][col][1]; + int b = pixels[row][col][2]; + int a = pixels[row][col][3]; + ImageLineHelper.setPixelRGBA8(iLine, col, r, g, b, a); + } + pngWriter.writeRow(iLine); + } + pngWriter.end(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void enableGUIStandardItemLighting() { + GL11.glPushMatrix(); + GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); + RenderHelper.enableStandardItemLighting(); + GL11.glPopMatrix(); + } + + private RenderBlocks renderBlocks = RenderBlocks.getInstance(); + private boolean renderWithColor = true; + private float zLevel = 0f; + + // Original source : RenderItem + private void renderItemAndEffectIntoGUI(TextureManager textureManager, final ItemStack itemStack) { + if (!renderInventoryItem(renderBlocks, textureManager, itemStack, renderWithColor, zLevel)) { + renderItemIntoGUI(textureManager, itemStack); + } + } + + // Original source : ForgeHooksClient + private boolean renderInventoryItem(RenderBlocks renderBlocks, TextureManager engine, ItemStack item, boolean inColor, float zLevel) { + float x = 0f, y = 0f; + + if (item.getItemDamage() == OreDictionary.WILDCARD_VALUE) { + item.setItemDamage(0); + } + + IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(item, INVENTORY); + if (customRenderer == null) { + return false; + } + + engine.bindTexture(item.getItemSpriteNumber() == 0 ? TextureMap.locationBlocksTexture : TextureMap.locationItemsTexture); + if (customRenderer.shouldUseRenderHelper(INVENTORY, item, INVENTORY_BLOCK)) { + GL11.glPushMatrix(); + GL11.glTranslatef(x - 2, y + 3, -3.0F + zLevel); + GL11.glScalef(10F, 10F, 10F); + GL11.glTranslatef(1.0F, 0.5F, 1.0F); + GL11.glScalef(1.0F, 1.0F, -1F); + GL11.glRotatef(210F, 1.0F, 0.0F, 0.0F); + GL11.glRotatef(45F, 0.0F, 1.0F, 0.0F); + + if(inColor) { + int color = item.getItem().getColorFromItemStack(item, 0); + float r = (float)(color >> 16 & 0xff) / 255F; + float g = (float)(color >> 8 & 0xff) / 255F; + float b = (float)(color & 0xff) / 255F; + GL11.glColor4f(r, g, b, 1.0F); + } + + RenderHelper.disableStandardItemLighting(); + enableGUIStandardItemLighting(); + GL11.glRotatef(-90F, 0.0F, 1.0F, 0.0F); + renderBlocks.useInventoryTint = inColor; + customRenderer.renderItem(INVENTORY, item, renderBlocks); + renderBlocks.useInventoryTint = true; + RenderHelper.enableStandardItemLighting(); + GL11.glPopMatrix(); + } else { + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glPushMatrix(); + GL11.glTranslatef(x, y, -3.0F + zLevel); + + if (inColor) { + int color = item.getItem().getColorFromItemStack(item, 0); + float r = (float)(color >> 16 & 255) / 255.0F; + float g = (float)(color >> 8 & 255) / 255.0F; + float b = (float)(color & 255) / 255.0F; + GL11.glColor4f(r, g, b, 1.0F); + } + + customRenderer.renderItem(INVENTORY, item, renderBlocks); + GL11.glPopMatrix(); + GL11.glEnable(GL11.GL_LIGHTING); + } + + return true; + } + + // Original source : RenderItem + private void renderItemIntoGUI(TextureManager textureManager, ItemStack itemStack) { + int x = 0, y = 0; + + int itemDamage = itemStack.getItemDamage(); + if (itemDamage == OreDictionary.WILDCARD_VALUE) { + itemStack.setItemDamage(0); + itemDamage = 0; + } + + IIcon iconIndex = itemStack.getIconIndex(); + int itemStackColor; + + // render block + if (itemStack.getItemSpriteNumber() == 0 && RenderBlocks.renderItemIn3d(Block.getBlockFromItem(itemStack.getItem()).getRenderType())) { + textureManager.bindTexture(TextureMap.locationBlocksTexture); + Block block = Block.getBlockFromItem(itemStack.getItem()); + GL11.glEnable(GL11.GL_ALPHA_TEST); + + if (block.getRenderBlockPass() != 0) { + GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F); + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + } else { + GL11.glAlphaFunc(GL11.GL_GREATER, 0.5F); + GL11.glDisable(GL11.GL_BLEND); + } + + GL11.glPushMatrix(); + GL11.glTranslatef((float)(x - 2), (float)(y + 3), -3.0F + zLevel); + GL11.glScalef(10.0F, 10.0F, 10.0F); + GL11.glTranslatef(1.0F, 0.5F, 1.0F); + GL11.glScalef(1.0F, 1.0F, -1.0F); + GL11.glRotatef(210.0F, 1.0F, 0.0F, 0.0F); + GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F); + itemStackColor = itemStack.getItem().getColorFromItemStack(itemStack, 0); + float r = (float)(itemStackColor >> 16 & 255) / 255.0F; + float g = (float)(itemStackColor >> 8 & 255) / 255.0F; + float b = (float)(itemStackColor & 255) / 255.0F; + + if (this.renderWithColor) { + GL11.glColor4f(r, g, b, 1.0F); + } + + RenderHelper.disableStandardItemLighting(); + enableGUIStandardItemLighting(); + GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F); + renderBlocks.useInventoryTint = this.renderWithColor; + renderBlocks.renderBlockAsItem(block, itemDamage, 1.0F); + renderBlocks.useInventoryTint = true; + RenderHelper.enableStandardItemLighting(); + + if (block.getRenderBlockPass() == 0) { + GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F); + } + + GL11.glPopMatrix(); + } else if (itemStack.getItem().requiresMultipleRenderPasses()) { + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_ALPHA_TEST); + textureManager.bindTexture(TextureMap.locationItemsTexture); + GL11.glDisable(GL11.GL_ALPHA_TEST); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(0, 0, 0, 0); + GL11.glColorMask(false, false, false, true); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.setColorOpaque_I(-1); + tessellator.addVertex((x - 2), (y + 18), zLevel); + tessellator.addVertex((x + 18), (y + 18), zLevel); + tessellator.addVertex((x + 18), (y - 2), zLevel); + tessellator.addVertex((x - 2), (y - 2), zLevel); + tessellator.draw(); + GL11.glColorMask(true, true, true, true); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glEnable(GL11.GL_ALPHA_TEST); + + Item item = itemStack.getItem(); + for (itemStackColor = 0; itemStackColor < item.getRenderPasses(itemDamage); ++itemStackColor) { + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + textureManager.bindTexture(item.getSpriteNumber() == 0 ? TextureMap.locationBlocksTexture : TextureMap.locationItemsTexture); + IIcon iicon = item.getIcon(itemStack, itemStackColor); + int i1 = itemStack.getItem().getColorFromItemStack(itemStack, itemStackColor); + float r = (float)(i1 >> 16 & 255) / 255.0F; + float g = (float)(i1 >> 8 & 255) / 255.0F; + float b = (float)(i1 & 255) / 255.0F; + + if (this.renderWithColor) { + GL11.glColor4f(r, g, b, 1.0F); + } + + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_ALPHA_TEST); + + this.renderIcon(x, y, iicon); + + GL11.glDisable(GL11.GL_ALPHA_TEST); + GL11.glEnable(GL11.GL_LIGHTING); + } + + GL11.glEnable(GL11.GL_LIGHTING); + } else { + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + ResourceLocation resourcelocation = textureManager.getResourceLocation(itemStack.getItemSpriteNumber()); + textureManager.bindTexture(resourcelocation); + + if (iconIndex == null) { + iconIndex = ((TextureMap)Minecraft.getMinecraft().getTextureManager().getTexture(resourcelocation)).getAtlasSprite("missingno"); + } + + itemStackColor = itemStack.getItem().getColorFromItemStack(itemStack, 0); + float r = (float)(itemStackColor >> 16 & 255) / 255.0F; + float g = (float)(itemStackColor >> 8 & 255) / 255.0F; + float b = (float)(itemStackColor & 255) / 255.0F; + + if (this.renderWithColor) { + GL11.glColor4f(r, g, b, 1.0F); + } + + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_ALPHA_TEST); + GL11.glEnable(GL11.GL_BLEND); + + this.renderIcon(x, y, iconIndex); + + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_ALPHA_TEST); + GL11.glDisable(GL11.GL_BLEND); + + GL11.glEnable(GL11.GL_LIGHTING); + } + + GL11.glEnable(GL11.GL_CULL_FACE); + } + + private void renderFluidIcon(FluidStack fluidStack) { + int x = 0, y = 0; + + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + TextureManager textureManager = Minecraft.getMinecraft().getTextureManager(); + ResourceLocation resourcelocation = textureManager.getResourceLocation(fluidStack.getFluid().getSpriteNumber()); + textureManager.bindTexture(resourcelocation); + + IIcon iconIndex = fluidStack.getFluid().getIcon(fluidStack); + if (iconIndex == null) { + iconIndex = ((TextureMap)Minecraft.getMinecraft().getTextureManager().getTexture(resourcelocation)).getAtlasSprite("missingno"); + } + + int fluidStackColor = fluidStack.getFluid().getColor(fluidStack); + float r = (float)(fluidStackColor >> 16 & 255) / 255.0F; + float g = (float)(fluidStackColor >> 8 & 255) / 255.0F; + float b = (float)(fluidStackColor & 255) / 255.0F; + + if (this.renderWithColor) { + GL11.glColor4f(r, g, b, 1.0F); + } + + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glEnable(GL11.GL_ALPHA_TEST); + GL11.glEnable(GL11.GL_BLEND); + + this.renderIcon(x, y, iconIndex); + + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glDisable(GL11.GL_ALPHA_TEST); + GL11.glDisable(GL11.GL_BLEND); + + GL11.glEnable(GL11.GL_LIGHTING); + } + + private void renderIcon(int x, int y, IIcon icon) { + int width = 16, height = 16; + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV(x, (y + height), zLevel, icon.getMinU(), icon.getMaxV()); + tessellator.addVertexWithUV((x + width), (y + height), zLevel, icon.getMaxU(), icon.getMaxV()); + tessellator.addVertexWithUV((x + width), y, zLevel, icon.getMaxU(), icon.getMinV()); + tessellator.addVertexWithUV(x, y, zLevel, icon.getMinU(), icon.getMinV()); + tessellator.draw(); + } + + public void dispose() { + bufferInitialized = false; + GL30.glDeleteFramebuffers(frameBufferObject); + GL30.glDeleteRenderbuffers(renderBufferObject); + GL30.glDeleteRenderbuffers(depthBufferObject); + } +} From 8eae83b792a9740b978117d3742d9e162f249218 Mon Sep 17 00:00:00 2001 From: wlghdu97 Date: Wed, 27 May 2020 23:35:17 +0900 Subject: [PATCH 05/14] Fix icon output name to be encoded with base 64 --- .../java/com/bigbass/recex/recipes/renderer/IconRenderer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java b/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java index 8e48682..8546a12 100644 --- a/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java +++ b/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java @@ -28,6 +28,7 @@ import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; +import java.util.Base64; import static net.minecraftforge.client.IItemRenderer.ItemRenderType.INVENTORY; import static net.minecraftforge.client.IItemRenderer.ItemRendererHelper.INVENTORY_BLOCK; @@ -111,7 +112,8 @@ private void checkFrameBuffer() { } private File getPngFile(String unlocalizedName) { - File output = new File(RecipeExporterMod.clientConfigDir.getParent() + "/RecEx-Icons/" + unlocalizedName + ".png"); + String encodedUnlocalizedName = Base64.getEncoder().encodeToString(unlocalizedName.getBytes()); + File output = new File(RecipeExporterMod.clientConfigDir.getParent() + "/RecEx-Icons/" + encodedUnlocalizedName + ".png"); try { if(!output.exists()){ boolean result = output.getParentFile().mkdirs(); From 92c54386f4c742384568a5789ce56f69a8fd18b4 Mon Sep 17 00:00:00 2001 From: wlghdu97 Date: Wed, 27 May 2020 23:35:30 +0900 Subject: [PATCH 06/14] Fix icon output mkdir issue --- .../com/bigbass/recex/recipes/renderer/IconRenderer.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java b/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java index 8546a12..c3ce5f9 100644 --- a/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java +++ b/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java @@ -112,10 +112,13 @@ private void checkFrameBuffer() { } private File getPngFile(String unlocalizedName) { + if (unlocalizedName == null || unlocalizedName.isEmpty()) { + return null; + } String encodedUnlocalizedName = Base64.getEncoder().encodeToString(unlocalizedName.getBytes()); File output = new File(RecipeExporterMod.clientConfigDir.getParent() + "/RecEx-Icons/" + encodedUnlocalizedName + ".png"); try { - if(!output.exists()){ + if(!output.getParentFile().exists()){ boolean result = output.getParentFile().mkdirs(); if (!result) { throw new IOException("failed to create icon folder."); From 4f9adc29fdd065ecd67dbcc5ef9e8eb6d05a5afe Mon Sep 17 00:00:00 2001 From: wlghdu97 Date: Wed, 27 May 2020 23:36:26 +0900 Subject: [PATCH 07/14] Change icon output to use original RenderHelper.enableGUIStandardItemLighting --- .../recex/recipes/renderer/IconRenderer.java | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java b/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java index c3ce5f9..bf7c601 100644 --- a/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java +++ b/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java @@ -81,12 +81,15 @@ public void printItemStack(ItemStack itemStack, String unlocalizedName) { before(); // draw icon + RenderHelper.disableStandardItemLighting(); + RenderHelper.enableGUIStandardItemLighting(); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glEnable(GL11.GL_ALPHA_TEST); TextureManager textureManager = Minecraft.getMinecraft().getTextureManager(); renderItemAndEffectIntoGUI(textureManager, itemStack); - GL11.glDisable(GL11.GL_ALPHA_TEST); GL11.glDisable(GL11.GL_DEPTH_TEST); + GL11.glDisable(GL11.GL_ALPHA_TEST); + RenderHelper.enableStandardItemLighting(); printPng(output); after(); @@ -193,13 +196,6 @@ private void printPng(File output) { } } - private void enableGUIStandardItemLighting() { - GL11.glPushMatrix(); - GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F); - RenderHelper.enableStandardItemLighting(); - GL11.glPopMatrix(); - } - private RenderBlocks renderBlocks = RenderBlocks.getInstance(); private boolean renderWithColor = true; private float zLevel = 0f; @@ -242,13 +238,10 @@ private boolean renderInventoryItem(RenderBlocks renderBlocks, TextureManager en GL11.glColor4f(r, g, b, 1.0F); } - RenderHelper.disableStandardItemLighting(); - enableGUIStandardItemLighting(); GL11.glRotatef(-90F, 0.0F, 1.0F, 0.0F); renderBlocks.useInventoryTint = inColor; customRenderer.renderItem(INVENTORY, item, renderBlocks); renderBlocks.useInventoryTint = true; - RenderHelper.enableStandardItemLighting(); GL11.glPopMatrix(); } else { GL11.glDisable(GL11.GL_LIGHTING); @@ -315,13 +308,10 @@ private void renderItemIntoGUI(TextureManager textureManager, ItemStack itemStac GL11.glColor4f(r, g, b, 1.0F); } - RenderHelper.disableStandardItemLighting(); - enableGUIStandardItemLighting(); GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F); renderBlocks.useInventoryTint = this.renderWithColor; renderBlocks.renderBlockAsItem(block, itemDamage, 1.0F); renderBlocks.useInventoryTint = true; - RenderHelper.enableStandardItemLighting(); if (block.getRenderBlockPass() == 0) { GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F); From 4ad16622386e232a004dc0271c9c2749c61f3921 Mon Sep 17 00:00:00 2001 From: wlghdu97 Date: Tue, 9 Jun 2020 16:52:17 +0900 Subject: [PATCH 08/14] Fix IconRenderer block renderer lighting issue --- .../com/bigbass/recex/recipes/renderer/IconRenderer.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java b/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java index bf7c601..40089ea 100644 --- a/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java +++ b/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java @@ -23,6 +23,7 @@ import net.minecraftforge.oredict.OreDictionary; import org.lwjgl.BufferUtils; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; import org.lwjgl.opengl.GL30; import java.io.File; @@ -85,10 +86,12 @@ public void printItemStack(ItemStack itemStack, String unlocalizedName) { RenderHelper.enableGUIStandardItemLighting(); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glEnable(GL11.GL_ALPHA_TEST); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); TextureManager textureManager = Minecraft.getMinecraft().getTextureManager(); renderItemAndEffectIntoGUI(textureManager, itemStack); - GL11.glDisable(GL11.GL_DEPTH_TEST); + GL11.glDisable(GL12.GL_RESCALE_NORMAL); GL11.glDisable(GL11.GL_ALPHA_TEST); + GL11.glDisable(GL11.GL_DEPTH_TEST); RenderHelper.enableStandardItemLighting(); printPng(output); From bddd75719b2da3b9504a7142461f0da4a32f0da6 Mon Sep 17 00:00:00 2001 From: wlghdu97 Date: Tue, 9 Jun 2020 18:49:16 +0900 Subject: [PATCH 09/14] Add gt++ recipe exporter --- .../bigbass/recex/recipes/RecipeExporter.java | 4 +- .../exporters/ForestryRecipeExporter.java | 5 +- .../recipes/exporters/GTPPRecipeExporter.java | 86 +++++++++++++++++++ .../recipes/exporters/RecipeExporter.java | 7 ++ 4 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/bigbass/recex/recipes/exporters/GTPPRecipeExporter.java create mode 100644 src/main/java/com/bigbass/recex/recipes/exporters/RecipeExporter.java diff --git a/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java b/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java index 91a2a1a..1b72617 100644 --- a/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java +++ b/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java @@ -2,6 +2,7 @@ import com.bigbass.recex.RecipeExporterMod; import com.bigbass.recex.recipes.exporters.ForestryRecipeExporter; +import com.bigbass.recex.recipes.exporters.GTPPRecipeExporter; import com.bigbass.recex.recipes.gregtech.GregtechRecipe; import com.bigbass.recex.recipes.gregtech.RecipeUtil; import com.bigbass.recex.recipes.renderer.IconRenderer; @@ -64,7 +65,8 @@ public void run(){ List sources = new ArrayList(); sources.add(getGregtechRecipes()); - sources.add(new ForestryRecipeExporter().getForestryRecipes()); + sources.add(new GTPPRecipeExporter().getRecipes()); + sources.add(new ForestryRecipeExporter().getRecipes()); sources.add(getShapedRecipes()); sources.add(getShapelessRecipes()); sources.add(getOreDictShapedRecipes()); diff --git a/src/main/java/com/bigbass/recex/recipes/exporters/ForestryRecipeExporter.java b/src/main/java/com/bigbass/recex/recipes/exporters/ForestryRecipeExporter.java index e48508d..4777326 100644 --- a/src/main/java/com/bigbass/recex/recipes/exporters/ForestryRecipeExporter.java +++ b/src/main/java/com/bigbass/recex/recipes/exporters/ForestryRecipeExporter.java @@ -16,9 +16,10 @@ import java.util.List; import java.util.Map; -public class ForestryRecipeExporter { +public class ForestryRecipeExporter implements RecipeExporter { - public Mod getForestryRecipes() { + @Override + public Mod getRecipes() { List machines = new ArrayList<>(); machines.add(getCarpenterRecipes()); machines.add(getCentrifugeRecipes()); diff --git a/src/main/java/com/bigbass/recex/recipes/exporters/GTPPRecipeExporter.java b/src/main/java/com/bigbass/recex/recipes/exporters/GTPPRecipeExporter.java new file mode 100644 index 0000000..b3ac970 --- /dev/null +++ b/src/main/java/com/bigbass/recex/recipes/exporters/GTPPRecipeExporter.java @@ -0,0 +1,86 @@ +package com.bigbass.recex.recipes.exporters; + +import com.bigbass.recex.recipes.Fluid; +import com.bigbass.recex.recipes.Item; +import com.bigbass.recex.recipes.Machine; +import com.bigbass.recex.recipes.Mod; +import com.bigbass.recex.recipes.gregtech.GregtechRecipe; +import com.bigbass.recex.recipes.gregtech.RecipeUtil; +import gregtech.api.util.GTPP_Recipe; +import gregtech.api.util.GT_LanguageManager; +import gregtech.api.util.GT_Recipe; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class GTPPRecipeExporter implements RecipeExporter { + + @Override + public Mod getRecipes() { + List machines = new ArrayList<>(); + for (GTPP_Recipe.GTPP_Recipe_Map map : GTPP_Recipe.GTPP_Recipe_Map.sMappings) { + machines.add(getMachine(map.mUnlocalizedName, map.mRecipeList)); + } + for (GTPP_Recipe.GTPP_Recipe_Map_Internal map : GTPP_Recipe.GTPP_Recipe_Map_Internal.sMappingsEx) { + machines.add(getMachine(map.mUnlocalizedName, map.mRecipeList)); + } + return new Mod("gregtech", machines); + } + + private Machine getMachine(String unlocalizedName, Collection recipeList) { + Machine machine = new Machine(GT_LanguageManager.getTranslation(unlocalizedName)); + + // machine name retrieval + if (machine.name == null || machine.name.isEmpty()) { + machine.name = unlocalizedName; + } + + for (GT_Recipe rec : recipeList) { + GregtechRecipe gtr = new GregtechRecipe(); + gtr.en = rec.mEnabled; + gtr.dur = rec.mDuration; + gtr.eut = rec.mEUt; + + // item inputs + for (ItemStack stack : rec.mInputs) { + Item item = RecipeUtil.formatGregtechItemStack(stack); + if (item == null) { + continue; + } + gtr.iI.add(item); + } + + // item outputs + for (ItemStack stack : rec.mOutputs) { + Item item = RecipeUtil.formatGregtechItemStack(stack); + if (item == null) { + continue; + } + gtr.iO.add(item); + } + + // fluid inputs + for (FluidStack stack : rec.mFluidInputs) { + Fluid fluid = RecipeUtil.formatGregtechFluidStack(stack); + if (fluid == null) { + continue; + } + gtr.fI.add(fluid); + } + + // fluid outputs + for (FluidStack stack : rec.mFluidOutputs) { + Fluid fluid = RecipeUtil.formatGregtechFluidStack(stack); + if (fluid == null) { + continue; + } + gtr.fO.add(fluid); + } + machine.recipes.add(gtr); + } + return machine; + } +} diff --git a/src/main/java/com/bigbass/recex/recipes/exporters/RecipeExporter.java b/src/main/java/com/bigbass/recex/recipes/exporters/RecipeExporter.java new file mode 100644 index 0000000..b9dfdf6 --- /dev/null +++ b/src/main/java/com/bigbass/recex/recipes/exporters/RecipeExporter.java @@ -0,0 +1,7 @@ +package com.bigbass.recex.recipes.exporters; + +import com.bigbass.recex.recipes.Mod; + +public interface RecipeExporter { + Mod getRecipes(); +} From 93cca24f8940694e4af23110cadc3a5680975eee Mon Sep 17 00:00:00 2001 From: wlghdu97 Date: Tue, 9 Jun 2020 18:49:42 +0900 Subject: [PATCH 10/14] Add requiring mods dependencies --- src/main/java/com/bigbass/recex/RecipeExporterMod.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bigbass/recex/RecipeExporterMod.java b/src/main/java/com/bigbass/recex/RecipeExporterMod.java index c6bca40..d3993f8 100644 --- a/src/main/java/com/bigbass/recex/RecipeExporterMod.java +++ b/src/main/java/com/bigbass/recex/RecipeExporterMod.java @@ -12,7 +12,12 @@ import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; -@Mod(modid = RecipeExporterMod.MODID, version = RecipeExporterMod.VERSION, acceptableRemoteVersions = "*") +@Mod( + modid = RecipeExporterMod.MODID, + version = RecipeExporterMod.VERSION, + acceptableRemoteVersions = "*", + dependencies = "required-after:Forge; after:gregtech; after:Forestry; after: miscutils;" +) public class RecipeExporterMod { public static final String MODID = "RecEx"; From 106594e830dcaab84e8ecbb8c19343415c37f2ea Mon Sep 17 00:00:00 2001 From: wlghdu97 Date: Tue, 21 Jul 2020 21:59:49 +0900 Subject: [PATCH 11/14] Add vanilla furnace recipe exporter --- .../com/bigbass/recex/recipes/FurnaceRecipe.java | 6 ++++++ .../com/bigbass/recex/recipes/RecipeExporter.java | 14 ++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/main/java/com/bigbass/recex/recipes/FurnaceRecipe.java diff --git a/src/main/java/com/bigbass/recex/recipes/FurnaceRecipe.java b/src/main/java/com/bigbass/recex/recipes/FurnaceRecipe.java new file mode 100644 index 0000000..bd0c704 --- /dev/null +++ b/src/main/java/com/bigbass/recex/recipes/FurnaceRecipe.java @@ -0,0 +1,6 @@ +package com.bigbass.recex.recipes; + +public class FurnaceRecipe implements Recipe { + public Item i; + public Item o; +} diff --git a/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java b/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java index 1b72617..b22a888 100644 --- a/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java +++ b/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java @@ -17,6 +17,7 @@ import net.minecraft.block.Block; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; +import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.item.crafting.ShapedRecipes; import net.minecraft.item.crafting.ShapelessRecipes; import net.minecraftforge.fluids.FluidStack; @@ -72,6 +73,7 @@ public void run(){ sources.add(getOreDictShapedRecipes()); sources.add(getOreDictShapelessRecipes()); sources.add(getReplacements()); + sources.add(getFurnaceRecipes()); IconRenderer.getInstance().dispose(); @@ -308,6 +310,18 @@ private Machine getShapelessRecipes(){ return new Machine("shapeless", retRecipes); } + + private Machine getFurnaceRecipes() { + List recipes = new ArrayList<>(); + Map smeltingList = FurnaceRecipes.smelting().getSmeltingList(); + for (Map.Entry entry : smeltingList.entrySet()) { + FurnaceRecipe recipe = new FurnaceRecipe(); + recipe.i = RecipeUtil.formatRegularItemStack(entry.getKey()); + recipe.o = RecipeUtil.formatRegularItemStack(entry.getValue()); + recipes.add(recipe); + } + return new Machine("furnace", recipes); + } private void saveData(String json){ try { From 1f078641954411a27cd07ced2eab44de21f7eb12 Mon Sep 17 00:00:00 2001 From: wlghdu97 Date: Tue, 21 Jul 2020 22:00:16 +0900 Subject: [PATCH 12/14] Fix IconRenderer itemStackColor npe --- .../com/bigbass/recex/recipes/renderer/IconRenderer.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java b/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java index 40089ea..5824f9e 100644 --- a/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java +++ b/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java @@ -348,7 +348,12 @@ private void renderItemIntoGUI(TextureManager textureManager, ItemStack itemStac OpenGlHelper.glBlendFunc(770, 771, 1, 0); textureManager.bindTexture(item.getSpriteNumber() == 0 ? TextureMap.locationBlocksTexture : TextureMap.locationItemsTexture); IIcon iicon = item.getIcon(itemStack, itemStackColor); - int i1 = itemStack.getItem().getColorFromItemStack(itemStack, itemStackColor); + int i1; + try { + i1 = itemStack.getItem().getColorFromItemStack(itemStack, itemStackColor); + } catch (Exception e) { + i1 = 16777215; + } float r = (float)(i1 >> 16 & 255) / 255.0F; float g = (float)(i1 >> 8 & 255) / 255.0F; float b = (float)(i1 & 255) / 255.0F; From 78c3c36958cd8d6016039b1cd71d96646677f780 Mon Sep 17 00:00:00 2001 From: wlghdu97 Date: Tue, 21 Jul 2020 22:02:26 +0900 Subject: [PATCH 13/14] Fix Item.localizedName to remove chat formatting --- .../recex/recipes/gregtech/RecipeUtil.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/bigbass/recex/recipes/gregtech/RecipeUtil.java b/src/main/java/com/bigbass/recex/recipes/gregtech/RecipeUtil.java index 5f60c59..727f0b5 100644 --- a/src/main/java/com/bigbass/recex/recipes/gregtech/RecipeUtil.java +++ b/src/main/java/com/bigbass/recex/recipes/gregtech/RecipeUtil.java @@ -8,7 +8,11 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; +import java.util.regex.Pattern; + public class RecipeUtil { + + private static Pattern pattern = Pattern.compile("(?i)" + '\u00a7' + "[0-9A-FK-OR]"); public static Item formatRegularItemStack(ItemStack stack){ if(stack == null){ @@ -22,7 +26,7 @@ public static Item formatRegularItemStack(ItemStack stack){ item.uN = stack.getUnlocalizedName(); } catch(Exception e){} try { - item.lN = stack.getDisplayName(); + item.lN = pattern.matcher(stack.getDisplayName()).replaceAll(""); } catch(Exception e){} IconRenderer.getInstance().printItemStack(stack, item.uN); @@ -41,7 +45,7 @@ public static Fluid formatRegularFluidStack(FluidStack stack) { fluid.uN = stack.getUnlocalizedName(); } catch (Exception e) {} try { - fluid.lN = stack.getLocalizedName(); + fluid.lN = pattern.matcher(stack.getLocalizedName()).replaceAll(""); } catch (Exception e) {} IconRenderer.getInstance().printFluidStack(stack, fluid.uN); @@ -60,10 +64,10 @@ public static Item formatGregtechItemStack(ItemStack stack){ item.uN = stack.getUnlocalizedName(); } catch(Exception e){} try { - item.lN = stack.getDisplayName(); + item.lN = pattern.matcher(stack.getDisplayName()).replaceAll(""); } catch(Exception e1){ try { - item.lN = GT_LanguageManager.getTranslation(stack.getUnlocalizedName()); + item.lN = pattern.matcher(GT_LanguageManager.getTranslation(stack.getUnlocalizedName())).replaceAll(""); } catch(Exception e2){} } @@ -87,13 +91,13 @@ public static Fluid formatGregtechFluidStack(FluidStack stack){ fluid.uN = stack.getUnlocalizedName(); } catch(Exception e){} try { - fluid.lN = GT_LanguageManager.getTranslation(stack.getUnlocalizedName()); + fluid.lN = pattern.matcher(GT_LanguageManager.getTranslation(stack.getUnlocalizedName())).replaceAll(""); } catch(Exception e1){ try { - fluid.lN = stack.getFluid().getName(); + fluid.lN = pattern.matcher(stack.getFluid().getName()).replaceAll(""); } catch(Exception e2){ try { - fluid.lN = stack.getLocalizedName(); + fluid.lN = pattern.matcher(stack.getLocalizedName()).replaceAll(""); } catch(Exception e3){} } } From c1fca4447029cfd66786ae8a31b7dd1c7b14905a Mon Sep 17 00:00:00 2001 From: wlghdu97 Date: Sun, 26 Jul 2020 11:55:12 +0900 Subject: [PATCH 14/14] Fix missing dependencies --- build.gradle | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index d656a02..1a934ba 100644 --- a/build.gradle +++ b/build.gradle @@ -24,12 +24,14 @@ buildscript { dependencies { classpath "net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT" classpath "de.undercouch:gradle-download-task:3.1.2" + classpath "com.github.jengelman.gradle.plugins:shadow:2.0.1" } } import de.undercouch.gradle.tasks.download.Download apply plugin: 'forge' apply plugin: 'eclipse' +apply plugin: 'com.github.johnrengelman.shadow' eclipse { classpath { @@ -48,11 +50,31 @@ version = "0.0.1" group = "com.bigbass.recex" archivesBaseName = "RecipeExporter" +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + minecraft { version = "1.7.10-10.13.4.1614-1.7.10" runDir = "eclipse" } +jar { + finalizedBy shadowJar + manifest { + attributes 'Main-Class': 'com.bigbass.recex' + } +} + +shadowJar { + configurations = [project.configurations.shadow] + relocate 'ar.com.hjg.pngj', 'com.bigbass.recex.pngj' + classifier '' +} + +reobf { + shadowJar {} +} + repositories { maven { name "Forge" // Applied Energistics @@ -95,12 +117,14 @@ dependencies { compile "codechicken:CodeChickenLib:1.7.10-1.1.3.138:dev" compile "codechicken:CodeChickenCore:1.7.10-1.0.7.47:dev" compile "codechicken:NotEnoughItems:1.7.10-1.0.5.120:dev" - + compile "net.sengir.forestry:forestry_1.7.10:4.2.9.57:dev" + compile "com.google.code.gson:gson:2.7" - + shadow "ar.com.hjg:pngj:2.1.0" + compile "javax.json:javax.json-api:1.0" compile "org.glassfish:javax.json:1.0.4" - + compile fileTree(dir: 'libs', include: '*.jar') compile fileTree(dir: 'libs', include: '*.zip') }