Yeah... sorry about the lack of code. Normally I would just stick all the code up there, but I'm part of a dev team right now, and I really don't want to get in trouble for posting source code to the mod. :/
I got vanilla shaped and shapeless, and ore dictionary shapeless to work, but I can't seem to get the old ore dictionary shaped recipes to work. Relevant code:
Well, first you should ask your team for help then....honestly if you want help here and getting in the questions you have, code will help us solve faster.....and the relevant code you have posted is not relevant. First you may want to understand that in my videos I explain about the grid size, and each class that must be changed to match or you will receive errors in one way or another. Ore Dictionary classes may not work so well because of it being a part of forge and relies heavily on the vanilla crafting table. This may be part of the issue you have. Another is, look at the crafting manager....recipes are made by using "XXX", "XXX", "XXX"....so these recipes will be hardcoded to the 3x3 size grid shape. As I said before you may have to recreate every recipe you want to fit the "XXXX", "XXXX", "XXXX", "XXXX" shape you are looking for....
Well, first you should ask your team for help then....honestly if you want help here and getting in the questions you have, code will help us solve faster.....and the relevant code you have posted is not relevant. First you may want to understand that in my videos I explain about the grid size, and each class that must be changed to match or you will receive errors in one way or another. Ore Dictionary classes may not work so well because of it being a part of forge and relies heavily on the vanilla crafting table. This may be part of the issue you have. Another is, look at the crafting manager....recipes are made by using "XXX", "XXX", "XXX"....so these recipes will be hardcoded to the 3x3 size grid shape. As I said before you may have to recreate every recipe you want to fit the "XXXX", "XXXX", "XXXX", "XXXX" shape you are looking for....
Yeah, I might have to do that. Well, thanks for putting up with my incompetence, and sorry for wasting your time.
It wasnt so much a waste of time, I had mentioned about rewriting the recipes before. I had this trouble once when creating my better table mod. Vanilla recipes all had to be redone for my table. Also provide code and a clear explanation of what you are trying to accomplish so we can better help you.
It wasnt so much a waste of time, I had mentioned about rewriting the recipes before. I had this trouble once when creating my better table mod. Vanilla recipes all had to be redone for my table. Also provide code and a clear explanation of what you are trying to accomplish so we can better help you.
I'm creating all the vanilla crafting recipes for my table, and they're working fine. I was just looking for a dynamic way to convert from ShapedOreRecipe to my custom ShapedOreRecipe class. I can do it from vanilla shaped and shapeless, but shaped ore just doesn't want to cooperate.
package BlackFighter111.BlackMagicMod;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.Block;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
public class CraftingManagerDarkStoneAltar
{
public static final int WILDCARD_VALUE = Short.MAX_VALUE;
private static final CraftingManagerDarkStoneAltar instance = new CraftingManagerDarkStoneAltar();
private List recipes = new ArrayList();
public static final CraftingManagerDarkStoneAltar getInstance()
{
return instance;
}
private CraftingManagerDarkStoneAltar()
{
recipes = new ArrayList();
//This is where your recipes will go
this.addRecipe(new ItemStack(blackMagicMod.blackMagicTome, 1), new Object[] {" C ", " CCC ", "DCBCD", " CCC ", " C ", 'C', blackMagicMod.corruptedSoul, 'D', blackMagicMod.darkStone, 'B', Item.book});
Collections.sort(this.recipes, new RecipeSorterDarkStoneAltar(this));
System.out.println(this.recipes.size() + " recipes");
}
public DarkStoneAltarShapedRecipies addRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj)
{
String var3 = "";
int var4 = 0;
int var5 = 0;
int var6 = 0;
if (par2ArrayOfObj[var4] instanceof String[])
{
String[] var7 = (String[])((String[])par2ArrayOfObj[var4++]);
for (int var8 = 0; var8 < var7.length; ++var8)
{
String var9 = var7[var8];
++var6;
var5 = var9.length();
var3 = var3 + var9;
}
}
else
{
while (par2ArrayOfObj[var4] instanceof String)
{
String var11 = (String)par2ArrayOfObj[var4++];
++var6;
var5 = var11.length();
var3 = var3 + var11;
}
}
HashMap var12;
for (var12 = new HashMap(); var4 < par2ArrayOfObj.length; var4 += 2)
{
Character var13 = (Character)par2ArrayOfObj[var4];
ItemStack var14 = null;
if (par2ArrayOfObj[var4 + 1] instanceof Item)
{
var14 = new ItemStack((Item)par2ArrayOfObj[var4 + 1]);
}
else if (par2ArrayOfObj[var4 + 1] instanceof Block)
{
var14 = new ItemStack((Block)par2ArrayOfObj[var4 + 1], 1, -1);
}
else if (par2ArrayOfObj[var4 + 1] instanceof ItemStack)
{
var14 = (ItemStack)par2ArrayOfObj[var4 + 1];
}
var12.put(var13, var14);
}
ItemStack[] var15 = new ItemStack[var5 * var6];
for (int var16 = 0; var16 < var5 * var6; ++var16)
{
char var10 = var3.charAt(var16);
if (var12.containsKey(Character.valueOf(var10)))
{
var15[var16] = ((ItemStack)var12.get(Character.valueOf(var10))).copy();
}
else
{
var15[var16] = null;
}
}
DarkStoneAltarShapedRecipies var17 = new DarkStoneAltarShapedRecipies(var5, var6, var15, par1ItemStack);
this.recipes.add(var17);
return var17;
}
public void addShapelessRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj)
{
ArrayList var3 = new ArrayList();
Object[] var4 = par2ArrayOfObj;
int var5 = par2ArrayOfObj.length;
for (int var6 = 0; var6 < var5; ++var6)
{
Object var7 = var4[var6];
if (var7 instanceof ItemStack)
{
var3.add(((ItemStack)var7).copy());
}
else if (var7 instanceof Item)
{
var3.add(new ItemStack((Item)var7));
}
else
{
if (!(var7 instanceof Block))
{
throw new RuntimeException("Invalid shapeless recipy!");
}
var3.add(new ItemStack((Block)var7));
}
}
this.recipes.add(new DarkStoneAltarShapelessRecipies(par1ItemStack, var3));
}
public ItemStack findMatchingRecipe(InventoryCrafting par1InventoryCrafting, World par2World)
{
int var3 = 0;
ItemStack var4 = null;
ItemStack var5 = null;
int var6;
for (var6 = 0; var6 < par1InventoryCrafting.getSizeInventory(); ++var6)
{
ItemStack var7 = par1InventoryCrafting.getStackInSlot(var6);
if (var7 != null)
{
if (var3 == 0)
{
var4 = var7;
}
if (var3 == 1)
{
var5 = var7;
}
++var3;
}
}
if (var3 == 2 && var4.itemID == var5.itemID && var4.stackSize == 1 && var5.stackSize == 1 && Item.itemsList[var4.itemID].isRepairable())
{
Item var11 = Item.itemsList[var4.itemID];
int var13 = var11.getMaxDamage() - var4.getItemDamageForDisplay();
int var8 = var11.getMaxDamage() - var5.getItemDamageForDisplay();
int var9 = var13 + var8 + var11.getMaxDamage() * 5 / 100;
int var10 = var11.getMaxDamage() - var9;
if (var10 < 0)
{
var10 = 0;
}
return new ItemStack(var4.itemID, 1, var10);
}
else
{
for (var6 = 0; var6 < this.recipes.size(); ++var6)
{
IRecipe var12 = (IRecipe)this.recipes.get(var6);
if (var12.matches(par1InventoryCrafting, par2World))
{
return var12.getCraftingResult(par1InventoryCrafting);
}
}
return null;
}
}
/**
* returns the List<> of all recipes
*/
public List getRecipeList()
{
return this.recipes;
}
}
package BlackFighter111.BlackMagicMod;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
public class GuiDarkStoneAltar extends GuiContainer
{
private ResourceLocation guiTexture = new ResourceLocation("blackmagicmod:textures/gui/darkStoneAltar.png");
public GuiDarkStoneAltar(InventoryPlayer inventoryplayer, World world, int i, int j, int k)
{
super(new ContainerDarkStoneAltar(inventoryplayer, world, i, j, k));
}
public void onGuiClosed()
{
super.onGuiClosed();
}
protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
//this.fontRenderer.drawString(StatCollector.translateToLocal("\u00a76Better"), 120, 5, 0x404040);
//this.fontRenderer.drawString(StatCollector.translateToLocal("\u00a76Crafting"), 116, 20, 0x404040);
//this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 - 14, 0x404040);
}
protected void drawGuiContainerBackgroundLayer(float f, int i, int j)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
mc.renderEngine.bindTexture(guiTexture);
int l = (width - xSize) / 2;
int i1 = (height - ySize) / 2;
drawTexturedModalRect(l, i1, 0, 0, xSize, ySize);
}
}
package BlackFighter111.BlackMagicMod;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;
public class GuiHandlerDarkStoneAltar implements IGuiHandler
{
@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity tile_entity = world.getBlockTileEntity(x, y, z);
switch(id)
{
case 0: return id == 0 && world.getBlockId(x, y, z) == blackMagicMod.darkStoneTable.blockID ? new ContainerDarkStoneAltar(player.inventory, world, x, y, z) : null;
}
return null;
}
@Override
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity tile_entity = world.getBlockTileEntity(x, y, z);
switch(id)
{
case 0: return id == 0 && world.getBlockId(x, y, z) == blackMagicMod.darkStoneTable.blockID ? new GuiDarkStoneAltar(player.inventory, world, x, y, z) : null;
}
return null;
}
}
package BlackFighter111.BlackMagicMod;
import java.util.Comparator;
import net.minecraft.item.crafting.IRecipe;
public class RecipeSorterDarkStoneAltar implements Comparator
{
final CraftingManagerDarkStoneAltar craftingManagerDarkStoneAltar;
public RecipeSorterDarkStoneAltar(CraftingManagerDarkStoneAltar par1CraftingManagerDarkStoneAltar)
{
this.craftingManagerDarkStoneAltar = par1CraftingManagerDarkStoneAltar;
}
public int compareRecipes(IRecipe par1IRecipe, IRecipe par2IRecipe)
{
return par1IRecipe instanceof DarkStoneAltarShapelessRecipies && par2IRecipe instanceof DarkStoneAltarShapedRecipies ? 1 : (par2IRecipe instanceof DarkStoneAltarShapelessRecipies && par1IRecipe instanceof DarkStoneAltarShapedRecipies ? -1 : (par2IRecipe.getRecipeSize() < par1IRecipe.getRecipeSize() ? -1 : (par2IRecipe.getRecipeSize() > par1IRecipe.getRecipeSize() ? 1 : 0)));
}
public int compare(Object par1Obj, Object par2Obj)
{
return this.compareRecipes((IRecipe)par1Obj, (IRecipe)par2Obj);
}
}
package BlackFighter111.BlackMagicMod;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public class DarkStoneAltarShapedRecipies implements IRecipe
{
/** How many horizontal slots this recipe is wide. */
public final int recipeWidth;
/** How many vertical slots this recipe uses. */
public final int recipeHeight;
/** Is a array of ItemStack that composes the recipe. */
public final ItemStack[] recipeItems;
/** Is the ItemStack that you get when craft the recipe. */
private ItemStack recipeOutput;
/** Is the itemID of the output item that you get when craft the recipe. */
public final int recipeOutputItemID;
private boolean field_92101_f = false;
public DarkStoneAltarShapedRecipies(int par1, int par2, ItemStack[] par3ArrayOfItemStack, ItemStack par4ItemStack)
{
this.recipeOutputItemID = par4ItemStack.itemID;
this.recipeWidth = par1;
this.recipeHeight = par2;
this.recipeItems = par3ArrayOfItemStack;
this.recipeOutput = par4ItemStack;
}
public ItemStack getRecipeOutput()
{
return this.recipeOutput;
}
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World)
{
for (int i = 0; i <= 5 - this.recipeWidth; ++i)
{
for (int j = 0; j <= 5 - this.recipeHeight; ++j)
{
if (this.checkMatch(par1InventoryCrafting, i, j, true))
{
return true;
}
if (this.checkMatch(par1InventoryCrafting, i, j, false))
{
return true;
}
}
}
return false;
}
/**
* Checks if the region of a crafting inventory is match for the recipe.
*/
private boolean checkMatch(InventoryCrafting par1InventoryCrafting, int par2, int par3, boolean par4)
{
for (int k = 0; k < 5; ++k)
{
for (int l = 0; l < 5; ++l)
{
int i1 = k - par2;
int j1 = l - par3;
ItemStack itemstack = null;
if (i1 >= 0 && j1 >= 0 && i1 < this.recipeWidth && j1 < this.recipeHeight)
{
if (par4)
{
itemstack = this.recipeItems[this.recipeWidth - i1 - 1 + j1 * this.recipeWidth];
}
else
{
itemstack = this.recipeItems[i1 + j1 * this.recipeWidth];
}
}
ItemStack itemstack1 = par1InventoryCrafting.getStackInRowAndColumn(k, l);
if (itemstack1 != null || itemstack != null)
{
if (itemstack1 == null && itemstack != null || itemstack1 != null && itemstack == null)
{
return false;
}
if (itemstack.itemID != itemstack1.itemID)
{
return false;
}
if (itemstack.getItemDamage() != 32767 && itemstack.getItemDamage() != itemstack1.getItemDamage())
{
return false;
}
}
}
}
return true;
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)
{
ItemStack itemstack = this.getRecipeOutput().copy();
if (this.field_92101_f)
{
for (int i = 0; i < par1InventoryCrafting.getSizeInventory(); ++i)
{
ItemStack itemstack1 = par1InventoryCrafting.getStackInSlot(i);
if (itemstack1 != null && itemstack1.hasTagCompound())
{
itemstack.setTagCompound((NBTTagCompound)itemstack1.stackTagCompound.copy());
}
}
}
return itemstack;
}
/**
* Returns the size of the recipe area
*/
public int getRecipeSize()
{
return this.recipeWidth * this.recipeHeight;
}
public DarkStoneAltarShapedRecipies func_92100_c()
{
this.field_92101_f = true;
return this;
}
}
package BlackFighter111.BlackMagicMod;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
public class DarkStoneAltarShapelessRecipies implements IRecipe
{
/** Is the ItemStack that you get when craft the recipe. */
private final ItemStack recipeOutput;
/** Is a List of ItemStack that composes the recipe. */
public final List recipeItems;
public DarkStoneAltarShapelessRecipies(ItemStack par1ItemStack, List par2List)
{
this.recipeOutput = par1ItemStack;
this.recipeItems = par2List;
}
public ItemStack getRecipeOutput()
{
return this.recipeOutput;
}
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World)
{
ArrayList arraylist = new ArrayList(this.recipeItems);
for (int i = 0; i < 5; ++i)
{
for (int j = 0; j < 5; ++j)
{
ItemStack itemstack = par1InventoryCrafting.getStackInRowAndColumn(j, i);
if (itemstack != null)
{
boolean flag = false;
Iterator iterator = arraylist.iterator();
while (iterator.hasNext())
{
ItemStack itemstack1 = (ItemStack)iterator.next();
if (itemstack.itemID == itemstack1.itemID && (itemstack1.getItemDamage() == 32767 || itemstack.getItemDamage() == itemstack1.getItemDamage()))
{
flag = true;
arraylist.remove(itemstack1);
break;
}
}
if (!flag)
{
return false;
}
}
}
}
return arraylist.isEmpty();
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)
{
return this.recipeOutput.copy();
}
/**
* Returns the size of the recipe area
*/
public int getRecipeSize()
{
return this.recipeItems.size();
}
}
I am having trouble importing the 5x5 table into my existing. I can run it just fine in its own workspace with all of the original names hierarchies, but once in mine, it goes kaput.
Specifically, here is the error that I am receiving:
[INFO] [STDERR] at net.smeltercraft.mod.table.ContainerWorkSurface.onCraftMatrixChanged(ContainerWorkSurface.java:62)
[INFO] [STDERR] at net.smeltercraft.mod.table.ContainerWorkSurface.<init>(ContainerWorkSurface.java:57)
[INFO] [STDERR] at net.smeltercraft.mod.table.WorkSurfaceGui.<init>(WorkSurfaceGui.java:17)
[INFO] [STDERR] at net.smeltercraft.mod.viffy.GuiHandlerWorkSurface.getClientGuiElement(GuiHandlerWorkSurface.java:29)
[INFO] [STDERR] at cpw.mods.fml.common.network.NetworkRegistry.openLocalGui(NetworkRegistry.java:328)
[INFO] [STDERR] at cpw.mods.fml.common.network.FMLNetworkHandler.openGui(FMLNetworkHandler.java:357)
[INFO] [STDERR] at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2480)
[INFO] [STDERR] at net.smeltercraft.mod.table.WorkSurface.onBlockActivated(WorkSurface.java:54)
[INFO] [STDERR] at net.minecraft.client.multiplayer.PlayerControllerMP.onPlayerRightClick(PlayerControllerMP.java:371)
My Main Class:
package net.smeltercraft.mod;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.smeltercraft.mod.item.ItemBrassBackSaw;
import net.smeltercraft.mod.item.ItemBrassHammer;
import net.smeltercraft.mod.item.SmelterCraftItem;
i
import net.smeltercraft.mod.viffy.CommonProxy;
import net.smeltercraft.mod.viffy.CraftingHandlerSmelterCraft;
import net.smeltercraft.mod.viffy.GuiHandlerWorkSurface;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@Mod(modid = SmelterCraft.modid, name = "SmelterCraft", version = "v0.001")
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class SmelterCraft {
//MODID DECLARATION
public static final String modid = "smeltercraft";
//INSTANCE DECLARATION
@Instance(modid)
public static SmelterCraft instance;
//BLOCK DECLARATION
public static Block blockWorkSurface;
//ITEM DECLARATION
public static Item itemStaff;
public static Item itemBrassHammer;
public static Item itemBrassNail;
public static Item itemBrassBackSaw;
public static Item itemBrassPlankCasing;
@SidedProxy(clientSide = "net.smeltercraft.mod.viffy.ClientProxy", serverSide = "net.smeltercraft.mod.viffy.CommonProxy")
public static CommonProxy proxy;
public static CreativeTabs SmelterTab;
@EventHandler
public void load (FMLInitializationEvent e){
SmelterTab = new CreativeTabs("SmelterCraft"){
@SideOnly(Side.CLIENT)
public int getTabIconItemIndex(){
return SmelterCraft.blockGarnetOre.blockID;
}
};
LanguageRegistry.instance().addStringLocalization(SmelterTab.getTranslatedTabLabel(), "SmelterCraft");
//BLOCK INITIALIZATION
itemBrassHammer = new ItemBrassHammer(13279).setUnlocalizedName("BrassHammer");
registerItem(itemBrassHammer, "Brass Hammer");
itemBrassNail = new SmelterCraftItem(13279).setUnlocalizedName("BrassNail");
registerItem(itemBrassNail, "Brass Nail");
itemBrassBackSaw = new ItemBrassBackSaw(13280).setUnlocalizedName("BrassBackSaw");
registerItem(itemBrassBackSaw, "Brass Back Saw");
itemBrassPlankCasing = new SmelterCraftItem(13281).setUnlocalizedName("BrassPlankCasing");
registerItem(itemBrassPlankCasing, "Brass Plank Casing");
//MACHINE INITIALIZATION
blockWorkSurface = new WorkSurface(1051).setUnlocalizedName("WorkSurface").setHardness(3.7F).setCreativeTab(SmelterTab);
registerBlock(blockWorkSurface, "Work Surface");
LanguageRegistry.instance().addStringLocalization("container.worksurface", "Work Surface");
//HANDLER INITIALIZATION
GameRegistry.registerCraftingHandler(new CraftingHandlerSmelterCraft());
NetworkRegistry.instance().registerGuiHandler(this, new GuiHandlerWorkSurface());
//CRAFTING RECIPES
//TIER ZERO CRAFTING RECIPES
GameRegistry.addRecipe(new ItemStack(itemCobblestoneNugget, 9), new Object[]{"X", 'X', Block.cobblestone});
GameRegistry.addRecipe(new ItemStack(Block.stone), new Object[]{"XXX", "XXX", "XXX", 'X', itemStoneNugget});
GameRegistry.addRecipe(new ItemStack(Block.cobblestone), new Object[]{"XXX", "XXX", "XXX", 'X', itemCobblestoneNugget});
GameRegistry.addRecipe(new ItemStack(itemRawBrassDust, 2), new Object[]{"XY", 'X', itemRawCuprumDust, 'Y', itemRawZincDust});
GameRegistry.addRecipe(new ItemStack(itemRawBrassDust, 2), new Object[]{"YX", 'X', itemRawCuprumDust, 'Y', itemRawZincDust});
GameRegistry.addRecipe(new ItemStack(itemRawBronzeDust, 2), new Object[]{"XY", 'X', itemRawCuprumDust, 'Y', itemRawStannumDust});
GameRegistry.addRecipe(new ItemStack(itemBrassPlankCasing, 1), new Object[]{"XYX", "YYY", "XYX", 'X', itemBrassNail, 'Y', Block.wood});
//SMELTING RECIPES
//RECIPE INITIALIZATION
//WORLD GENERATION INITIALIZATION
GameRegistry.registerWorldGenerator(new WorldGenSmelterCraft());
proxy.registerRenderThings();
}
public void registerBlock(Block block, String name){
GameRegistry.registerBlock(block, block.getUnlocalizedName());
LanguageRegistry.addName(block, name);
}
public void registerItem(Item item, String name){
GameRegistry.registerItem(item, item.getUnlocalizedName());
LanguageRegistry.addName(item, name);
}
}
Block Class:
package net.smeltercraft.mod.table;
import net.smeltercraft.mod.SmelterCraft;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class WorkSurface extends Block
{
@SideOnly(Side.CLIENT)
private Icon workbenchIconTop;
@SideOnly(Side.CLIENT)
private Icon workbenchIconFront;
public WorkSurface(int i)
{
super(i, Material.ground);
this.setCreativeTab(SmelterCraft.SmelterTab);
}
@SideOnly(Side.CLIENT)
/**
* From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
*/
public Icon getIcon(int par1, int par2)
{
return par1 == 1 ? this.workbenchIconTop : (par1 == 0 ? Block.planks.getBlockTextureFromSide(par1) : (par1 != 2 && par1 != 4 ? this.blockIcon : this.workbenchIconFront));
}
@SideOnly(Side.CLIENT)
/**
* When this method is called, your block should register all the icons it needs with the given IconRegister. This
* is the only chance you get to register icons.
*/
public void registerIcons(IconRegister par1IconRegister)
{
this.blockIcon = par1IconRegister.registerIcon("BetterTable:better_side");
this.workbenchIconTop = par1IconRegister.registerIcon("BetterTable:better_top");
this.workbenchIconFront = par1IconRegister.registerIcon("BetterTable:better_front");
}
public boolean onBlockActivated(World var1, int var2, int var3, int var4, EntityPlayer player, int var6, float var7, float var8, float var9)
{
if (!player.isSneaking())
{
player.openGui(SmelterCraft.instance, 12, var1, var2, var3, var4);
return true;
}
else
{
return false;
}
}
}
package net.smeltercraft.mod.table;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import cpw.mods.fml.common.registry.GameRegistry;
import net.smeltercraft.mod.SmelterCraft;
import net.smeltercraft.mod.item.*;
import net.smeltercraft.mod.tablecare.SmelterCraftRecipeSorter;
import net.smeltercraft.mod.tablecare.SmelterCraftShapedRecipes;
import net.smeltercraft.mod.tablecare.SmelterCraftShapelessRecipes;
import net.minecraft.block.Block;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
import net.smeltercraft.mod.tablecare.SmelterCraftShapedRecipes;
public class SmelterCraftCraftingManager
{
public static final int WILDCARD_VALUE = Short.MAX_VALUE;
private static final SmelterCraftCraftingManager instance = new SmelterCraftCraftingManager();
private List recipes = new ArrayList();
public static final SmelterCraftCraftingManager getInstance()
{
return instance;
}
private SmelterCraftCraftingManager()
{
recipes = new ArrayList();
//Basic Crafts
this.func_92051_a(new ItemStack(SmelterCraft.itemStaff, 1), new Object[] {"S", "S", "S", "S", "S", 'S', Item.stick});
Collections.sort(this.recipes, new SmelterCraftRecipeSorter(this));
System.out.println(this.recipes.size() + " recipes");
}
public SmelterCraftShapedRecipes func_92051_a(ItemStack par1ItemStack, Object ... par2ArrayOfObj)
{
String var3 = "";
int var4 = 0;
int var5 = 0;
int var6 = 0;
if (par2ArrayOfObj[var4] instanceof String[])
{
String[] var7 = (String[])((String[])par2ArrayOfObj[var4++]);
for (int var8 = 0; var8 < var7.length; ++var8)
{
String var9 = var7[var8];
++var6;
var5 = var9.length();
var3 = var3 + var9;
}
}
else
{
while (par2ArrayOfObj[var4] instanceof String)
{
String var11 = (String)par2ArrayOfObj[var4++];
++var6;
var5 = var11.length();
var3 = var3 + var11;
}
}
HashMap var12;
for (var12 = new HashMap(); var4 < par2ArrayOfObj.length; var4 += 2)
{
Character var13 = (Character)par2ArrayOfObj[var4];
ItemStack var14 = null;
if (par2ArrayOfObj[var4 + 1] instanceof Item)
{
var14 = new ItemStack((Item)par2ArrayOfObj[var4 + 1]);
}
else if (par2ArrayOfObj[var4 + 1] instanceof Block)
{
var14 = new ItemStack((Block)par2ArrayOfObj[var4 + 1], 1, -1);
}
else if (par2ArrayOfObj[var4 + 1] instanceof ItemStack)
{
var14 = (ItemStack)par2ArrayOfObj[var4 + 1];
}
var12.put(var13, var14);
}
ItemStack[] var15 = new ItemStack[var5 * var6];
for (int var16 = 0; var16 < var5 * var6; ++var16)
{
char var10 = var3.charAt(var16);
if (var12.containsKey(Character.valueOf(var10)))
{
var15[var16] = ((ItemStack)var12.get(Character.valueOf(var10))).copy();
}
else
{
var15[var16] = null;
}
}
SmelterCraftShapedRecipes var17 = new SmelterCraftShapedRecipes(var5, var6, var15, par1ItemStack);
this.recipes.add(var17);
return var17;
}
public void addBuilderShapelessRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj)
{
ArrayList var3 = new ArrayList();
Object[] var4 = par2ArrayOfObj;
int var5 = par2ArrayOfObj.length;
for (int var6 = 0; var6 < var5; ++var6)
{
Object var7 = var4[var6];
if (var7 instanceof ItemStack)
{
var3.add(((ItemStack)var7).copy());
}
else if (var7 instanceof Item)
{
var3.add(new ItemStack((Item)var7));
}
else
{
if (!(var7 instanceof Block))
{
throw new RuntimeException("Invalid shapeless recipy!");
}
var3.add(new ItemStack((Block)var7));
}
}
this.recipes.add(new SmelterCraftShapelessRecipes(par1ItemStack, var3));
}
public ItemStack findMatchingRecipe(InventoryCrafting par1InventoryCrafting, World par2World)
{
int var3 = 0;
ItemStack var4 = null;
ItemStack var5 = null;
int var6;
for (var6 = 0; var6 < par1InventoryCrafting.getSizeInventory(); ++var6)
{
ItemStack var7 = par1InventoryCrafting.getStackInSlot(var6);
if (var7 != null)
{
if (var3 == 0)
{
var4 = var7;
}
if (var3 == 1)
{
var5 = var7;
}
++var3;
}
}
if (var3 == 2 && var4.itemID == var5.itemID && var4.stackSize == 1 && var5.stackSize == 1 && Item.itemsList[var4.itemID].isRepairable())
{
Item var11 = Item.itemsList[var4.itemID];
int var13 = var11.getMaxDamage() - var4.getItemDamageForDisplay();
int var8 = var11.getMaxDamage() - var5.getItemDamageForDisplay();
int var9 = var13 + var8 + var11.getMaxDamage() * 5 / 100;
int var10 = var11.getMaxDamage() - var9;
if (var10 < 0)
{
var10 = 0;
}
return new ItemStack(var4.itemID, 1, var10);
}
else
{
for (var6 = 0; var6 < this.recipes.size(); ++var6)
{
IRecipe var12 = (IRecipe)this.recipes.get(var6);
if (var12.matches(par1InventoryCrafting, par2World))
{
return var12.getCraftingResult(par1InventoryCrafting);
}
}
return null;
}
}
/**
* returns the List<> of all recipes
*/
public List getRecipeList()
{
return this.recipes;
}
}
GUI Class:
package net.smeltercraft.mod.table;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
public class WorkSurfaceGui extends GuiContainer
{
private ResourceLocation worksurface = new ResourceLocation("textures/gui/worksurface.png");
public WorkSurfaceGui(InventoryPlayer inventoryplayer, World world, int i, int j, int k)
{
super(new ContainerWorkSurface(inventoryplayer, world, i, j, k));
this.xSize = 176;
this.ySize = 165;
}
public void onGuiClosed()
{
super.onGuiClosed();
}
protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
this.fontRenderer.drawString(StatCollector.translateToLocal("Work Surface"), 100, 5, 0x404040);
//this.fontRenderer.drawString(StatCollector.translateToLocal("Surface"), 116, 20, 0x404040);
//this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 - 14, 0x404040);
}
public void drawGuiContainerBackgroundLayer(float f, int j, int i) {
GL11.glColor4f(1F, 1F, 1F, 1F);
Minecraft.getMinecraft().getTextureManager().
bindTexture(worksurface);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
}
}
GUI Handler Class:
package net.smeltercraft.mod.viffy;
import net.smeltercraft.mod.SmelterCraft;
import net.smeltercraft.mod.table.WorkSurfaceGui;
import net.smeltercraft.mod.table.ContainerWorkSurface;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;
public class GuiHandlerWorkSurface implements IGuiHandler
{
@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity tile_entity = world.getBlockTileEntity(x, y, z);
switch(id)
{
case 12: return id == 12 && world.getBlockId(x, y, z) == SmelterCraft.blockWorkSurface.blockID ? new ContainerWorkSurface(player.inventory, world, x, y, z) : null;
}
return null;
}
@Override
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)
{
TileEntity tile_entity = world.getBlockTileEntity(x, y, z);
switch(id)
{
case 12: return id == 12 && world.getBlockId(x, y, z) == SmelterCraft.blockWorkSurface.blockID ? new WorkSurfaceGui(player.inventory, world, x, y, z) : null;
}
return null;
}
}
Recipe Sorter Class:
package net.smeltercraft.mod.tablecare;
import java.util.Comparator;
import net.minecraft.item.crafting.IRecipe;
import net.smeltercraft.mod.table.SmelterCraftCraftingManager;
public class SmelterCraftRecipeSorter implements Comparator
{
final SmelterCraftCraftingManager betterCraftingManager;
public SmelterCraftRecipeSorter(SmelterCraftCraftingManager par1BetterCraftingManager)
{
this.betterCraftingManager = par1BetterCraftingManager;
}
public int compareRecipes(IRecipe par1IRecipe, IRecipe par2IRecipe)
{
return par1IRecipe instanceof SmelterCraftShapelessRecipes && par2IRecipe instanceof SmelterCraftShapedRecipes ? 1 : (par2IRecipe instanceof SmelterCraftShapelessRecipes && par1IRecipe instanceof SmelterCraftShapedRecipes ? -1 : (par2IRecipe.getRecipeSize() < par1IRecipe.getRecipeSize() ? -1 : (par2IRecipe.getRecipeSize() > par1IRecipe.getRecipeSize() ? 1 : 0)));
}
public int compare(Object par1Obj, Object par2Obj)
{
return this.compareRecipes((IRecipe)par1Obj, (IRecipe)par2Obj);
}
}
Shaped Recipes Class:
package net.smeltercraft.mod.tablecare;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public class SmelterCraftShapedRecipes implements IRecipe
{
/** How many horizontal slots this recipe is wide. */
public final int recipeWidth;
/** How many vertical slots this recipe uses. */
public final int recipeHeight;
/** Is a array of ItemStack that composes the recipe. */
public final ItemStack[] recipeItems;
/** Is the ItemStack that you get when craft the recipe. */
private ItemStack recipeOutput;
/** Is the itemID of the output item that you get when craft the recipe. */
public final int recipeOutputItemID;
private boolean field_92101_f = false;
public SmelterCraftShapedRecipes(int par1, int par2, ItemStack[] par3ArrayOfItemStack, ItemStack par4ItemStack)
{
this.recipeOutputItemID = par4ItemStack.itemID;
this.recipeWidth = par1;
this.recipeHeight = par2;
this.recipeItems = par3ArrayOfItemStack;
this.recipeOutput = par4ItemStack;
}
public ItemStack getRecipeOutput()
{
return this.recipeOutput;
}
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World)
{
for (int i = 0; i <= 5 - this.recipeWidth; ++i)
{
for (int j = 0; j <= 5 - this.recipeHeight; ++j)
{
if (this.checkMatch(par1InventoryCrafting, i, j, true))
{
return true;
}
if (this.checkMatch(par1InventoryCrafting, i, j, false))
{
return true;
}
}
}
return false;
}
/**
* Checks if the region of a crafting inventory is match for the recipe.
*/
private boolean checkMatch(InventoryCrafting par1InventoryCrafting, int par2, int par3, boolean par4)
{
for (int k = 0; k < 5; ++k)
{
for (int l = 0; l < 5; ++l)
{
int i1 = k - par2;
int j1 = l - par3;
ItemStack itemstack = null;
if (i1 >= 0 && j1 >= 0 && i1 < this.recipeWidth && j1 < this.recipeHeight)
{
if (par4)
{
itemstack = this.recipeItems[this.recipeWidth - i1 - 1 + j1 * this.recipeWidth];
}
else
{
itemstack = this.recipeItems[i1 + j1 * this.recipeWidth];
}
}
ItemStack itemstack1 = par1InventoryCrafting.getStackInRowAndColumn(k, l);
if (itemstack1 != null || itemstack != null)
{
if (itemstack1 == null && itemstack != null || itemstack1 != null && itemstack == null)
{
return false;
}
if (itemstack.itemID != itemstack1.itemID)
{
return false;
}
if (itemstack.getItemDamage() != 32767 && itemstack.getItemDamage() != itemstack1.getItemDamage())
{
return false;
}
}
}
}
return true;
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)
{
ItemStack itemstack = this.getRecipeOutput().copy();
if (this.field_92101_f)
{
for (int i = 0; i < par1InventoryCrafting.getSizeInventory(); ++i)
{
ItemStack itemstack1 = par1InventoryCrafting.getStackInSlot(i);
if (itemstack1 != null && itemstack1.hasTagCompound())
{
itemstack.setTagCompound((NBTTagCompound)itemstack1.stackTagCompound.copy());
}
}
}
return itemstack;
}
/**
* Returns the size of the recipe area
*/
public int getRecipeSize()
{
return this.recipeWidth * this.recipeHeight;
}
public SmelterCraftShapedRecipes func_92100_c()
{
this.field_92101_f = true;
return this;
}
}
Shapeless Recipes Class:
package net.smeltercraft.mod.tablecare;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
public class SmelterCraftShapelessRecipes implements IRecipe
{
/** Is the ItemStack that you get when craft the recipe. */
private final ItemStack recipeOutput;
/** Is a List of ItemStack that composes the recipe. */
public final List recipeItems;
public SmelterCraftShapelessRecipes(ItemStack par1ItemStack, List par2List)
{
this.recipeOutput = par1ItemStack;
this.recipeItems = par2List;
}
public ItemStack getRecipeOutput()
{
return this.recipeOutput;
}
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World)
{
ArrayList arraylist = new ArrayList(this.recipeItems);
for (int i = 0; i < 5; ++i)
{
for (int j = 0; j < 5; ++j)
{
ItemStack itemstack = par1InventoryCrafting.getStackInRowAndColumn(j, i);
if (itemstack != null)
{
boolean flag = false;
Iterator iterator = arraylist.iterator();
while (iterator.hasNext())
{
ItemStack itemstack1 = (ItemStack)iterator.next();
if (itemstack.itemID == itemstack1.itemID && (itemstack1.getItemDamage() == 32767 || itemstack.getItemDamage() == itemstack1.getItemDamage()))
{
flag = true;
arraylist.remove(itemstack1);
break;
}
}
if (!flag)
{
return false;
}
}
}
}
return arraylist.isEmpty();
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)
{
return this.recipeOutput.copy();
}
/**
* Returns the size of the recipe area
*/
public int getRecipeSize()
{
return this.recipeItems.size();
}
}
Any help you can spare is greatly appreciated!
Rollback Post to RevisionRollBack
If someone helps you out, don't hesitate to hit the green button to give them some props.
Dude i followed your code i have no problems in my code but when i go into minecraft and i try to open my crafting table the gui dosnt come up!!!!!! am so lost please help
package BlackFighter111.BlackMagicMod; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import cpw.mods.fml.common.registry.GameRegistry; import net.minecraft.block.Block; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.world.World; public class CraftingManagerDarkStoneAltar { public static final int WILDCARD_VALUE = Short.MAX_VALUE; private static final CraftingManagerDarkStoneAltar instance = new CraftingManagerDarkStoneAltar(); private List recipes = new ArrayList(); public static final CraftingManagerDarkStoneAltar getInstance() { return instance; } private CraftingManagerDarkStoneAltar() { recipes = new ArrayList(); //This is where your recipes will go this.addRecipe(new ItemStack(blackMagicMod.blackMagicTome, 1), new Object[] {" C ", " CCC ", "DCBCD", " CCC ", " C ", 'C', blackMagicMod.corruptedSoul, 'D', blackMagicMod.darkStone, 'B', Item.book}); Collections.sort(this.recipes, new RecipeSorterDarkStoneAltar(this)); System.out.println(this.recipes.size() + " recipes"); } public DarkStoneAltarShapedRecipies addRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj) { String var3 = ""; int var4 = 0; int var5 = 0; int var6 = 0; if (par2ArrayOfObj[var4] instanceof String[]) { String[] var7 = (String[])((String[])par2ArrayOfObj[var4++]); for (int var8 = 0; var8 < var7.length; ++var8) { String var9 = var7[var8]; ++var6; var5 = var9.length(); var3 = var3 + var9; } } else { while (par2ArrayOfObj[var4] instanceof String) { String var11 = (String)par2ArrayOfObj[var4++]; ++var6; var5 = var11.length(); var3 = var3 + var11; } } HashMap var12; for (var12 = new HashMap(); var4 < par2ArrayOfObj.length; var4 += 2) { Character var13 = (Character)par2ArrayOfObj[var4]; ItemStack var14 = null; if (par2ArrayOfObj[var4 + 1] instanceof Item) { var14 = new ItemStack((Item)par2ArrayOfObj[var4 + 1]); } else if (par2ArrayOfObj[var4 + 1] instanceof Block) { var14 = new ItemStack((Block)par2ArrayOfObj[var4 + 1], 1, -1); } else if (par2ArrayOfObj[var4 + 1] instanceof ItemStack) { var14 = (ItemStack)par2ArrayOfObj[var4 + 1]; } var12.put(var13, var14); } ItemStack[] var15 = new ItemStack[var5 * var6]; for (int var16 = 0; var16 < var5 * var6; ++var16) { char var10 = var3.charAt(var16); if (var12.containsKey(Character.valueOf(var10))) { var15[var16] = ((ItemStack)var12.get(Character.valueOf(var10))).copy(); } else { var15[var16] = null; } } DarkStoneAltarShapedRecipies var17 = new DarkStoneAltarShapedRecipies(var5, var6, var15, par1ItemStack); this.recipes.add(var17); return var17; } public void addShapelessRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj) { ArrayList var3 = new ArrayList(); Object[] var4 = par2ArrayOfObj; int var5 = par2ArrayOfObj.length; for (int var6 = 0; var6 < var5; ++var6) { Object var7 = var4[var6]; if (var7 instanceof ItemStack) { var3.add(((ItemStack)var7).copy()); } else if (var7 instanceof Item) { var3.add(new ItemStack((Item)var7)); } else { if (!(var7 instanceof Block)) { throw new RuntimeException("Invalid shapeless recipy!"); } var3.add(new ItemStack((Block)var7)); } } this.recipes.add(new DarkStoneAltarShapelessRecipies(par1ItemStack, var3)); } public ItemStack findMatchingRecipe(InventoryCrafting par1InventoryCrafting, World par2World) { int var3 = 0; ItemStack var4 = null; ItemStack var5 = null; int var6; for (var6 = 0; var6 < par1InventoryCrafting.getSizeInventory(); ++var6) { ItemStack var7 = par1InventoryCrafting.getStackInSlot(var6); if (var7 != null) { if (var3 == 0) { var4 = var7; } if (var3 == 1) { var5 = var7; } ++var3; } } if (var3 == 2 && var4.itemID == var5.itemID && var4.stackSize == 1 && var5.stackSize == 1 && Item.itemsList[var4.itemID].isRepairable()) { Item var11 = Item.itemsList[var4.itemID]; int var13 = var11.getMaxDamage() - var4.getItemDamageForDisplay(); int var8 = var11.getMaxDamage() - var5.getItemDamageForDisplay(); int var9 = var13 + var8 + var11.getMaxDamage() * 5 / 100; int var10 = var11.getMaxDamage() - var9; if (var10 < 0) { var10 = 0; } return new ItemStack(var4.itemID, 1, var10); } else { for (var6 = 0; var6 < this.recipes.size(); ++var6) { IRecipe var12 = (IRecipe)this.recipes.get(var6); if (var12.matches(par1InventoryCrafting, par2World)) { return var12.getCraftingResult(par1InventoryCrafting); } } return null; } } /** * returns the List<> of all recipes */ public List getRecipeList() { return this.recipes; } }
package BlackFighter111.BlackMagicMod; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import net.minecraft.world.World; import org.lwjgl.opengl.GL11; public class GuiDarkStoneAltar extends GuiContainer { private ResourceLocation guiTexture = new ResourceLocation("blackmagicmod:textures/gui/darkStoneAltar.png"); public GuiDarkStoneAltar(InventoryPlayer inventoryplayer, World world, int i, int j, int k) { super(new ContainerDarkStoneAltar(inventoryplayer, world, i, j, k)); } public void onGuiClosed() { super.onGuiClosed(); } protected void drawGuiContainerForegroundLayer(int par1, int par2) { //this.fontRenderer.drawString(StatCollector.translateToLocal("\u00a76Better"), 120, 5, 0x404040); //this.fontRenderer.drawString(StatCollector.translateToLocal("\u00a76Crafting"), 116, 20, 0x404040); //this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 - 14, 0x404040); } protected void drawGuiContainerBackgroundLayer(float f, int i, int j) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); mc.renderEngine.bindTexture(guiTexture); int l = (width - xSize) / 2; int i1 = (height - ySize) / 2; drawTexturedModalRect(l, i1, 0, 0, xSize, ySize); } }
package BlackFighter111.BlackMagicMod; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import cpw.mods.fml.common.network.IGuiHandler; public class GuiHandlerDarkStoneAltar implements IGuiHandler { @Override public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { TileEntity tile_entity = world.getBlockTileEntity(x, y, z); switch(id) { case 0: return id == 0 && world.getBlockId(x, y, z) == blackMagicMod.darkStoneTable.blockID ? new ContainerDarkStoneAltar(player.inventory, world, x, y, z) : null; } return null; } @Override public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { TileEntity tile_entity = world.getBlockTileEntity(x, y, z); switch(id) { case 0: return id == 0 && world.getBlockId(x, y, z) == blackMagicMod.darkStoneTable.blockID ? new GuiDarkStoneAltar(player.inventory, world, x, y, z) : null; } return null; } }
package BlackFighter111.BlackMagicMod; import java.util.Comparator; import net.minecraft.item.crafting.IRecipe; public class RecipeSorterDarkStoneAltar implements Comparator { final CraftingManagerDarkStoneAltar craftingManagerDarkStoneAltar; public RecipeSorterDarkStoneAltar(CraftingManagerDarkStoneAltar par1CraftingManagerDarkStoneAltar) { this.craftingManagerDarkStoneAltar = par1CraftingManagerDarkStoneAltar; } public int compareRecipes(IRecipe par1IRecipe, IRecipe par2IRecipe) { return par1IRecipe instanceof DarkStoneAltarShapelessRecipies && par2IRecipe instanceof DarkStoneAltarShapedRecipies ? 1 : (par2IRecipe instanceof DarkStoneAltarShapelessRecipies && par1IRecipe instanceof DarkStoneAltarShapedRecipies ? -1 : (par2IRecipe.getRecipeSize() < par1IRecipe.getRecipeSize() ? -1 : (par2IRecipe.getRecipeSize() > par1IRecipe.getRecipeSize() ? 1 : 0))); } public int compare(Object par1Obj, Object par2Obj) { return this.compareRecipes((IRecipe)par1Obj, (IRecipe)par2Obj); } }
package BlackFighter111.BlackMagicMod; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; public class DarkStoneAltarShapedRecipies implements IRecipe { /** How many horizontal slots this recipe is wide. */ public final int recipeWidth; /** How many vertical slots this recipe uses. */ public final int recipeHeight; /** Is a array of ItemStack that composes the recipe. */ public final ItemStack[] recipeItems; /** Is the ItemStack that you get when craft the recipe. */ private ItemStack recipeOutput; /** Is the itemID of the output item that you get when craft the recipe. */ public final int recipeOutputItemID; private boolean field_92101_f = false; public DarkStoneAltarShapedRecipies(int par1, int par2, ItemStack[] par3ArrayOfItemStack, ItemStack par4ItemStack) { this.recipeOutputItemID = par4ItemStack.itemID; this.recipeWidth = par1; this.recipeHeight = par2; this.recipeItems = par3ArrayOfItemStack; this.recipeOutput = par4ItemStack; } public ItemStack getRecipeOutput() { return this.recipeOutput; } /** * Used to check if a recipe matches current crafting inventory */ public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World) { for (int i = 0; i <= 5 - this.recipeWidth; ++i) { for (int j = 0; j <= 5 - this.recipeHeight; ++j) { if (this.checkMatch(par1InventoryCrafting, i, j, true)) { return true; } if (this.checkMatch(par1InventoryCrafting, i, j, false)) { return true; } } } return false; } /** * Checks if the region of a crafting inventory is match for the recipe. */ private boolean checkMatch(InventoryCrafting par1InventoryCrafting, int par2, int par3, boolean par4) { for (int k = 0; k < 5; ++k) { for (int l = 0; l < 5; ++l) { int i1 = k - par2; int j1 = l - par3; ItemStack itemstack = null; if (i1 >= 0 && j1 >= 0 && i1 < this.recipeWidth && j1 < this.recipeHeight) { if (par4) { itemstack = this.recipeItems[this.recipeWidth - i1 - 1 + j1 * this.recipeWidth]; } else { itemstack = this.recipeItems[i1 + j1 * this.recipeWidth]; } } ItemStack itemstack1 = par1InventoryCrafting.getStackInRowAndColumn(k, l); if (itemstack1 != null || itemstack != null) { if (itemstack1 == null && itemstack != null || itemstack1 != null && itemstack == null) { return false; } if (itemstack.itemID != itemstack1.itemID) { return false; } if (itemstack.getItemDamage() != 32767 && itemstack.getItemDamage() != itemstack1.getItemDamage()) { return false; } } } } return true; } /** * Returns an Item that is the result of this recipe */ public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting) { ItemStack itemstack = this.getRecipeOutput().copy(); if (this.field_92101_f) { for (int i = 0; i < par1InventoryCrafting.getSizeInventory(); ++i) { ItemStack itemstack1 = par1InventoryCrafting.getStackInSlot(i); if (itemstack1 != null && itemstack1.hasTagCompound()) { itemstack.setTagCompound((NBTTagCompound)itemstack1.stackTagCompound.copy()); } } } return itemstack; } /** * Returns the size of the recipe area */ public int getRecipeSize() { return this.recipeWidth * this.recipeHeight; } public DarkStoneAltarShapedRecipies func_92100_c() { this.field_92101_f = true; return this; } }
package BlackFighter111.BlackMagicMod; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.world.World; public class DarkStoneAltarShapelessRecipies implements IRecipe { /** Is the ItemStack that you get when craft the recipe. */ private final ItemStack recipeOutput; /** Is a List of ItemStack that composes the recipe. */ public final List recipeItems; public DarkStoneAltarShapelessRecipies(ItemStack par1ItemStack, List par2List) { this.recipeOutput = par1ItemStack; this.recipeItems = par2List; } public ItemStack getRecipeOutput() { return this.recipeOutput; } /** * Used to check if a recipe matches current crafting inventory */ public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World) { ArrayList arraylist = new ArrayList(this.recipeItems); for (int i = 0; i < 5; ++i) { for (int j = 0; j < 5; ++j) { ItemStack itemstack = par1InventoryCrafting.getStackInRowAndColumn(j, i); if (itemstack != null) { boolean flag = false; Iterator iterator = arraylist.iterator(); while (iterator.hasNext()) { ItemStack itemstack1 = (ItemStack)iterator.next(); if (itemstack.itemID == itemstack1.itemID && (itemstack1.getItemDamage() == 32767 || itemstack.getItemDamage() == itemstack1.getItemDamage())) { flag = true; arraylist.remove(itemstack1); break; } } if (!flag) { return false; } } } } return arraylist.isEmpty(); } /** * Returns an Item that is the result of this recipe */ public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting) { return this.recipeOutput.copy(); } /** * Returns the size of the recipe area */ public int getRecipeSize() { return this.recipeItems.size(); } }
Dude i followed your code i have no problems in my code but when i go into minecraft and i try to open my crafting table the gui dosnt come up!!!!!! am so lost please help
Did you guys get your tables to work?
Rollback Post to RevisionRollBack
If someone helps you out, don't hesitate to hit the green button to give them some props.
Hello, I just want to start off by saying these tutorials are very good and have helped a huge amount, thank you micro!
Anyway, I have a custom 1 x 3 crafting table for my mod.
Everything seems to be working, slots are aligned with the texture....
Only issue is the crafting recipes don't work, and by thoroughly scanning my code, can't figure out why...
Here is my code, I plan to upload it to GitHub soon, but for now I'll just post it...
SCMCraftingManager
i
package gent202.snowcones;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
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.RecipesArmor;
import net.minecraft.item.crafting.RecipesArmorDyes;
import net.minecraft.item.crafting.RecipesCrafting;
import net.minecraft.item.crafting.RecipesDyes;
import net.minecraft.item.crafting.RecipesFood;
import net.minecraft.item.crafting.RecipesIngots;
import net.minecraft.item.crafting.RecipesMapCloning;
import net.minecraft.item.crafting.RecipesMapExtending;
import net.minecraft.item.crafting.RecipesTools;
import net.minecraft.item.crafting.RecipesWeapons;
import net.minecraft.world.World;
public class SCMCraftingManager
{
/** The static instance of this class */
private static final SCMCraftingManager instance = new SCMCraftingManager();
/** A list of all the recipes added */
private List recipes = new ArrayList();
/**
* Returns the static instance of this class
*/
public static final SCMCraftingManager getInstance()
{
return instance;
}
private SCMCraftingManager()
{
Collections.sort(this.recipes, new SCMRecipeSorter(this));
}
public ShapedRecipesSCM addRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj)
{
String s = "";
int i = 0;
int j = 0;
int k = 0;
if (par2ArrayOfObj[i] instanceof String[])
{
String[] astring = (String[])((String[])par2ArrayOfObj[i++]);
for (int l = 0; l < astring.length; ++l)
{
String s1 = astring[l];
++k;
j = s1.length();
s = s + s1;
}
}
else
{
while (par2ArrayOfObj[i] instanceof String)
{
String s2 = (String)par2ArrayOfObj[i++];
++k;
j = s2.length();
s = s + s2;
}
}
HashMap hashmap;
for (hashmap = new HashMap(); i < par2ArrayOfObj.length; i += 2)
{
Character character = (Character)par2ArrayOfObj[i];
ItemStack itemstack1 = null;
if (par2ArrayOfObj[i + 1] instanceof Item)
{
itemstack1 = new ItemStack((Item)par2ArrayOfObj[i + 1]);
}
else if (par2ArrayOfObj[i + 1] instanceof Block)
{
itemstack1 = new ItemStack((Block)par2ArrayOfObj[i + 1], 1, 32767);
}
else if (par2ArrayOfObj[i + 1] instanceof ItemStack)
{
itemstack1 = (ItemStack)par2ArrayOfObj[i + 1];
}
hashmap.put(character, itemstack1);
}
ItemStack[] aitemstack = new ItemStack[j * k];
for (int i1 = 0; i1 < j * k; ++i1)
{
char c0 = s.charAt(i1);
if (hashmap.containsKey(Character.valueOf(c0)))
{
aitemstack[i1] = ((ItemStack)hashmap.get(Character.valueOf(c0))).copy();
}
else
{
aitemstack[i1] = null;
}
}
ShapedRecipesSCM shapedSCTrecipes = new ShapedRecipesSCM(j, k, aitemstack, par1ItemStack);
this.recipes.add(shapedSCTrecipes);
return shapedSCTrecipes;
}
public void addShapelessRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj)
{
ArrayList arraylist = new ArrayList();
Object[] aobject = par2ArrayOfObj;
int i = par2ArrayOfObj.length;
for (int j = 0; j < i; ++j)
{
Object object1 = aobject[j];
if (object1 instanceof ItemStack)
{
arraylist.add(((ItemStack)object1).copy());
}
else if (object1 instanceof Item)
{
arraylist.add(new ItemStack((Item)object1));
}
else
{
if (!(object1 instanceof Block))
{
throw new RuntimeException("Invalid shapelessSCT recipy!");
}
arraylist.add(new ItemStack((Block)object1));
}
}
this.recipes.add(new ShapelessRecipesSCM(par1ItemStack, arraylist));
}
public ItemStack findMatchingRecipe(InventoryCrafting par1InventoryCrafting, World par2World)
{
int i = 0;
ItemStack itemstack = null;
ItemStack itemstack1 = null;
int j;
for (j = 0; j < par1InventoryCrafting.getSizeInventory(); ++j)
{
ItemStack itemstack2 = par1InventoryCrafting.getStackInSlot(j);
if (itemstack2 != null)
{
if (i == 0)
{
itemstack = itemstack2;
}
if (i == 1)
{
itemstack1 = itemstack2;
}
++i;
}
}
if (i == 2 &amp;&amp; itemstack.itemID == itemstack1.itemID &amp;&amp; itemstack.stackSize == 1 &amp;&amp; itemstack1.stackSize == 1 &amp;&amp; Item.itemsList[itemstack.itemID].isRepairable())
{
Item item = Item.itemsList[itemstack.itemID];
int k = item.getMaxDamage() - itemstack.getItemDamageForDisplay();
int l = item.getMaxDamage() - itemstack1.getItemDamageForDisplay();
int i1 = k + l + item.getMaxDamage() * 5 / 100;
int j1 = item.getMaxDamage() - i1;
if (j1 < 0)
{
j1 = 0;
}
return new ItemStack(itemstack.itemID, 1, j1);
}
else
{
for (j = 0; j < this.recipes.size(); ++j)
{
IRecipe irecipe = (IRecipe)this.recipes.get(j);
if (irecipe.matches(par1InventoryCrafting, par2World))
{
return irecipe.getCraftingResult(par1InventoryCrafting);
}
}
return null;
}
}
/**
* returns the List<> of all recipes
*/
public List getRecipeList()
{
return this.recipes;
}
}
ShapedRecipesSCM
package gent202.snowcones;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public class ShapedRecipesSCM implements IRecipe
{
/** How many horizontal slots this recipe is wide. */
public final int recipeWidth;
/** How many vertical slots this recipe uses. */
public final int recipeHeight;
/** Is a array of ItemStack that composes the recipe. */
public final ItemStack[] recipeItems;
/** Is the ItemStack that you get when craft the recipe. */
private ItemStack recipeOutput;
/** Is the itemID of the output item that you get when craft the recipe. */
public final int recipeOutputItemID;
private boolean field_92101_f;
public ShapedRecipesSCM(int par1, int par2, ItemStack[] par3ArrayOfItemStack, ItemStack par4ItemStack)
{
this.recipeOutputItemID = par4ItemStack.itemID;
this.recipeWidth = par1;
this.recipeHeight = par2;
this.recipeItems = par3ArrayOfItemStack;
this.recipeOutput = par4ItemStack;
}
public ItemStack getRecipeOutput()
{
return this.recipeOutput;
}
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World)
{
for (int i = 0; i <= 3 - this.recipeWidth; ++i)
{
for (int j = 0; j <= 1 - this.recipeHeight; ++j)
{
if (this.checkMatch(par1InventoryCrafting, i, j, true))
{
return true;
}
if (this.checkMatch(par1InventoryCrafting, i, j, false))
{
return true;
}
}
}
return false;
}
/**
* Checks if the region of a crafting inventory is match for the recipe.
*/
private boolean checkMatch(InventoryCrafting par1InventoryCrafting, int par2, int par3, boolean par4)
{
for (int k = 0; k < 3; ++k)
{
for (int l = 0; l < 1; ++l)
{
int i1 = k - par2;
int j1 = l - par3;
ItemStack itemstack = null;
if (i1 >= 0 &amp;&amp; j1 >= 0 &amp;&amp; i1 < this.recipeWidth &amp;&amp; j1 < this.recipeHeight)
{
if (par4)
{
itemstack = this.recipeItems[this.recipeWidth - i1 - 1 + j1 * this.recipeWidth];
}
else
{
itemstack = this.recipeItems[i1 + j1 * this.recipeWidth];
}
}
ItemStack itemstack1 = par1InventoryCrafting.getStackInRowAndColumn(k, l);
if (itemstack1 != null || itemstack != null)
{
if (itemstack1 == null &amp;&amp; itemstack != null || itemstack1 != null &amp;&amp; itemstack == null)
{
return false;
}
if (itemstack.itemID != itemstack1.itemID)
{
return false;
}
if (itemstack.getItemDamage() != 32767 &amp;&amp; itemstack.getItemDamage() != itemstack1.getItemDamage())
{
return false;
}
}
}
}
return true;
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)
{
ItemStack itemstack = this.getRecipeOutput().copy();
if (this.field_92101_f)
{
for (int i = 0; i < par1InventoryCrafting.getSizeInventory(); ++i)
{
ItemStack itemstack1 = par1InventoryCrafting.getStackInSlot(i);
if (itemstack1 != null &amp;&amp; itemstack1.hasTagCompound())
{
itemstack.setTagCompound((NBTTagCompound)itemstack1.stackTagCompound.copy());
}
}
}
return itemstack;
}
/**
* Returns the size of the recipe area
*/
public int getRecipeSize()
{
return this.recipeWidth * this.recipeHeight;
}
public ShapedRecipesSCM func_92100_c()
{
this.field_92101_f = true;
return this;
}
}
Finally, ShapelessRecipesSCM
package gent202.snowcones;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
public class ShapelessRecipesSCM implements IRecipe
{
/** Is the ItemStack that you get when craft the recipe. */
private final ItemStack recipeOutput;
/** Is a List of ItemStack that composes the recipe. */
public final List recipeItems;
public ShapelessRecipesSCM(ItemStack par1ItemStack, List par2List)
{
this.recipeOutput = par1ItemStack;
this.recipeItems = par2List;
}
public ItemStack getRecipeOutput()
{
return this.recipeOutput;
}
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World)
{
ArrayList arraylist = new ArrayList(this.recipeItems);
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 1; ++j)
{
ItemStack itemstack = par1InventoryCrafting.getStackInRowAndColumn(j, i);
if (itemstack != null)
{
boolean flag = false;
Iterator iterator = arraylist.iterator();
while (iterator.hasNext())
{
ItemStack itemstack1 = (ItemStack)iterator.next();
if (itemstack.itemID == itemstack1.itemID &amp;&amp; (itemstack1.getItemDamage() == 32767 || itemstack.getItemDamage() == itemstack1.getItemDamage()))
{
flag = true;
arraylist.remove(itemstack1);
break;
}
}
if (!flag)
{
return false;
}
}
}
}
return arraylist.isEmpty();
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)
{
return this.recipeOutput.copy();
}
/**
* Returns the size of the recipe area
*/
public int getRecipeSize()
{
return this.recipeItems.size();
}
}
Just wondering what's going on... seems to be the only problem I'm running into besides shift-click crash.
If you need to see anything else, I'd be glad to post more code.
Thanks!
Hi, so my table opens and everything seems fine but when I try to pick up stacks of items to put in the table the just go back into their slots or just disappear. I have occasionally gotten items to pick up but only when i try to grab and different item and then they disappear anyway. Any help would be great.
Main Class
@Mod(modid="alchemycraft2", name="AlchemyCraft 2", version="1.0.0 Alpha")
public class alchemycraft2 {
public static final String modid = "alchemycraft 2";
@SidedProxy(clientSide="alchemycraft2.common.ClientProxy", serverSide="alchemycraft.common.ServerProxy")
public static ServerProxy proxy;
public static CreativeTabs TabAlchemyCraft2 = new TabAlchemyCraft2(CreativeTabs.getNextID(), "AlchemyCraft 2");
//misc
@Instance("alchemycraft2")
public static alchemycraft2 instance;
private GuiHandlerElementorumElit guiHandlerElementorumElit = new GuiHandlerElementorumElit();
//items
public static Item Æther;
public static Item Air;
public static Item Light;
//blocks
public static Block ÆthericRunedStone;
public static Block AirRunedStone;
public static Block ElementorumElit;
@EventHandler
public void init(FMLInitializationEvent Event){
//blocks
ÆthericRunedStone = new ÆthericRunedStone(1001, Material.rock).setUnlocalizedName("ÆthericRunedStone");
GameRegistry.registerBlock(ÆthericRunedStone, "Ætheric Runed Stone");
AirRunedStone = new AirRunedStone(1003, Material.rock).setUnlocalizedName("AirRunedStone");
GameRegistry.registerBlock(AirRunedStone, "Aura Runed Stone");
ElementorumElit = new ElementorumElit(1005, Material.rock).setUnlocalizedName("ElementorumElit");
GameRegistry.registerBlock(ElementorumElit, "Elementorum Elit");
//items
Æther = new Æther(1000).setUnlocalizedName("Æther");
Air = new Air(1002).setUnlocalizedName("Air");
Light = new Light(1004).setUnlocalizedName("Light");
public class ContainerElementorumElit extends Container
{
/** The crafting matrix inventory (3x3). */
public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3);
public IInventory craftResult = new InventoryCraftResult();
private World worldObj;
private int posX;
private int posY;
private int posZ;
public ContainerElementorumElit(InventoryPlayer par1InventoryPlayer, World par2World, int par3, int par4, int par5)
{
this.worldObj = par2World;
this.posX = par3;
this.posY = par4;
this.posZ = par5;
this.addSlotToContainer(new SlotCrafting(par1InventoryPlayer.player, 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));
}
}
for (l = 0; l < 3; ++l)
{
for (i1 = 0; i1 < 9; ++i1)
{
this.addSlotToContainer(new Slot(par1InventoryPlayer, i1 + l * 9 + 9, 8 + i1 * 18, 84 + l * 18));
}
}
for (l = 0; l < 9; ++l)
{
this.addSlotToContainer(new Slot(par1InventoryPlayer, l, 8 + l * 18, 142));
}
this.onCraftMatrixChanged(this.craftMatrix);
}
/**
* Callback for when the crafting matrix is changed.
*/
public void onCraftMatrixChanged(IInventory par1IInventory)
{
this.craftResult.setInventorySlotContents(0, CraftingManagerElementorumElit.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
}
/**
* Called when the container is closed.
*/
public void onContainerClosed(EntityPlayer par1EntityPlayer)
{
super.onContainerClosed(par1EntityPlayer);
if (!this.worldObj.isRemote)
{
for (int i = 0; i < 9; ++i)
{
ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);
if (itemstack != null)
{
par1EntityPlayer.dropPlayerItem(itemstack);
}
}
}
}
/**
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
*/
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
{
ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(par2);
@Mod(modid="alchemycraft2", name="AlchemyCraft 2", version="1.0.0 Alpha")
public class alchemycraft2 {
public static final String modid = "alchemycraft 2";
@SidedProxy(clientSide="alchemycraft2.common.ClientProxy", serverSide="alchemycraft.common.ServerProxy")
public static ServerProxy proxy;
public static CreativeTabs TabAlchemyCraft2 = new TabAlchemyCraft2(CreativeTabs.getNextID(), "AlchemyCraft 2");
//misc
@Instance("alchemycraft2")
public static alchemycraft2 instance;
private GuiHandlerElementorumElit guiHandlerElementorumElit = new GuiHandlerElementorumElit();
//items
public static Item Æther;
public static Item Air;
public static Item Light;
//blocks
public static Block ÆthericRunedStone;
public static Block AirRunedStone;
public static Block ElementorumElit;
@EventHandler
public void init(FMLInitializationEvent Event){
//blocks
ÆthericRunedStone = new ÆthericRunedStone(1001, Material.rock).setUnlocalizedName("ÆthericRunedStone");
GameRegistry.registerBlock(ÆthericRunedStone, "Ætheric Runed Stone");
AirRunedStone = new AirRunedStone(1003, Material.rock).setUnlocalizedName("AirRunedStone");
GameRegistry.registerBlock(AirRunedStone, "Aura Runed Stone");
ElementorumElit = new ElementorumElit(1005, Material.rock).setUnlocalizedName("ElementorumElit");
GameRegistry.registerBlock(ElementorumElit, "Elementorum Elit");
//items
Æther = new Æther(1000).setUnlocalizedName("Æther");
Air = new Air(1002).setUnlocalizedName("Air");
Light = new Light(1004).setUnlocalizedName("Light");
@SideOnly(Side.CLIENT)
public class GuiElementorumElit extends GuiContainer
{
public static String GuiTexturePrefix = "alchemycraft2" + ":" + "textures/gui/";
private static final ResourceLocation alchemycraft2 = new ResourceLocation(GuiTexturePrefix + "ElementorumElit.png");
public GuiElementorumElit(InventoryPlayer par1InventoryPlayer, World par2World, int par3, int par4, int par5)
{
super(new ContainerElementorumElit(par1InventoryPlayer, par2World, par3, par4, par5));
}
public void onGuiClosed(){
super.onGuiClosed();
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items)
*/
protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
this.fontRenderer.drawString(I18n.getString("Elementorum Elit"), 28, 6, 4210752);
this.fontRenderer.drawString(I18n.getString("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
}
/**
* Draw the background layer for the GuiContainer (everything behind the items)
*/
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(alchemycraft2);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
}
}
/** How many horizontal slots this recipe is wide. */
public final int recipeWidth;
/** How many vertical slots this recipe uses. */
public final int recipeHeight;
/** Is a array of ItemStack that composes the recipe. */
public final ItemStack[] recipeItems;
/** Is the ItemStack that you get when craft the recipe. */
private ItemStack recipeOutput;
/** Is the itemID of the output item that you get when craft the recipe. */
public final int recipeOutputItemID;
private boolean field_92101_f = false;
public ItemStack getRecipeOutput()
{
return this.recipeOutput;
}
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World)
{
for (int i = 0; i <= 3 - this.recipeWidth; ++i)
{
for (int j = 0; j <= 3 - this.recipeHeight; ++j)
{
if (this.checkMatch(par1InventoryCrafting, i, j, true))
{
return true;
}
if (this.checkMatch(par1InventoryCrafting, i, j, false))
{
return true;
}
}
}
return false;
}
/**
* Checks if the region of a crafting inventory is match for the recipe.
*/
private boolean checkMatch(InventoryCrafting par1InventoryCrafting, int par2, int par3, boolean par4)
{
for (int k = 0; k < 3; ++k)
{
for (int l = 0; l < 3; ++l)
{
int i1 = k - par2;
int j1 = l - par3;
ItemStack itemstack = null;
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)
{
ItemStack itemstack = this.getRecipeOutput().copy();
if (this.field_92101_f)
{
for (int i = 0; i < par1InventoryCrafting.getSizeInventory(); ++i)
{
ItemStack itemstack1 = par1InventoryCrafting.getStackInSlot(i);
public class ShapelessEERecipes implements IRecipe{
/** Is the ItemStack that you get when craft the recipe. */
private final ItemStack recipeOutput;
/** Is a List of ItemStack that composes the recipe. */
public final List recipeItems;
public ShapelessEERecipes(ItemStack par1ItemStack, List par2List)
{
this.recipeOutput = par1ItemStack;
this.recipeItems = par2List;
}
public ItemStack getRecipeOutput()
{
return this.recipeOutput;
}
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World)
{
ArrayList arraylist = new ArrayList(this.recipeItems);
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
{
ItemStack itemstack = par1InventoryCrafting.getStackInRowAndColumn(j, i);
if (itemstack != null)
{
boolean flag = false;
Iterator iterator = arraylist.iterator();
while (iterator.hasNext())
{
ItemStack itemstack1 = (ItemStack)iterator.next();
if (itemstack.itemID == itemstack1.itemID && (itemstack1.getItemDamage() == 32767 || itemstack.getItemDamage() == itemstack1.getItemDamage()))
{
flag = true;
arraylist.remove(itemstack1);
break;
}
}
if (!flag)
{
return false;
}
}
}
}
return arraylist.isEmpty();
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)
{
return this.recipeOutput.copy();
}
/**
* Returns the size of the recipe area
*/
public int getRecipeSize()
{
return this.recipeItems.size();
}
}
Hi, so my table opens and everything seems fine but when I try to pick up stacks of items to put in the table the just go back into their slots or just disappear. I have occasionally gotten items to pick up but only when i try to grab and different item and then they disappear anyway. Any help would be great.
Thanks
It looks like your crafting manager code is the same as your main modding class. Throw that up and I will have a go at it.
Rollback Post to RevisionRollBack
If someone helps you out, don't hesitate to hit the green button to give them some props.
public class CraftingManagerElementorumElit
{
/** The static instance of this class */
private static final CraftingManagerElementorumElit instance = new CraftingManagerElementorumElit();
/** A list of all the recipes added */
private List recipes = new ArrayList();
/**
* Returns the static instance of this class
*/
public static final CraftingManagerElementorumElit getInstance()
{
return instance;
}
private CraftingManagerElementorumElit()
{
this.addRecipe(new ItemStack(Item.paper, 3), new Object[] {"###", '#', Item.reed});
Collections.sort(this.recipes, new RecipeSorterElementorumElit(this));
}
public ShapedRecipes addRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj)
{
String s = "";
int i = 0;
int j = 0;
int k = 0;
if (par2ArrayOfObj[i] instanceof String[])
{
String[] astring = (String[])((String[])par2ArrayOfObj[i++]);
for (int l = 0; l < astring.length; ++l)
{
String s1 = astring[l];
++k;
j = s1.length();
s = s + s1;
}
}
else
{
while (par2ArrayOfObj[i] instanceof String)
{
String s2 = (String)par2ArrayOfObj[i++];
++k;
j = s2.length();
s = s + s2;
}
}
HashMap hashmap;
for (hashmap = new HashMap(); i < par2ArrayOfObj.length; i += 2)
{
Character character = (Character)par2ArrayOfObj[i];
ItemStack itemstack1 = null;
if (par2ArrayOfObj[i + 1] instanceof Item)
{
itemstack1 = new ItemStack((Item)par2ArrayOfObj[i + 1]);
}
else if (par2ArrayOfObj[i + 1] instanceof Block)
{
itemstack1 = new ItemStack((Block)par2ArrayOfObj[i + 1], 1, 32767);
}
else if (par2ArrayOfObj[i + 1] instanceof ItemStack)
{
itemstack1 = (ItemStack)par2ArrayOfObj[i + 1];
}
public ItemStack findMatchingRecipe(InventoryCrafting par1InventoryCrafting, World par2World)
{
int i = 0;
ItemStack itemstack = null;
ItemStack itemstack1 = null;
int j;
public class CraftingManagerElementorumElit
{
/** The static instance of this class */
private static final CraftingManagerElementorumElit instance = new CraftingManagerElementorumElit();
/** A list of all the recipes added */
private List recipes = new ArrayList();
/**
* Returns the static instance of this class
*/
public static final CraftingManagerElementorumElit getInstance()
{
return instance;
}
private CraftingManagerElementorumElit()
{
this.addRecipe(new ItemStack(Item.paper, 3), new Object[] {"###", '#', Item.reed});
Collections.sort(this.recipes, new RecipeSorterElementorumElit(this));
}
public ShapedRecipes addRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj)
{
String s = "";
int i = 0;
int j = 0;
int k = 0;
if (par2ArrayOfObj[i] instanceof String[])
{
String[] astring = (String[])((String[])par2ArrayOfObj[i++]);
for (int l = 0; l < astring.length; ++l)
{
String s1 = astring[l];
++k;
j = s1.length();
s = s + s1;
}
}
else
{
while (par2ArrayOfObj[i] instanceof String)
{
String s2 = (String)par2ArrayOfObj[i++];
++k;
j = s2.length();
s = s + s2;
}
}
HashMap hashmap;
for (hashmap = new HashMap(); i < par2ArrayOfObj.length; i += 2)
{
Character character = (Character)par2ArrayOfObj[i];
ItemStack itemstack1 = null;
if (par2ArrayOfObj[i + 1] instanceof Item)
{
itemstack1 = new ItemStack((Item)par2ArrayOfObj[i + 1]);
}
else if (par2ArrayOfObj[i + 1] instanceof Block)
{
itemstack1 = new ItemStack((Block)par2ArrayOfObj[i + 1], 1, 32767);
}
else if (par2ArrayOfObj[i + 1] instanceof ItemStack)
{
itemstack1 = (ItemStack)par2ArrayOfObj[i + 1];
}
public ItemStack findMatchingRecipe(InventoryCrafting par1InventoryCrafting, World par2World)
{
int i = 0;
ItemStack itemstack = null;
ItemStack itemstack1 = null;
int j;
Hey link, it looks like there is a quite a bit missing from you main class. I'm not seeing any imports, package names, blocks or anything like that. Could you post the above with all the code from each of them for me to look at?
Thanks in advance!
Rollback Post to RevisionRollBack
If someone helps you out, don't hesitate to hit the green button to give them some props.
public class ElementorumElit extends Block
{
@SideOnly(Side.CLIENT)
private Icon workbenchIconTop;
@SideOnly(Side.CLIENT)
private Icon workbenchIconFront;
protected ElementorumElit(int par1, Material rock)
{
super(par1, Material.wood);
this.setCreativeTab(alchemycraft2.TabAlchemyCraft2);
}
@SideOnly(Side.CLIENT)
/**
* From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
*/
public Icon getIcon(int par1, int par2)
{
return par1 == 1 ? this.workbenchIconTop : (par1 == 0 ? Block.planks.getBlockTextureFromSide(par1) : (par1 != 2 && par1 != 4 ? this.blockIcon : this.workbenchIconFront));
}
@SideOnly(Side.CLIENT)
/**
* When this method is called, your block should register all the icons it needs with the given IconRegister. This
* is the only chance you get to register icons.
*/
public void registerIcons(IconRegister par1IconRegister)
{
this.blockIcon = par1IconRegister.registerIcon("alchemycraft2:ElementorumElit_side");
this.workbenchIconTop = par1IconRegister.registerIcon("alchemycraft2:ElementorumElit_top");
this.workbenchIconFront = par1IconRegister.registerIcon("alchemycraft2:ElementorumElit_front");
}
/**
* Called upon block activation (right click on the block.)
*/
public boolean onBlockActivated(World var1, int var2, int var3, int var4, EntityPlayer player, int par6, float par7, float par8, float par9)
{
if (!player.isSneaking())
{
player.openGui(alchemycraft2.instance, 0, var1, var2, var3, var4);
return true;
}
else
{
return false;
}
}
}
public class ElementorumElit extends Block
{
@SideOnly(Side.CLIENT)
private Icon workbenchIconTop;
@SideOnly(Side.CLIENT)
private Icon workbenchIconFront;
protected ElementorumElit(int par1, Material rock)
{
super(par1, Material.wood);
this.setCreativeTab(alchemycraft2.TabAlchemyCraft2);
}
@SideOnly(Side.CLIENT)
/**
* From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
*/
public Icon getIcon(int par1, int par2)
{
return par1 == 1 ? this.workbenchIconTop : (par1 == 0 ? Block.planks.getBlockTextureFromSide(par1) : (par1 != 2 && par1 != 4 ? this.blockIcon : this.workbenchIconFront));
}
@SideOnly(Side.CLIENT)
/**
* When this method is called, your block should register all the icons it needs with the given IconRegister. This
* is the only chance you get to register icons.
*/
public void registerIcons(IconRegister par1IconRegister)
{
this.blockIcon = par1IconRegister.registerIcon("alchemycraft2:ElementorumElit_side");
this.workbenchIconTop = par1IconRegister.registerIcon("alchemycraft2:ElementorumElit_top");
this.workbenchIconFront = par1IconRegister.registerIcon("alchemycraft2:ElementorumElit_front");
}
/**
* Called upon block activation (right click on the block.)
*/
public boolean onBlockActivated(World var1, int var2, int var3, int var4, EntityPlayer player, int par6, float par7, float par8, float par9)
{
if (!player.isSneaking())
{
player.openGui(alchemycraft2.instance, 0, var1, var2, var3, var4);
return true;
}
else
{
return false;
}
}
}
I see what you mean, that's a pretty odd behavior. I will dig into it tonight and see what I can find.
Rollback Post to RevisionRollBack
If someone helps you out, don't hesitate to hit the green button to give them some props.
Well, first you should ask your team for help then....honestly if you want help here and getting in the questions you have, code will help us solve faster.....and the relevant code you have posted is not relevant. First you may want to understand that in my videos I explain about the grid size, and each class that must be changed to match or you will receive errors in one way or another. Ore Dictionary classes may not work so well because of it being a part of forge and relies heavily on the vanilla crafting table. This may be part of the issue you have. Another is, look at the crafting manager....recipes are made by using "XXX", "XXX", "XXX"....so these recipes will be hardcoded to the 3x3 size grid shape. As I said before you may have to recreate every recipe you want to fit the "XXXX", "XXXX", "XXXX", "XXXX" shape you are looking for....
Find out how I generate....coolAlias...world structure generation and rotation tool...
-tlf
Find out how I generate....coolAlias...world structure generation and rotation tool...
-tlf
same for me no errors no nothin just wont open
Specifically, here is the error that I am receiving:
My Main Class:
Block Class:
Container Class:
Crafting Manager Class:
GUI Class:
GUI Handler Class:
Recipe Sorter Class:
Shaped Recipes Class:
Shapeless Recipes Class:
Any help you can spare is greatly appreciated!
Did you guys get your tables to work?
Anyway, I have a custom 1 x 3 crafting table for my mod.
Everything seems to be working, slots are aligned with the texture....
Only issue is the crafting recipes don't work, and by thoroughly scanning my code, can't figure out why...
Here is my code, I plan to upload it to GitHub soon, but for now I'll just post it...
SCMCraftingManager
ShapedRecipesSCM
Finally, ShapelessRecipesSCM
Also, my recipe format is as follows...
Just wondering what's going on... seems to be the only problem I'm running into besides shift-click crash.
If you need to see anything else, I'd be glad to post more code.
Thanks!
Main Class
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
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.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid="alchemycraft2", name="AlchemyCraft 2", version="1.0.0 Alpha")
public class alchemycraft2 {
public static final String modid = "alchemycraft 2";
@SidedProxy(clientSide="alchemycraft2.common.ClientProxy", serverSide="alchemycraft.common.ServerProxy")
public static ServerProxy proxy;
public static CreativeTabs TabAlchemyCraft2 = new TabAlchemyCraft2(CreativeTabs.getNextID(), "AlchemyCraft 2");
//misc
@Instance("alchemycraft2")
public static alchemycraft2 instance;
private GuiHandlerElementorumElit guiHandlerElementorumElit = new GuiHandlerElementorumElit();
//items
public static Item Æther;
public static Item Air;
public static Item Light;
//blocks
public static Block ÆthericRunedStone;
public static Block AirRunedStone;
public static Block ElementorumElit;
@EventHandler
public void init(FMLInitializationEvent Event){
//blocks
ÆthericRunedStone = new ÆthericRunedStone(1001, Material.rock).setUnlocalizedName("ÆthericRunedStone");
GameRegistry.registerBlock(ÆthericRunedStone, "Ætheric Runed Stone");
AirRunedStone = new AirRunedStone(1003, Material.rock).setUnlocalizedName("AirRunedStone");
GameRegistry.registerBlock(AirRunedStone, "Aura Runed Stone");
ElementorumElit = new ElementorumElit(1005, Material.rock).setUnlocalizedName("ElementorumElit");
GameRegistry.registerBlock(ElementorumElit, "Elementorum Elit");
//items
Æther = new Æther(1000).setUnlocalizedName("Æther");
Air = new Air(1002).setUnlocalizedName("Air");
Light = new Light(1004).setUnlocalizedName("Light");
//misc
NetworkRegistry.instance().registerGuiHandler(this, guiHandlerElementorumElit);
//lang reg
LanguageRegistry.addName(Æther, "Æther");
LanguageRegistry.addName(ÆthericRunedStone, "Ætheric Runed Stone");
LanguageRegistry.addName(Air, "Aura");
LanguageRegistry.addName(AirRunedStone, "Aura Runed Stone");
LanguageRegistry.addName(Light, "Lumen");
//recipes
GameRegistry.addShapelessRecipe(new ItemStack(Æther, 1), new Object[] {
alchemycraft2.ÆthericRunedStone, Item.glassBottle
});
GameRegistry.addShapelessRecipe(new ItemStack(Air, 1), new Object[] {
alchemycraft2.AirRunedStone, Item.glassBottle
});
}
}
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
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;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class ContainerElementorumElit extends Container
{
/** The crafting matrix inventory (3x3). */
public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3);
public IInventory craftResult = new InventoryCraftResult();
private World worldObj;
private int posX;
private int posY;
private int posZ;
public ContainerElementorumElit(InventoryPlayer par1InventoryPlayer, World par2World, int par3, int par4, int par5)
{
this.worldObj = par2World;
this.posX = par3;
this.posY = par4;
this.posZ = par5;
this.addSlotToContainer(new SlotCrafting(par1InventoryPlayer.player, 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));
}
}
for (l = 0; l < 3; ++l)
{
for (i1 = 0; i1 < 9; ++i1)
{
this.addSlotToContainer(new Slot(par1InventoryPlayer, i1 + l * 9 + 9, 8 + i1 * 18, 84 + l * 18));
}
}
for (l = 0; l < 9; ++l)
{
this.addSlotToContainer(new Slot(par1InventoryPlayer, l, 8 + l * 18, 142));
}
this.onCraftMatrixChanged(this.craftMatrix);
}
/**
* Callback for when the crafting matrix is changed.
*/
public void onCraftMatrixChanged(IInventory par1IInventory)
{
this.craftResult.setInventorySlotContents(0, CraftingManagerElementorumElit.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj));
}
/**
* Called when the container is closed.
*/
public void onContainerClosed(EntityPlayer par1EntityPlayer)
{
super.onContainerClosed(par1EntityPlayer);
if (!this.worldObj.isRemote)
{
for (int i = 0; i < 9; ++i)
{
ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);
if (itemstack != null)
{
par1EntityPlayer.dropPlayerItem(itemstack);
}
}
}
}
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
{
return this.worldObj.getBlockId(this.posX, this.posY, this.posZ) != alchemycraft2.ElementorumElit.blockID ? false : par1EntityPlayer.getDistanceSq((double)this.posX + 0.5D, (double)this.posY + 0.5D, (double)this.posZ + 0.5D) <= 64.0D;
}
/**
* Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
*/
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
{
ItemStack itemstack = null;
Slot slot = (Slot)this.inventorySlots.get(par2);
if (slot != null && slot.getHasStack())
{
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (par2 == 0)
{
if (!this.mergeItemStack(itemstack1, 10, 46, true))
{
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
else if (par2 >= 10 && par2 < 37)
{
if (!this.mergeItemStack(itemstack1, 37, 46, false))
{
return null;
}
}
else if (par2 >= 37 && par2 < 46)
{
if (!this.mergeItemStack(itemstack1, 10, 37, false))
{
return null;
}
}
else if (!this.mergeItemStack(itemstack1, 10, 46, false))
{
return null;
}
if (itemstack1.stackSize == 0)
{
slot.putStack((ItemStack)null);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.stackSize == itemstack.stackSize)
{
return null;
}
slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
}
return itemstack;
}
public boolean func_94530_a(ItemStack par1ItemStack, Slot par2Slot)
{
return par2Slot.inventory != this.craftResult && super.func_94530_a(par1ItemStack, par2Slot);
}
}
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
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.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid="alchemycraft2", name="AlchemyCraft 2", version="1.0.0 Alpha")
public class alchemycraft2 {
public static final String modid = "alchemycraft 2";
@SidedProxy(clientSide="alchemycraft2.common.ClientProxy", serverSide="alchemycraft.common.ServerProxy")
public static ServerProxy proxy;
public static CreativeTabs TabAlchemyCraft2 = new TabAlchemyCraft2(CreativeTabs.getNextID(), "AlchemyCraft 2");
//misc
@Instance("alchemycraft2")
public static alchemycraft2 instance;
private GuiHandlerElementorumElit guiHandlerElementorumElit = new GuiHandlerElementorumElit();
//items
public static Item Æther;
public static Item Air;
public static Item Light;
//blocks
public static Block ÆthericRunedStone;
public static Block AirRunedStone;
public static Block ElementorumElit;
@EventHandler
public void init(FMLInitializationEvent Event){
//blocks
ÆthericRunedStone = new ÆthericRunedStone(1001, Material.rock).setUnlocalizedName("ÆthericRunedStone");
GameRegistry.registerBlock(ÆthericRunedStone, "Ætheric Runed Stone");
AirRunedStone = new AirRunedStone(1003, Material.rock).setUnlocalizedName("AirRunedStone");
GameRegistry.registerBlock(AirRunedStone, "Aura Runed Stone");
ElementorumElit = new ElementorumElit(1005, Material.rock).setUnlocalizedName("ElementorumElit");
GameRegistry.registerBlock(ElementorumElit, "Elementorum Elit");
//items
Æther = new Æther(1000).setUnlocalizedName("Æther");
Air = new Air(1002).setUnlocalizedName("Air");
Light = new Light(1004).setUnlocalizedName("Light");
//misc
NetworkRegistry.instance().registerGuiHandler(this, guiHandlerElementorumElit);
//lang reg
LanguageRegistry.addName(Æther, "Æther");
LanguageRegistry.addName(ÆthericRunedStone, "Ætheric Runed Stone");
LanguageRegistry.addName(Air, "Aura");
LanguageRegistry.addName(AirRunedStone, "Aura Runed Stone");
LanguageRegistry.addName(Light, "Lumen");
//recipes
GameRegistry.addShapelessRecipe(new ItemStack(Æther, 1), new Object[] {
alchemycraft2.ÆthericRunedStone, Item.glassBottle
});
GameRegistry.addShapelessRecipe(new ItemStack(Air, 1), new Object[] {
alchemycraft2.AirRunedStone, Item.glassBottle
});
}
}
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiElementorumElit extends GuiContainer
{
public static String GuiTexturePrefix = "alchemycraft2" + ":" + "textures/gui/";
private static final ResourceLocation alchemycraft2 = new ResourceLocation(GuiTexturePrefix + "ElementorumElit.png");
public GuiElementorumElit(InventoryPlayer par1InventoryPlayer, World par2World, int par3, int par4, int par5)
{
super(new ContainerElementorumElit(par1InventoryPlayer, par2World, par3, par4, par5));
}
public void onGuiClosed(){
super.onGuiClosed();
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items)
*/
protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
this.fontRenderer.drawString(I18n.getString("Elementorum Elit"), 28, 6, 4210752);
this.fontRenderer.drawString(I18n.getString("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
}
/**
* Draw the background layer for the GuiContainer (everything behind the items)
*/
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(alchemycraft2);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
}
}
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;
public class GuiHandlerElementorumElit implements IGuiHandler {
@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
TileEntity tile_entity = world.getBlockTileEntity(x, y, z);
switch(id)
{
case 0: return id == 0 && world.getBlockId(x, y, z) == alchemycraft2.ElementorumElit.blockID ? new ContainerElementorumElit(player.inventory, world, x, y, z) : null;
}
return null;
}
@Override
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
TileEntity tile_entity = world.getBlockTileEntity(x, y, z);
switch(id)
{
case 0: return id == 0 && world.getBlockId(x, y, z) == alchemycraft2.ElementorumElit.blockID ? new GuiElementorumElit(player.inventory, world, x, y, z) : null;
}
return null;
}
}
import java.util.Comparator;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;
class RecipeSorterElementorumElit implements Comparator
{
final CraftingManagerElementorumElit craftingManagerElementorumElit;
RecipeSorterElementorumElit(CraftingManagerElementorumElit par1CraftingManagerElementorumElit)
{
this.craftingManagerElementorumElit = par1CraftingManagerElementorumElit;
}
public int compareRecipes(IRecipe par1IRecipe, IRecipe par2IRecipe)
{
return par1IRecipe instanceof ShapelessEERecipes && par2IRecipe instanceof ShapedEERecipes ? 1 : (par2IRecipe instanceof ShapelessEERecipes && par1IRecipe instanceof ShapedEERecipes ? -1 : (par2IRecipe.getRecipeSize() < par1IRecipe.getRecipeSize() ? -1 : (par2IRecipe.getRecipeSize() > par1IRecipe.getRecipeSize() ? 1 : 0)));
}
public int compare(Object par1Obj, Object par2Obj)
{
return this.compareRecipes((IRecipe)par1Obj, (IRecipe)par2Obj);
}
}
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
public class ShapedEERecipes implements IRecipe{
/** How many horizontal slots this recipe is wide. */
public final int recipeWidth;
/** How many vertical slots this recipe uses. */
public final int recipeHeight;
/** Is a array of ItemStack that composes the recipe. */
public final ItemStack[] recipeItems;
/** Is the ItemStack that you get when craft the recipe. */
private ItemStack recipeOutput;
/** Is the itemID of the output item that you get when craft the recipe. */
public final int recipeOutputItemID;
private boolean field_92101_f = false;
public ShapedEERecipes(int par1, int par2, ItemStack[] par3ArrayOfItemStack, ItemStack par4ItemStack)
{
this.recipeOutputItemID = par4ItemStack.itemID;
this.recipeWidth = par1;
this.recipeHeight = par2;
this.recipeItems = par3ArrayOfItemStack;
this.recipeOutput = par4ItemStack;
}
public ItemStack getRecipeOutput()
{
return this.recipeOutput;
}
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World)
{
for (int i = 0; i <= 3 - this.recipeWidth; ++i)
{
for (int j = 0; j <= 3 - this.recipeHeight; ++j)
{
if (this.checkMatch(par1InventoryCrafting, i, j, true))
{
return true;
}
if (this.checkMatch(par1InventoryCrafting, i, j, false))
{
return true;
}
}
}
return false;
}
/**
* Checks if the region of a crafting inventory is match for the recipe.
*/
private boolean checkMatch(InventoryCrafting par1InventoryCrafting, int par2, int par3, boolean par4)
{
for (int k = 0; k < 3; ++k)
{
for (int l = 0; l < 3; ++l)
{
int i1 = k - par2;
int j1 = l - par3;
ItemStack itemstack = null;
if (i1 >= 0 && j1 >= 0 && i1 < this.recipeWidth && j1 < this.recipeHeight)
{
if (par4)
{
itemstack = this.recipeItems[this.recipeWidth - i1 - 1 + j1 * this.recipeWidth];
}
else
{
itemstack = this.recipeItems[i1 + j1 * this.recipeWidth];
}
}
ItemStack itemstack1 = par1InventoryCrafting.getStackInRowAndColumn(k, l);
if (itemstack1 != null || itemstack != null)
{
if (itemstack1 == null && itemstack != null || itemstack1 != null && itemstack == null)
{
return false;
}
if (itemstack.itemID != itemstack1.itemID)
{
return false;
}
if (itemstack.getItemDamage() != 32767 && itemstack.getItemDamage() != itemstack1.getItemDamage())
{
return false;
}
}
}
}
return true;
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)
{
ItemStack itemstack = this.getRecipeOutput().copy();
if (this.field_92101_f)
{
for (int i = 0; i < par1InventoryCrafting.getSizeInventory(); ++i)
{
ItemStack itemstack1 = par1InventoryCrafting.getStackInSlot(i);
if (itemstack1 != null && itemstack1.hasTagCompound())
{
itemstack.setTagCompound((NBTTagCompound)itemstack1.stackTagCompound.copy());
}
}
}
return itemstack;
}
/**
* Returns the size of the recipe area
*/
public int getRecipeSize()
{
return this.recipeWidth * this.recipeHeight;
}
public ShapedEERecipes func_92100_c()
{
this.field_92101_f = true;
return this;
}
}
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
public class ShapelessEERecipes implements IRecipe{
/** Is the ItemStack that you get when craft the recipe. */
private final ItemStack recipeOutput;
/** Is a List of ItemStack that composes the recipe. */
public final List recipeItems;
public ShapelessEERecipes(ItemStack par1ItemStack, List par2List)
{
this.recipeOutput = par1ItemStack;
this.recipeItems = par2List;
}
public ItemStack getRecipeOutput()
{
return this.recipeOutput;
}
/**
* Used to check if a recipe matches current crafting inventory
*/
public boolean matches(InventoryCrafting par1InventoryCrafting, World par2World)
{
ArrayList arraylist = new ArrayList(this.recipeItems);
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
{
ItemStack itemstack = par1InventoryCrafting.getStackInRowAndColumn(j, i);
if (itemstack != null)
{
boolean flag = false;
Iterator iterator = arraylist.iterator();
while (iterator.hasNext())
{
ItemStack itemstack1 = (ItemStack)iterator.next();
if (itemstack.itemID == itemstack1.itemID && (itemstack1.getItemDamage() == 32767 || itemstack.getItemDamage() == itemstack1.getItemDamage()))
{
flag = true;
arraylist.remove(itemstack1);
break;
}
}
if (!flag)
{
return false;
}
}
}
}
return arraylist.isEmpty();
}
/**
* Returns an Item that is the result of this recipe
*/
public ItemStack getCraftingResult(InventoryCrafting par1InventoryCrafting)
{
return this.recipeOutput.copy();
}
/**
* Returns the size of the recipe area
*/
public int getRecipeSize()
{
return this.recipeItems.size();
}
}
Thanks
It looks like your crafting manager code is the same as your main modding class. Throw that up and I will have a go at it.
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.item.crafting.ShapedRecipes;
import net.minecraft.item.crafting.ShapelessRecipes;
import net.minecraft.world.World;
public class CraftingManagerElementorumElit
{
/** The static instance of this class */
private static final CraftingManagerElementorumElit instance = new CraftingManagerElementorumElit();
/** A list of all the recipes added */
private List recipes = new ArrayList();
/**
* Returns the static instance of this class
*/
public static final CraftingManagerElementorumElit getInstance()
{
return instance;
}
private CraftingManagerElementorumElit()
{
this.addRecipe(new ItemStack(Item.paper, 3), new Object[] {"###", '#', Item.reed});
Collections.sort(this.recipes, new RecipeSorterElementorumElit(this));
}
public ShapedRecipes addRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj)
{
String s = "";
int i = 0;
int j = 0;
int k = 0;
if (par2ArrayOfObj[i] instanceof String[])
{
String[] astring = (String[])((String[])par2ArrayOfObj[i++]);
for (int l = 0; l < astring.length; ++l)
{
String s1 = astring[l];
++k;
j = s1.length();
s = s + s1;
}
}
else
{
while (par2ArrayOfObj[i] instanceof String)
{
String s2 = (String)par2ArrayOfObj[i++];
++k;
j = s2.length();
s = s + s2;
}
}
HashMap hashmap;
for (hashmap = new HashMap(); i < par2ArrayOfObj.length; i += 2)
{
Character character = (Character)par2ArrayOfObj[i];
ItemStack itemstack1 = null;
if (par2ArrayOfObj[i + 1] instanceof Item)
{
itemstack1 = new ItemStack((Item)par2ArrayOfObj[i + 1]);
}
else if (par2ArrayOfObj[i + 1] instanceof Block)
{
itemstack1 = new ItemStack((Block)par2ArrayOfObj[i + 1], 1, 32767);
}
else if (par2ArrayOfObj[i + 1] instanceof ItemStack)
{
itemstack1 = (ItemStack)par2ArrayOfObj[i + 1];
}
hashmap.put(character, itemstack1);
}
ItemStack[] aitemstack = new ItemStack[j * k];
for (int i1 = 0; i1 < j * k; ++i1)
{
char c0 = s.charAt(i1);
if (hashmap.containsKey(Character.valueOf(c0)))
{
aitemstack[i1] = ((ItemStack)hashmap.get(Character.valueOf(c0))).copy();
}
else
{
aitemstack[i1] = null;
}
}
ShapedRecipes shapedrecipes = new ShapedRecipes(j, k, aitemstack, par1ItemStack);
this.recipes.add(shapedrecipes);
return shapedrecipes;
}
public void addShapelessRecipe(ItemStack par1ItemStack, Object ... par2ArrayOfObj)
{
ArrayList arraylist = new ArrayList();
Object[] aobject = par2ArrayOfObj;
int i = par2ArrayOfObj.length;
for (int j = 0; j < i; ++j)
{
Object object1 = aobject[j];
if (object1 instanceof ItemStack)
{
arraylist.add(((ItemStack)object1).copy());
}
else if (object1 instanceof Item)
{
arraylist.add(new ItemStack((Item)object1));
}
else
{
if (!(object1 instanceof Block))
{
throw new RuntimeException("Invalid shapeless recipy!");
}
arraylist.add(new ItemStack((Block)object1));
}
}
this.recipes.add(new ShapelessRecipes(par1ItemStack, arraylist));
}
public ItemStack findMatchingRecipe(InventoryCrafting par1InventoryCrafting, World par2World)
{
int i = 0;
ItemStack itemstack = null;
ItemStack itemstack1 = null;
int j;
for (j = 0; j < par1InventoryCrafting.getSizeInventory(); ++j)
{
ItemStack itemstack2 = par1InventoryCrafting.getStackInSlot(j);
if (itemstack2 != null)
{
if (i == 0)
{
itemstack = itemstack2;
}
if (i == 1)
{
itemstack1 = itemstack2;
}
++i;
}
}
if (i == 2 && itemstack.itemID == itemstack1.itemID && itemstack.stackSize == 1 && itemstack1.stackSize == 1 && Item.itemsList[itemstack.itemID].isRepairable())
{
Item item = Item.itemsList[itemstack.itemID];
int k = item.getMaxDamage() - itemstack.getItemDamageForDisplay();
int l = item.getMaxDamage() - itemstack1.getItemDamageForDisplay();
int i1 = k + l + item.getMaxDamage() * 5 / 100;
int j1 = item.getMaxDamage() - i1;
if (j1 < 0)
{
j1 = 0;
}
return new ItemStack(itemstack.itemID, 1, j1);
}
else
{
for (j = 0; j < this.recipes.size(); ++j)
{
IRecipe irecipe = (IRecipe)this.recipes.get(j);
if (irecipe.matches(par1InventoryCrafting, par2World))
{
return irecipe.getCraftingResult(par1InventoryCrafting);
}
}
return null;
}
}
/**
* returns the List<> of all recipes
*/
public List getRecipeList()
{
return this.recipes;
}
}
My bad... Looks like I need your block class as well...
Thanks in advance!
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
public class ElementorumElit extends Block
{
@SideOnly(Side.CLIENT)
private Icon workbenchIconTop;
@SideOnly(Side.CLIENT)
private Icon workbenchIconFront;
protected ElementorumElit(int par1, Material rock)
{
super(par1, Material.wood);
this.setCreativeTab(alchemycraft2.TabAlchemyCraft2);
}
@SideOnly(Side.CLIENT)
/**
* From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
*/
public Icon getIcon(int par1, int par2)
{
return par1 == 1 ? this.workbenchIconTop : (par1 == 0 ? Block.planks.getBlockTextureFromSide(par1) : (par1 != 2 && par1 != 4 ? this.blockIcon : this.workbenchIconFront));
}
@SideOnly(Side.CLIENT)
/**
* When this method is called, your block should register all the icons it needs with the given IconRegister. This
* is the only chance you get to register icons.
*/
public void registerIcons(IconRegister par1IconRegister)
{
this.blockIcon = par1IconRegister.registerIcon("alchemycraft2:ElementorumElit_side");
this.workbenchIconTop = par1IconRegister.registerIcon("alchemycraft2:ElementorumElit_top");
this.workbenchIconFront = par1IconRegister.registerIcon("alchemycraft2:ElementorumElit_front");
}
/**
* Called upon block activation (right click on the block.)
*/
public boolean onBlockActivated(World var1, int var2, int var3, int var4, EntityPlayer player, int par6, float par7, float par8, float par9)
{
if (!player.isSneaking())
{
player.openGui(alchemycraft2.instance, 0, var1, var2, var3, var4);
return true;
}
else
{
return false;
}
}
}
I see what you mean, that's a pretty odd behavior. I will dig into it tonight and see what I can find.
I had to comment out the proxies since I didn't have those, but I added this line right below the @Mod.
Also, on your block class further down, I took out the material so it looks like this:
And finally, in your block class, I did this to your constructor:
Give that a buzz and see what happens.
yes that fixed it. Thanks a TON!
You betcha! Can't wait to see the finished mod!