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') } 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"; 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/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/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/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/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 52d52bd..98b3275 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 implements ItemBase { + 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/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 new file mode 100644 index 0000000..4bbe8db --- /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 implements Recipe { + /** 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/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 44adf06..b22a888 100644 --- a/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java +++ b/src/main/java/com/bigbass/recex/recipes/RecipeExporter.java @@ -1,31 +1,37 @@ 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.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; +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; 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; import net.minecraftforge.oredict.OreDictionary; 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 { @@ -55,17 +61,30 @@ public static RecipeExporter getInst(){ */ public void run(){ Hashtable root = new Hashtable(); + + IconRenderer.getInstance().init(); List sources = new ArrayList(); sources.add(getGregtechRecipes()); + sources.add(new GTPPRecipeExporter().getRecipes()); + sources.add(new ForestryRecipeExporter().getRecipes()); sources.add(getShapedRecipes()); sources.add(getShapelessRecipes()); sources.add(getOreDictShapedRecipes()); - //TODO Support Oredicted Shaped and Shapeless Ore recipes - + sources.add(getOreDictShapelessRecipes()); + sources.add(getReplacements()); + sources.add(getFurnaceRecipes()); + + IconRenderer.getInstance().dispose(); + 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){ @@ -82,18 +101,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){ @@ -146,22 +160,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){ @@ -172,18 +180,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)); } } @@ -192,27 +196,73 @@ private Object getOreDictShapedRecipes(){ retRecipes.add(rec); } } - data.put("recipes", retRecipes); - return data; + return new Machine("shapedOre", retRecipes); } - private Set getReplacements(String name){ + private Machine getOreDictShapelessRecipes(){ + 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); + } + } + + return new Machine("shapelessOre", retRecipes); + } + + 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 ItemList getReplacements(){ + List oreDictItems = new ArrayList<>(); + String[] oreNames = OreDictionary.getOreNames(); + for(String name : oreNames){ + oreDictItems.add(new OreDictItem(name, getReplacements(name))); + } + + return new ItemList("replacements", oreDictItems); + } + + 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(){ - 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){ @@ -229,17 +279,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){ @@ -262,9 +307,20 @@ private Object getShapelessRecipes(){ retRecipes.add(rec); } } - data.put("recipes", retRecipes); - return data; + 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){ 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/exporters/ForestryRecipeExporter.java b/src/main/java/com/bigbass/recex/recipes/exporters/ForestryRecipeExporter.java new file mode 100644 index 0000000..4777326 --- /dev/null +++ b/src/main/java/com/bigbass/recex/recipes/exporters/ForestryRecipeExporter.java @@ -0,0 +1,268 @@ +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 implements RecipeExporter { + + @Override + public Mod getRecipes() { + 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/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(); +} 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/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/gregtech/RecipeUtil.java b/src/main/java/com/bigbass/recex/recipes/gregtech/RecipeUtil.java index 04cc2cc..727f0b5 100644 --- a/src/main/java/com/bigbass/recex/recipes/gregtech/RecipeUtil.java +++ b/src/main/java/com/bigbass/recex/recipes/gregtech/RecipeUtil.java @@ -3,12 +3,16 @@ 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; +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,11 +26,31 @@ 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); 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 = pattern.matcher(stack.getLocalizedName()).replaceAll(""); + } catch (Exception e) {} + + IconRenderer.getInstance().printFluidStack(stack, fluid.uN); + return fluid; + } public static Item formatGregtechItemStack(ItemStack stack){ if(stack == null){ @@ -40,17 +64,18 @@ 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){} } 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; } @@ -66,17 +91,18 @@ 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){} } } - + + 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..5824f9e --- /dev/null +++ b/src/main/java/com/bigbass/recex/recipes/renderer/IconRenderer.java @@ -0,0 +1,465 @@ +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.GL12; +import org.lwjgl.opengl.GL30; + +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; + +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 + RenderHelper.disableStandardItemLighting(); + 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(GL12.GL_RESCALE_NORMAL); + GL11.glDisable(GL11.GL_ALPHA_TEST); + GL11.glDisable(GL11.GL_DEPTH_TEST); + RenderHelper.enableStandardItemLighting(); + + 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) { + 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.getParentFile().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 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); + } + + GL11.glRotatef(-90F, 0.0F, 1.0F, 0.0F); + renderBlocks.useInventoryTint = inColor; + customRenderer.renderItem(INVENTORY, item, renderBlocks); + renderBlocks.useInventoryTint = true; + 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); + } + + GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F); + renderBlocks.useInventoryTint = this.renderWithColor; + renderBlocks.renderBlockAsItem(block, itemDamage, 1.0F); + renderBlocks.useInventoryTint = true; + + 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; + 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; + + 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); + } +} 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; + } +}