Posted September 28, 201510 yr Hey, I've got my own crafting table, with it's Gui and container. I want the crafting recipes of my mod just to be crafted in the mod's workbench. So I created my own CraftingManager and used this method in my container class: @Override public void onCraftMatrixChanged(IInventory inventoryIn) { this.craftResult.setInventorySlotContents(0, MyCraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj)); } I copied all methods from the CraftingManager to my own one and added my recipes. When I put the items in the correct shape, the result is displayed and I can take it out, but the items in the 3x3 slots are still there. I can take tons of result items, because they are not consumed. I also tried to use the forge CraftingManager. Then all works fine... I don't know what's wrong MyCraftingManager.class (I copied all methods from the original CraftingManager): public class MyCraftingManager { private static final MyCraftingManagerinstance = new MyCraftingManager(); private final List recipes = Lists.newArrayList(); public static MyCraftingManagergetInstance() { return instance; } private MyCraftingManager() { addRecipe(new ItemStack(MyBlocks.MyBlock, 2), new Object[] { "111", "111", "111", '1', Blocks.cobblestone }); Collections.sort(this.recipes, new Comparator() { public int compare(IRecipe rec1, IRecipe rec2) { return rec1 instanceof ShapelessRecipes && rec2 instanceof ShapedRecipes ? 1 : (rec2 instanceof ShapelessRecipes && rec1 instanceof ShapedRecipes ? -1 : (rec2.getRecipeSize() < rec1.getRecipeSize() ? -1 : (rec2.getRecipeSize() > rec1.getRecipeSize() ? 1 : 0))); } public int compare(Object rec1, Object rec2) { return this.compare((IRecipe) rec1, (IRecipe) rec2); } }); } public ShapedRecipes addRecipe(ItemStack stack, Object... recipeComponents) { String s = ""; int i = 0; int j = 0; int k = 0; if (recipeComponents[i] instanceof String[]) { String[] astring = (String[]) ((String[]) recipeComponents[i++]); for (int l = 0; l < astring.length; ++l) { String s1 = astring[l]; ++k; j = s1.length(); s = s + s1; } } else { while (recipeComponents[i] instanceof String) { String s2 = (String) recipeComponents[i++]; ++k; j = s2.length(); s = s + s2; } } HashMap hashmap; for (hashmap = Maps.newHashMap(); i < recipeComponents.length; i += 2) { Character character = (Character) recipeComponents[i]; ItemStack itemstack1 = null; if (recipeComponents[i + 1] instanceof Item) { itemstack1 = new ItemStack((Item) recipeComponents[i + 1]); } else if (recipeComponents[i + 1] instanceof Block) { itemstack1 = new ItemStack((Block) recipeComponents[i + 1], 1, 32767); } else if (recipeComponents[i + 1] instanceof ItemStack) { itemstack1 = (ItemStack) recipeComponents[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, stack); this.recipes.add(shapedrecipes); return shapedrecipes; } public void addShapelessRecipe(ItemStack stack, Object... recipeComponents) { ArrayList arraylist = Lists.newArrayList(); Object[] aobject = recipeComponents; int i = recipeComponents.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 IllegalArgumentException( "Invalid shapeless recipe: unknown type " + object1.getClass().getName() + "!"); } arraylist.add(new ItemStack((Block) object1)); } } this.recipes.add(new ShapelessRecipes(stack, arraylist)); } public void addRecipe(IRecipe recipe) { this.recipes.add(recipe); } public ItemStack findMatchingRecipe(InventoryCrafting inv, World world) { Iterator iterator = this.recipes.iterator(); IRecipe irecipe; do { if (!iterator.hasNext()) { return null; } irecipe = (IRecipe) iterator.next(); } while (!irecipe.matches(inv, world)); return irecipe.getCraftingResult(inv); } public ItemStack[] func_180303_b(InventoryCrafting inv, World world) { Iterator iterator = this.recipes.iterator(); while (iterator.hasNext()) { IRecipe irecipe = (IRecipe) iterator.next(); if (irecipe.matches(inv, world)) { return irecipe.getRemainingItems(inv); } } ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()]; for (int i = 0; i < aitemstack.length; ++i) { aitemstack[i] = inv.getStackInSlot(i); } return aitemstack; } public List getRecipeList() { return this.recipes; } } I think I has to do with this method, but I'm not really sure: public ItemStack[] func_180303_b(InventoryCrafting inv, World world) {}
September 28, 201510 yr read about the keyword extends please. after that go and smash ur head soft against a wall
September 29, 201510 yr damn u mojang. so u just want ur custom CraftingManager, which is basically the same, right? Why not create ur own instance using reflection, instead of just copy pasting the whole code
September 29, 201510 yr Author Yes, I just want my recipes to be crafted just in my workbench.. Could you explain that?
September 29, 201510 yr Could you google that? http://stackoverflow.com/questions/2599440/how-can-i-access-a-private-constructor-of-a-class
September 29, 201510 yr Author I added this to my constructor: public MyCraftingManager() { try { Constructor<CraftingManager> constructor = CraftingManager.class.getDeclaredConstructor(new Class[0]); constructor.setAccessible(true); CraftingManager cm = constructor.newInstance(new Object[0]); } catch (Exception e) { e.printStackTrace(); } } Should I do now cm.addRecipe instead of calling my copied method? This works, but now I can craft vanilla items too and the bigger problem is that the items are still not consumed...
September 29, 201510 yr not sure why u need ur own class. just save the instance in ur main mod class and access it in ur crafting gui. For the problem with removing items, look at SlotCrafting#onPickupFromSlot
September 29, 201510 yr Author Because I need it for the crafting recipes. The container checks if the items are arranged as the recipes added in the constructor. Where do I have to call this? EDIT: I override the method on slot click in the container class.
September 29, 201510 yr if u are only coping methods from the crafting manager u wont need ur own class.
September 30, 201510 yr exactly. just add the recipes to ur custom CraftingManager instance, after that check in ur container if the recipe is valid (using the crafting manager) , and consume the items if the result is taken out
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.