Bug no meu Minecraft 2D

0 respostas
java
CloudyYard

oi pessoal!,
eu estou desenvolvendo um minecraft 2d
só que estou tendo um problema para programar o Craft…
quando eu programo para fazer uma recipe de 1MADEIRA = 4TABUAS
ele nao funciona exatamente como devia.
se eu colocar 5 madeiras na mesa de trabalho e clicar 5 vezes
ele deveria aparecer no mouse 20 tabuas mas nao acontece aparece
40 porque a cada click deveria aparecer 4 no mouse mas só no primeiro
click que aparece quatro depois fica pulando de 9 em 9…

source:
package pdev.game;

import java.awt.Color;

import java.awt.Graphics;

import java.awt.Point;

import java.awt.Rectangle;

import java.awt.event.MouseEvent;
public class WorkBench {

public static Cell[] workBench = new Cell[Tile.workBenchLength * Tile.workBenchHeight];

public static Cell[] product = new Cell[Tile.productLength * Tile.productHeight];

private static boolean isHolding = false;

public static boolean isOpen = false;
public static int[] holdingID = Tile.air;
public static int holdingIDStack = 0;
private int yOffSet = 150;

public WorkBench() {
    int x = 0, y = 0;
    for (int i = 0; i < workBench.length; i++) {
        workBench[i] = new Cell(new Rectangle((Component.pixel.width >> 1) - ((Tile.workBenchLength * (Tile.invCellSize + Tile.invCellSpace)) >> 1) + (x * (Tile.invCellSize + Tile.invCellSpace)), Component.pixel.height - (Tile.invCellSize + Tile.invBorderSpace) - (Tile.workBenchHeight * (Tile.invCellSize + Tile.invCellSpace)) + (y * (Tile.invCellSize + Tile.invCellSpace)) - (yOffSet), Tile.invCellSize, Tile.invCellSize), Tile.air, 0);

        x++;
        if (x == Tile.workBenchLength) {
            x = 0;
            y++;
        }
    }
    for (int i = 0; i < product.length; i++) {
        product[i] = new Cell(new Rectangle((Component.pixel.width >> 1) - ((Tile.productLength * (Tile.invCellSize + Tile.invCellSpace)) >> 1) + (x * (Tile.invCellSize + Tile.invCellSpace)) + 58, Component.pixel.height - (Tile.invCellSize + Tile.invBorderSpace) - (Tile.productHeight * (Tile.invCellSize + Tile.invCellSpace)) + (y * (Tile.invCellSize + Tile.invCellSpace)) - (yOffSet + 116), Tile.invCellSize, Tile.invCellSize), Tile.air, 0);

        x++;
        if (x == Tile.productLength) {
            x = 0;
            y++;
        }
    }
}

public static void click(MouseEvent e) {
    if (e.getButton() == MouseEvent.BUTTON1) {
        if (isOpen) {
            for (int i = 0; i < workBench.length; i++) {
                if (workBench[i].contains(new Point(Component.mse.x / Component.pixelSize, Component.mse.y / Component.pixelSize))) {
                    if (workBench[i].id != Tile.air && !isHolding) {
                        holdingIDStack = workBench[i].stack;
                        holdingID = workBench[i].id;
                        workBench[i].id = Tile.air;
                        workBench[i].stack = 0;

                        isHolding = true;
                    } else if (isHolding && workBench[i].id == Tile.air) {
                        workBench[i].stack = holdingIDStack;
                        workBench[i].id = holdingID;

                        isHolding = false;
                    } else if (isHolding && workBench[i].id != Tile.air) {
                        int scon = workBench[i].stack;
                        int[] con = workBench[i].id;

                        if (holdingID == con && holdingIDStack + scon <= Inventory.maxStack) {
                            workBench[i].stack = holdingIDStack + scon;
                            workBench[i].id = holdingID;
                            holdingID = Tile.air;
                            holdingIDStack = 0;
                        } else {
                            workBench[i].stack = holdingIDStack;
                            workBench[i].id = holdingID;

                            holdingIDStack = scon;
                            holdingID = con;
                        }
                    }
                }
            }
            for (int i = 0; i < product.length; i++) {
                if (product[i].contains(new Point(Component.mse.x / Component.pixelSize, Component.mse.y / Component.pixelSize))) {
                    if (product[i].id != Tile.air && !isHolding) {

                        for (int w = 0; w < workBench.length; w++) {
                            if (workBench[w].id != Tile.air) {
                                workBench[w].stack--;
                            }
                        }
                        holdingIDStack = product[i].stack;
                        holdingID = product[i].id;
                        product[i].id = Tile.air;
                        product[i].stack = 0;
                        isHolding = true;
                    } else if (holdingID == product[i].id && holdingIDStack + product[i].stack <= Inventory.maxStack) {
                        for (int w = 0; w < workBench.length; w++) {
                            if (workBench[w].id != Tile.air) {
                                workBench[w].stack--;
                            }
                            holdingIDStack++; // acho que o erro esta aqui
                            product[i].stack--;
                        }
                    }
                }
            }
            for (int i = 0; i < Inventory.invBar.length; i++) {
                if (Inventory.invBar[i].contains(new Point(Component.mse.x / Component.pixelSize, Component.mse.y / Component.pixelSize))) {
                    if (Inventory.invBar[i].id != Tile.air && !isHolding) {
                        holdingIDStack = Inventory.invBar[i].stack;
                        holdingID = Inventory.invBar[i].id;
                        Inventory.invBar[i].id = Tile.air;
                        Inventory.invBar[i].stack = 0;

                        isHolding = true;
                    } else if (isHolding && Inventory.invBar[i].id == Tile.air) {
                        Inventory.invBar[i].stack = holdingIDStack;
                        Inventory.invBar[i].id = holdingID;

                        isHolding = false;
                    } else if (isHolding && Inventory.invBar[i].id != Tile.air) {
                        int scon = Inventory.invBar[i].stack;
                        int[] con = Inventory.invBar[i].id;

                        if (holdingID == con && holdingIDStack + scon <= Inventory.maxStack) {
                            Inventory.invBar[i].stack = holdingIDStack + scon;
                            Inventory.invBar[i].id = holdingID;
                            holdingID = Tile.air;
                            holdingIDStack = 0;
                        } else {
                            Inventory.invBar[i].stack = holdingIDStack;
                            Inventory.invBar[i].id = holdingID;

                            holdingIDStack = scon;
                            holdingID = con;
                        }
                    }
                }
            }

            for (int i = 0; i < Inventory.invBag.length; i++) {
                if (Inventory.invBag[i].contains(new Point(Component.mse.x / Component.pixelSize, Component.mse.y / Component.pixelSize))) {
                    if (Inventory.invBag[i].id != Tile.air && !isHolding) {
                        holdingIDStack = Inventory.invBag[i].stack;
                        holdingID = Inventory.invBag[i].id;
                        Inventory.invBag[i].id = Tile.air;
                        Inventory.invBag[i].stack = 0;

                        isHolding = true;
                    } else if (isHolding && Inventory.invBag[i].id == Tile.air) {
                        Inventory.invBag[i].stack = holdingIDStack;
                        Inventory.invBag[i].id = holdingID;

                        isHolding = false;
                    } else if (isHolding && Inventory.invBag[i].id != Tile.air) {
                        int scon = Inventory.invBag[i].stack;
                        int[] con = Inventory.invBag[i].id;

                        if (holdingID == con && holdingIDStack + scon <= Inventory.maxStack) {
                            Inventory.invBag[i].stack = holdingIDStack + scon;
                            Inventory.invBag[i].id = holdingID;
                            holdingID = Tile.air;
                            holdingIDStack = 0;
                        } else {
                            Inventory.invBag[i].stack = holdingIDStack;
                            Inventory.invBag[i].id = holdingID;

                            holdingIDStack = scon;
                            holdingID = con;
                        }
                    }
                }
            }
        }
    } else if (e.getButton() == MouseEvent.BUTTON3) {
        if (isOpen) {
            for (int i = 0; i < workBench.length; i++) {
                if (workBench[i].contains(new Point(Component.mse.x / Component.pixelSize, Component.mse.y / Component.pixelSize))) {
                    if (isHolding && holdingID != Tile.air) {
                        if (workBench[i].id == Tile.air) {
                            workBench[i].id = holdingID;
                            workBench[i].stack++;
                            holdingIDStack--;
                        } else if (workBench[i].id == holdingID && holdingIDStack + workBench[i].stack < Inventory.maxStack) {
                            workBench[i].stack++;
                            holdingIDStack--;
                        }
                    }
                }
            }
            for (int i = 0; i < Inventory.invBar.length; i++) {
                if (Inventory.invBar[i].contains(new Point(Component.mse.x / Component.pixelSize, Component.mse.y / Component.pixelSize))) {
                    if (isHolding && holdingID != Tile.air) {
                        if (Inventory.invBar[i].id == Tile.air) {
                            Inventory.invBar[i].id = holdingID;
                            Inventory.invBar[i].stack++;
                            holdingIDStack--;
                        } else if (Inventory.invBar[i].id == holdingID && holdingIDStack + Inventory.invBar[i].stack < Inventory.maxStack) {
                            Inventory.invBar[i].stack++;
                            holdingIDStack--;
                        }
                    }
                }
            }
            for (int i = 0; i < Inventory.invBag.length; i++) {
                if (Inventory.invBag[i].contains(new Point(Component.mse.x / Component.pixelSize, Component.mse.y / Component.pixelSize))) {
                    if (isHolding && holdingID != Tile.air) {
                        if (Inventory.invBag[i].id == Tile.air) {
                            Inventory.invBag[i].id = holdingID;
                            Inventory.invBag[i].stack++;
                            holdingIDStack--;
                        } else if (Inventory.invBag[i].id == holdingID && holdingIDStack + Inventory.invBag[i].stack < Inventory.maxStack) {
                            Inventory.invBag[i].stack++;
                            holdingIDStack--;
                        }
                    }
                }
            }
        }
    }
}

public void checkRecipes() {
    new Recipes();
}

public static void recipe(int[] tile1, int[] tile2, int[] tile3, int[] tile4, int[] tile5, int[] tile6, int[] tile7, int[] tile8, int[] tile9, int[] result, int amount) {
    if (workBench[0].id == tile1 && workBench[1].id == tile2 && workBench[2].id == tile3 && workBench[3].id == tile4 && workBench[4].id == tile5 && workBench[5].id == tile6 && workBench[6].id == tile7 && workBench[7].id == tile8 && workBench[8].id == tile9) {
        product[0].id = result;
        product[0].stack = amount;
    } else if (WorkBench.product[0].id == result) {
        product[0].id = Tile.air;
        product[0].stack = 0;
    }
}

public void render(Graphics g) {

    if (holdingIDStack <= 0) {
        holdingIDStack = 0;
        holdingID = Tile.air;
        isHolding = false;
    }

    if (isOpen) {
        for (int i = 0; i < workBench.length; i++) {
            workBench[i].render(g, false);
        }
        for (int i = 0; i < product.length; i++) {
            product[i].render(g, false);
        }
        for (int i = 0; i < Inventory.invBag.length; i++) {
            Inventory.invBag[i].render(g, false);
        }
    }

    if (isHolding) {
        if(holdingID[2] == 0) {
            g.drawImage(Tile.tileset_terrain, (Component.mse.x / Component.pixelSize) - (Tile.invCellSize / 2) + Tile.invItemBorder, (Component.mse.y / Component.pixelSize) - (Tile.invCellSize / 2) + Tile.invItemBorder, (Component.mse.x / Component.pixelSize) - (Tile.invCellSize / 2) + Tile.invCellSize - Tile.invItemBorder, (Component.mse.y / Component.pixelSize) - (Tile.invCellSize / 2) + Tile.invCellSize - Tile.invItemBorder, holdingID[0] * Tile.tileSize, holdingID[1] * Tile.tileSize, holdingID[0] * Tile.tileSize + Tile.tileSize, holdingID[1] * Tile.tileSize + Tile.tileSize, null);
        } else if(holdingID[2] == 1) {
            g.drawImage(Tile.tileset_items, (Component.mse.x / Component.pixelSize) - (Tile.invCellSize / 2) + Tile.invItemBorder, (Component.mse.y / Component.pixelSize) - (Tile.invCellSize / 2) + Tile.invItemBorder, (Component.mse.x / Component.pixelSize) - (Tile.invCellSize / 2) + Tile.invCellSize - Tile.invItemBorder, (Component.mse.y / Component.pixelSize) - (Tile.invCellSize / 2) + Tile.invCellSize - Tile.invItemBorder, holdingID[0] * Tile.tileSize, holdingID[1] * Tile.tileSize, holdingID[0] * Tile.tileSize + Tile.tileSize, holdingID[1] * Tile.tileSize + Tile.tileSize, null);
        }
        if (holdingIDStack > 0) {
            g.setColor(Color.white);
            g.drawString("" + holdingIDStack, (Component.mse.x / Component.pixelSize) - (Tile.invCellSize / Component.pixelSize), (Component.mse.y / Component.pixelSize) + (Tile.invCellSize / Component.pixelSize));
        }
    }
}

}`

podem me ajudar?

Criado 18 de março de 2016
Respostas 0
Participantes 1