Skip to content

Commit

Permalink
Fixed localization files.
Browse files Browse the repository at this point in the history
Initial work on custom slot for backpack.
Upgrade to v0.6.5
  • Loading branch information
Darkona committed Oct 24, 2014
1 parent bbf9fe9 commit 3a5694a
Show file tree
Hide file tree
Showing 11 changed files with 859 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ buildscript {

apply plugin: 'forge'

version = "1.7.10-0.6.4"
version = "1.7.10-0.6.5"
group = "com.darkona.adventurebackpack" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "adventurebackpack"

Expand Down
209 changes: 209 additions & 0 deletions src/main/java/arg/ARG.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
/**
* Copyright (C) 2013 Flow86
*
* AdvancedRecipeGenerator is open-source.
*
* It is distributed under the terms of my Open Source License.
* It grants rights to read, modify, compile or run the code.
* It does *NOT* grant the right to redistribute this software or its
* modifications in any form, binary or source, except if expressively
* granted by the copyright holder.
*/

package arg;

import java.util.Map;
import java.util.logging.Logger;

import com.darkona.adventurebackpack.init.ModItems;
import com.darkona.adventurebackpack.init.recipes.AbstractBackpackRecipe;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.RecipeFireworks;
import net.minecraft.item.crafting.RecipesArmorDyes;
import net.minecraft.item.crafting.RecipesMapCloning;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.MinecraftForge;

import com.google.common.collect.Maps;

import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

@Mod(modid = ARG.NAME, name = ARG.NAME, version = ARG.VERSION)
public class ARG
{
public static final String NAME = "Advanced-Recipe-Generator";
public static final String VERSION = "${version}";

@Instance("Advanced-Recipe-Generator")
public static ARG instance;

public static Logger argLog = Logger.getLogger(NAME);

public static int[] mapLoaded = {0, 0};
public static boolean mapGenerated = false;

@EventHandler
public void load(FMLInitializationEvent evt)
{
argLog.info("Starting " + NAME + " #${buildnumber} " + VERSION + " (Built for Minecraft/Forge ${mc_apiversion}");
argLog.info("Copyright (c) Flow86, 2012-2014");

MinecraftForge.EVENT_BUS.register(this);
}

@SuppressWarnings({"rawtypes", "unchecked"})
@SubscribeEvent(priority = EventPriority.LOWEST)
@SideOnly(Side.CLIENT)
public void createRecipeImages(TextureStitchEvent.Post evt)
{
mapLoaded[evt.map.getTextureType()]++;

if (mapLoaded[0] > 0 && mapLoaded[0] == mapLoaded[1])
{
if (mapGenerated)
{
return;
}
mapGenerated = true;

argLog.info("Generating Recipes ...");

TextureManager tm = Minecraft.getMinecraft().getTextureManager();

// save since we get a ConcurrentModificationException in TextureManager.func_110549_a otherwise

Map mapTextureObjects = ObfuscationReflectionHelper.getPrivateValue(TextureManager.class, tm, "mapTextureObjects", "field_110585_a");

Map new_mapTextureObjects = Maps.newHashMap();
new_mapTextureObjects.putAll(mapTextureObjects);
ObfuscationReflectionHelper.setPrivateValue(TextureManager.class, tm, new_mapTextureObjects, "mapTextureObjects", "field_110585_a");

for (Object orecipe : CraftingManager.getInstance().getRecipeList())
{
IRecipe irecipe = (IRecipe) orecipe;

if ((irecipe instanceof RecipesArmorDyes) || (irecipe instanceof RecipeFireworks) || (irecipe instanceof RecipesMapCloning))
{
continue;
}

if (irecipe.getRecipeOutput() == null)
{
System.out.println("Skip recipe without output: " + irecipe.getClass().getSimpleName());
continue;
}

if (irecipe instanceof AbstractBackpackRecipe)
{
AbstractBackpackRecipe abs = new AbstractBackpackRecipe();
ItemStack b = new ItemStack(ModItems.adventureBackpack, 1);
b.setTagCompound(new NBTTagCompound());
b.stackTagCompound.setString("colorName", "Standard");
for (Map.Entry<String, ItemStack[]> recipe : abs.recipes.entrySet())
{
RenderRecipe render = new RenderRecipe(recipe.getKey());
for (int i = 0; i < 9; i++)
{
if (i == 4)
{
render.getCraftingContainer().craftMatrix.setInventorySlotContents(i, b);
} else
{
render.getCraftingContainer().craftMatrix.setInventorySlotContents(i, recipe.getValue()[i]);
}
}
render.getCraftingContainer().craftResult.setInventorySlotContents(0, abs.getCraftingResult(render.getCraftingContainer().craftMatrix));
render.draw("Adventure Backpack Colors");

}
} else
{
continue;
}


RenderRecipe render = new RenderRecipe(irecipe.getRecipeOutput().getDisplayName());

ItemStack[] recipeInput = null;
try
{
recipeInput = RecipeHelper.getRecipeArray(irecipe);
if (recipeInput == null)
{
continue;
}
} catch (Exception e)
{
e.printStackTrace();
}

// Determine mod of this recipe.
UniqueIdentifier identifier = null;
identifier = getUniqueIdentifier(irecipe.getRecipeOutput());
int recipe = 0;
while (identifier == null && recipeInput != null && recipe < recipeInput.length)
{
ItemStack input = recipeInput[recipe];
identifier = getUniqueIdentifier(input);
recipe++;
}
String subFolder = "vanilla";
if (identifier != null)
{
subFolder = identifier.modId;
}

try
{
for (int i = 0; i < recipeInput.length - 1; ++i)
render.getCraftingContainer().craftMatrix.setInventorySlotContents(i, recipeInput[i + 1]);

render.getCraftingContainer().craftResult.setInventorySlotContents(0, recipeInput[0]);
render.draw(subFolder);
} catch (Exception e)
{
e.printStackTrace();
}
}

// restore map since we get a ConcurrentModificationException in TextureManager.func_110549_a otherwise
ObfuscationReflectionHelper.setPrivateValue(TextureManager.class, tm, mapTextureObjects, "mapTextureObjects", "field_110585_a");

argLog.info("Finished Generation of Recipes in " + Minecraft.getMinecraft().mcDataDir + "/recipes/");
}
}

private UniqueIdentifier getUniqueIdentifier(ItemStack itemStack)
{
if (itemStack == null || itemStack.getItem() == null)
{
return null;
}
if (itemStack.getItem() instanceof ItemBlock)
{
Block block = Block.getBlockFromItem(((ItemBlock) itemStack.getItem()));
return GameRegistry.findUniqueIdentifierFor(block);
} else
{
return GameRegistry.findUniqueIdentifierFor(itemStack.getItem());
}
}
}
50 changes: 50 additions & 0 deletions src/main/java/arg/ContainerCraft.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright (C) 2013 Flow86
*
* AdvancedRecipeGenerator is open-source.
*
* It is distributed under the terms of my Open Source License.
* It grants rights to read, modify, compile or run the code.
* It does *NOT* grant the right to redistribute this software or its
* modifications in any form, binary or source, except if expressively
* granted by the copyright holder.
*/

package arg;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCraftResult;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;

public class ContainerCraft extends Container
{
public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3);
public IInventory craftResult = new InventoryCraftResult();

public ContainerCraft()
{
this.addSlotToContainer(new SlotCrafting(null, this.craftMatrix, this.craftResult, 0, 124, 35));
int l;
int i1;

for (l = 0; l < 3; ++l)
{
for (i1 = 0; i1 < 3; ++i1)
{
this.addSlotToContainer(new Slot(this.craftMatrix, i1 + l * 3, 30 + i1 * 18, 17 + l * 18));
}
}

this.onCraftMatrixChanged(this.craftMatrix);
}

@Override
public boolean canInteractWith(EntityPlayer entityplayer)
{
return true;
}
}
Loading

0 comments on commit 3a5694a

Please sign in to comment.