.

Статус
Закрыто для дальнейших ответов.

Mr_RoboMan

Старожил
Пользователь
Баллы
123
.
 
Последнее редактирование:
Проверять по компонентам, схеме и результату, только так.
 
Собственно так.
Состряпал я вот такой вот код:
Код:
    @Override
    public boolean equals(Object obj) {
        if (obj == this) return true;
        if (obj == null) return false;
        if (obj instanceof ShapedRecipe) {
            ShapedRecipe shaped_recipe = (ShapedRecipe) obj;
            if (!TextItemStack.equals(this.getResult(), shaped_recipe.getResult())) return false;
            for (int i = 0; i < 3; i++) {
                String my_shape = this.getShape()[i];
                String recipe_shape = shaped_recipe.getShape()[i];
                if (!my_shape.equals(recipe_shape)) return false;
            }
            Map<Character, ItemStack> my_map = this.getIngredientMap();
            Map<Character, ItemStack> recipe_map = shaped_recipe.getIngredientMap();
            return my_map.equals(recipe_map);
        } else return false;
    }
Он вроде даже работает.
Но только если как "ключи" рецепта использовать ТОЛЬКО символы нижнего регистра.
(Это так для потомков :D (ну или просто для тех у кого будет такая-же проблема))
P.S. Ну и полный код класса.. На всякий)
Код:
package ua.gwm.bukkit_plugin.gwm_library;

import org.bukkit.Bukkit;
import org.*********ventory.ItemStack;
import org.*********ventory.ShapedRecipe;

import java.util.Map;

public class AdvancedShapedRecipe extends ShapedRecipe {

    public static final char[] symbols = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'};

    private ItemStack[] craft;

    public AdvancedShapedRecipe(ItemStack result, ItemStack[] craft) {
        super(result);
        if (craft.length != 9) throw new RuntimeException("ItemStack[] craft length must be 9.");
        this.craft = craft;
    }

    public void activate() {
        String[] shapes = {"", "", ""};
        for (int i = 0; i < 3; i++) shapes[0] += craft[i] == null ? " " : symbols[i];
        for (int i = 3; i < 6; i++) shapes[1] += craft[i] == null ? " " : symbols[i];
        for (int i = 6; i < 9; i++) shapes[2] += craft[i] == null ? " " : symbols[i];
        shape(shapes);
        for (int i = 0; i < 9; i++) if (craft[i] != null) setIngredient(symbols[i], craft[i].getType());
        Bukkit.getServer().addRecipe(this);
    }

    public ItemStack[] getCraft() {
        return craft;
    }

    public void setCraft(ItemStack[] craft) {
        if (craft.length != 9) throw new RuntimeException("ItemStack[] craft length must be 9.");
        this.craft = craft;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) return true;
        if (obj == null) return false;
        if (obj instanceof ShapedRecipe) {
            ShapedRecipe shaped_recipe = (ShapedRecipe) obj;
            if (!TextItemStack.equals(this.getResult(), shaped_recipe.getResult())) return false;
            for (int i = 0; i < 3; i++) {
                String my_shape = this.getShape()[i];
                String recipe_shape = shaped_recipe.getShape()[i];
                if (!my_shape.equals(recipe_shape)) return false;
            }
            Map<Character, ItemStack> my_map = this.getIngredientMap();
            Map<Character, ItemStack> recipe_map = shaped_recipe.getIngredientMap();
            return my_map.equals(recipe_map);
        } else return false;
    }
}
Темку тоже оставлю открытой, авось кто решение лучше придумает... Хотя я вроде все сделяль красивенько...
Ска. Обманул меня
 
Статус
Закрыто для дальнейших ответов.
Назад
Верх