Solved ItemStack Material comparison problem

Discussion in 'Plugin Development' started by MX26, Feb 28, 2016.

Thread Status:
Not open for further replies.
  1. Offline


    SO, i'm making a custom crafting systm plugin, and just as i thought i'm done with it, i found out that my recipe comparison isn't working. No matter what i do, 2 ItemStacks from the 2 arrays are never equal.

    Inventory to crafting recipe method:
        public ItemStack[][] invToRecipe(Inventory craftInv){
            ItemStack[][] matrix=new ItemStack[3][3];
            for(int i=0; i<3; i++){
                for(int j=0; j<3; j++){
            return matrix; //"matrix" gets directly returned to the checkForRecipe method
    Recipe checker:
    public void checkForRecipe(ItemStack[][] input, Inventory inv){
            boolean tester = true;
            Server server = this.getServer();
            for(int i=0; i<Recipes.size(); i++){
                ItemStack[][] temp = Recipes.get(i).recipe;
                this.getServer().broadcastMessage("it enters the check");
                for(int x=0; x<3; x++){
                    for(int y=0; y<3; y++){
                        if(input[x][y] == null){
                            input[x][y]=new ItemStack(Material.AIR);
                        if(temp[x][y] == null){
                            temp[x][y]=new ItemStack(Material.AIR);
                            server.broadcastMessage(input[x][y].getData().toString() + " | " + temp[x][y].getData().toString());
                    inv.setItem(23, Recipes.get(i).output);
    In my mind this should work, and even in the server broadcasts all the "input[x][y].getData()" and "temp[x][y].getData()" are the same for the 1st recipe (see uploaded screenshot), but the if always returns that they aren't equal for whatever reason.

    Any help is appreciated :)

    Attached Files:

  2. Offline


    Wrong comparison tool for itemstacks. Use ".equal" or bukkit's ".isSimular" to test itemstacks. Google "== vs equals" if you do not know the difference.
  3. Offline



    Just thought of using equals this morning as well. Lesson learned I guess, don't code half asleep...
Thread Status:
Not open for further replies.

Share This Page