java类org.bukkit.inventory.Recipe的实例源码

ListRecipesCommandExecutor.java 文件源码 项目:CustomRecipes 阅读 23 收藏 0 点赞 0 评论 0
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (args.length == 0) return false;

    String recipeType = args[0];
    List<? extends Recipe> recipes = recipesByTypeMapper.apply(recipeType);

    if (recipes == null) {
        sender.sendMessage(ChatColor.RED + "Unknown recipe type: " + recipeType);
        return true;
    } else if (recipes.isEmpty()) {
        sender.sendMessage(ChatColor.RED + "No recipes found for type: " + recipeType);
        return true;
    }

    return sender instanceof Player ? listPlayer((Player) sender, recipeType, recipes) : listSender(sender, recipeType, recipes);
}
CraftServer.java 文件源码 项目:Uranium 阅读 17 收藏 0 点赞 0 评论 0
@Override
public List<Recipe> getRecipesFor(ItemStack result) {
    Validate.notNull(result, "Result cannot be null");

    List<Recipe> results = new ArrayList<Recipe>();
    Iterator<Recipe> iter = recipeIterator();
    while (iter.hasNext()) {
        Recipe recipe = iter.next();
        ItemStack stack = recipe.getResult();
        if (stack.getType() != result.getType()) {
            continue;
        }
        if (result.getDurability() == -1 || result.getDurability() == stack.getDurability()) {
            results.add(recipe);
        }
    }
    return results;
}
CraftingModule.java 文件源码 项目:ProjectAres 阅读 19 收藏 0 点赞 0 评论 0
public Recipe parseShapelessRecipe(MapModuleContext context, Element elRecipe) throws InvalidXMLException {
    ShapelessRecipe recipe = new ShapelessRecipe(parseRecipeResult(context, elRecipe));

    for(Element elIngredient : XMLUtils.getChildren(elRecipe, "ingredient", "i")) {
        MaterialPattern item = XMLUtils.parseMaterialPattern(elIngredient);
        int count = XMLUtils.parseNumber(elIngredient.getAttribute("amount"), Integer.class, 1);
        if(item.dataMatters()) {
            recipe.addIngredient(count, item.getMaterialData());
        } else {
            recipe.addIngredient(count, item.getMaterial());
        }
    }

    if(recipe.getIngredientList().isEmpty()) {
        throw new InvalidXMLException("Crafting recipe must have at least one ingredient", elRecipe);
    }

    return recipe;
}
CraftServer.java 文件源码 项目:ThermosRebased 阅读 27 收藏 0 点赞 0 评论 0
@Override
public List<Recipe> getRecipesFor(ItemStack result) {
    Validate.notNull(result, "Result cannot be null");

    List<Recipe> results = new ArrayList<Recipe>();
    Iterator<Recipe> iter = recipeIterator();
    while (iter.hasNext()) {
        Recipe recipe = iter.next();
        ItemStack stack = recipe.getResult();
        if (stack.getType() != result.getType()) {
            continue;
        }
        if (result.getDurability() == -1 || result.getDurability() == stack.getDurability()) {
            results.add(recipe);
        }
    }
    return results;
}
TestServer.java 文件源码 项目:ExilePearl 阅读 24 收藏 0 点赞 0 评论 0
@Override
public List<Recipe> getRecipesFor(ItemStack result) {
       Validate.notNull(result, "Result cannot be null");

       List<Recipe> results = new ArrayList<Recipe>();
       Iterator<Recipe> iter = recipeIterator();
       while (iter.hasNext()) {
           Recipe recipe = iter.next();
           ItemStack stack = recipe.getResult();
           if (stack.getType() != result.getType()) {
               continue;
           }
           if (result.getDurability() == -1 || result.getDurability() == stack.getDurability()) {
               results.add(recipe);
           }
       }
       return results;
}
CraftServer.java 文件源码 项目:Thermos 阅读 19 收藏 0 点赞 0 评论 0
@Override
public List<Recipe> getRecipesFor(ItemStack result) {
    Validate.notNull(result, "Result cannot be null");

    List<Recipe> results = new ArrayList<Recipe>();
    Iterator<Recipe> iter = recipeIterator();
    while (iter.hasNext()) {
        Recipe recipe = iter.next();
        ItemStack stack = recipe.getResult();
        if (stack.getType() != result.getType()) {
            continue;
        }
        if (result.getDurability() == -1 || result.getDurability() == stack.getDurability()) {
            results.add(recipe);
        }
    }
    return results;
}
CraftServer.java 文件源码 项目:KCauldron 阅读 34 收藏 0 点赞 0 评论 0
@Override
public List<Recipe> getRecipesFor(ItemStack result) {
    Validate.notNull(result, "Result cannot be null");

    List<Recipe> results = new ArrayList<Recipe>();
    Iterator<Recipe> iter = recipeIterator();
    while (iter.hasNext()) {
        Recipe recipe = iter.next();
        ItemStack stack = recipe.getResult();
        if (stack.getType() != result.getType()) {
            continue;
        }
        if (result.getDurability() == -1 || result.getDurability() == stack.getDurability()) {
            results.add(recipe);
        }
    }
    return results;
}
CraftServer.java 文件源码 项目:CauldronGit 阅读 22 收藏 0 点赞 0 评论 0
@Override
public List<Recipe> getRecipesFor(ItemStack result) {
    Validate.notNull(result, "Result cannot be null");

    List<Recipe> results = new ArrayList<Recipe>();
    Iterator<Recipe> iter = recipeIterator();
    while (iter.hasNext()) {
        Recipe recipe = iter.next();
        ItemStack stack = recipe.getResult();
        if (stack.getType() != result.getType()) {
            continue;
        }
        if (result.getDurability() == -1 || result.getDurability() == stack.getDurability()) {
            results.add(recipe);
        }
    }
    return results;
}
RecipeSnapshotTest.java 文件源码 项目:craftinomicon 阅读 21 收藏 0 点赞 0 评论 0
@Test
public void oakPlanksHaveAtLeastOneRecipe() {
    Iterator<Recipe> iterator = Bukkit.getServer().recipeIterator();
    while (iterator.hasNext()) {
        Recipe recipe = iterator.next();
        SortedSet<ItemStack> ingredients = ingredientsGetter.getIngredients(recipe);

        boolean shownOutput = false;
        for (ItemStack ingredient : ingredients) {
            if (ingredient.getType().equals(Material.WOOD)) {
                if (!shownOutput) {
                    shownOutput = true;
                }
                MaterialData data = ingredient.getData();
            }
        }
    }
}
RecipeSnapshotTest.java 文件源码 项目:craftinomicon 阅读 19 收藏 0 点赞 0 评论 0
@Test
public void realTest() {
    MaterialRecipes materialRecipes = recipeSnapshot.getMaterialRecipes(new MaterialData(Material.WORKBENCH));
    Collection<Recipe> recipes = materialRecipes.getRecipes();
    assertEqual(recipes.size(), 1);
    Recipe first = recipes.iterator().next();
    SortedSet<ItemStack> ingredients = ingredientsGetter.getIngredients(first);
    for (ItemStack ingredient : ingredients) {
        if (ingredient != null) {
            assertEqual(ingredient.getData().getData(), (byte)-1);
        }
    }

    MaterialRecipes recipes1 = recipeSnapshot.getMaterialRecipes(new MaterialData(Material.WOOD_STAIRS));
    assertEqual(recipes1.getRecipes().size(), 1);
    Recipe theRecipe = recipes1.getRecipes().iterator().next();
    SortedSet<ItemStack> stairsIngredients = ingredientsGetter.getIngredients(theRecipe);
    for (ItemStack stairsIngredient : stairsIngredients) {
        if (stairsIngredient != null) {
            assertEqual(stairsIngredient.getData().getData(), (byte)0);
        }
    }

    Bukkit.getServer().broadcastMessage("realtest passed");
}
RecipeSnapshotTest.java 文件源码 项目:craftinomicon 阅读 19 收藏 0 点赞 0 评论 0
@Test
public void jungleWoodPlanksCanCreateCraftingTableAndJungleWoodStairs() {
    Tree planks = new Tree(Material.WOOD);
    planks.setSpecies(TreeSpecies.JUNGLE);
    MaterialRecipes materialRecipes = recipeSnapshot.getMaterialRecipes(planks);
    boolean foundWorkBench = false;
    boolean foundJungleWoodPlanks = false;
    for (Recipe recipe : materialRecipes.getUsages()) {
        ItemStack result = recipe.getResult();
        if (Material.WORKBENCH.equals(result.getType())) {
            foundWorkBench = true;
        } else if (Material.JUNGLE_WOOD_STAIRS.equals(result.getType())) {
            foundJungleWoodPlanks = true;
        }
    }
    assertEqual(true, foundWorkBench);
    assertEqual(true, foundJungleWoodPlanks);
}
CraftServer.java 文件源码 项目:Cauldron-Old 阅读 28 收藏 0 点赞 0 评论 0
@Override
public List<Recipe> getRecipesFor(ItemStack result) {
    Validate.notNull(result, "Result cannot be null");

    List<Recipe> results = new ArrayList<Recipe>();
    Iterator<Recipe> iter = recipeIterator();
    while (iter.hasNext()) {
        Recipe recipe = iter.next();
        ItemStack stack = recipe.getResult();
        if (stack.getType() != result.getType()) {
            continue;
        }
        if (result.getDurability() == -1 || result.getDurability() == stack.getDurability()) {
            results.add(recipe);
        }
    }
    return results;
}
CraftServer_188.java 文件源码 项目:DiffUtils 阅读 19 收藏 0 点赞 0 评论 0
@Override
public List<Recipe> getRecipesFor(ItemStack result) {
    Validate.notNull(result, "Result cannot be null");

    List<Recipe> results = new ArrayList<Recipe>();
    Iterator<Recipe> iter = recipeIterator();
    while (iter.hasNext()) {
        Recipe recipe = iter.next();
        ItemStack stack = recipe.getResult();
        if (stack.getType() != result.getType()) {
            continue;
        }
        if (result.getDurability() == -1 || result.getDurability() == stack.getDurability()) {
            results.add(recipe);
        }
    }
    return results;
}
CraftServer_1710.java 文件源码 项目:DiffUtils 阅读 26 收藏 0 点赞 0 评论 0
@Override
public List<Recipe> getRecipesFor(ItemStack result) {
    Validate.notNull(result, "Result cannot be null");

    List<Recipe> results = new ArrayList<Recipe>();
    Iterator<Recipe> iter = recipeIterator();
    while (iter.hasNext()) {
        Recipe recipe = iter.next();
        ItemStack stack = recipe.getResult();
        if (stack.getType() != result.getType()) {
            continue;
        }
        if (result.getDurability() == -1 || result.getDurability() == stack.getDurability()) {
            results.add(recipe);
        }
    }
    return results;
}
CraftServer.java 文件源码 项目:Cauldron-Reloaded 阅读 20 收藏 0 点赞 0 评论 0
@Override
public List<Recipe> getRecipesFor(ItemStack result) {
    Validate.notNull(result, "Result cannot be null");

    List<Recipe> results = new ArrayList<Recipe>();
    Iterator<Recipe> iter = recipeIterator();
    while (iter.hasNext()) {
        Recipe recipe = iter.next();
        ItemStack stack = recipe.getResult();
        if (stack.getType() != result.getType()) {
            continue;
        }
        if (result.getDurability() == -1 || result.getDurability() == stack.getDurability()) {
            results.add(recipe);
        }
    }
    return results;
}
BukkitItemManager.java 文件源码 项目:Zephyr 阅读 23 收藏 0 点赞 0 评论 0
@Override
public void registerItem(Item item) {
    this.itemMap.put(item.getItemName(), item);
    if (item instanceof ActionItem) {
        this.actionMap.put(item.getItemName(), (ActionItem)item);
    }
    if (item instanceof Listener) {
        Bukkit.getPluginManager().registerEvents((Listener)item, ZephyrPlugin.getInstance());
    }

    if (item.getRecipe() != null) {
        @SuppressWarnings("deprecation")
        ItemStack stack = new ItemStack(item.getItemId(), 1);
        ItemMeta meta = stack.getItemMeta();
        meta.setDisplayName(item.getItemNameColor() + item.getItemName());
        meta.setLore(item.getItemLore());
        stack.setItemMeta(meta);
        stack.setDurability((short)item.getItemData());
        Recipe recipe = createRecipe(item.getRecipe(), stack);
        Bukkit.addRecipe(recipe);
    }
}
CraftServer.java 文件源码 项目:FFoKC 阅读 35 收藏 0 点赞 0 评论 0
@Override
public List<Recipe> getRecipesFor(ItemStack result) {
    Validate.notNull(result, "Result cannot be null");

    List<Recipe> results = new ArrayList<Recipe>();
    Iterator<Recipe> iter = recipeIterator();
    while (iter.hasNext()) {
        Recipe recipe = iter.next();
        ItemStack stack = recipe.getResult();
        if (stack.getType() != result.getType()) {
            continue;
        }
        if (result.getDurability() == -1 || result.getDurability() == stack.getDurability()) {
            results.add(recipe);
        }
    }
    return results;
}
RecipeIterator.java 文件源码 项目:CraftBukkit 阅读 25 收藏 0 点赞 0 评论 0
public Recipe next() {
    if (recipes.hasNext()) {
        removeFrom = recipes;
        return recipes.next().toBukkitRecipe();
    } else {
        net.minecraft.server.ItemStack item;
        if (smeltingCustom.hasNext()) {
            removeFrom = smeltingCustom;
            item = smeltingCustom.next();
        } else {
            removeFrom = smeltingVanilla;
            item = smeltingVanilla.next();
        }

        CraftItemStack stack = CraftItemStack.asCraftMirror(RecipesFurnace.getInstance().getResult(item));

        return new CraftFurnaceRecipe(stack, CraftItemStack.asCraftMirror(item));
    }
}
CraftServer.java 文件源码 项目:CraftBukkit 阅读 19 收藏 0 点赞 0 评论 0
@Override
public List<Recipe> getRecipesFor(ItemStack result) {
    Validate.notNull(result, "Result cannot be null");

    List<Recipe> results = new ArrayList<Recipe>();
    Iterator<Recipe> iter = recipeIterator();
    while (iter.hasNext()) {
        Recipe recipe = iter.next();
        ItemStack stack = recipe.getResult();
        if (stack.getType() != result.getType()) {
            continue;
        }
        if (result.getDurability() == -1 || result.getDurability() == stack.getDurability()) {
            results.add(recipe);
        }
    }
    return results;
}
RecipeIterator.java 文件源码 项目:Craftbukkit 阅读 20 收藏 0 点赞 0 评论 0
public Recipe next() {
    if (recipes.hasNext()) {
        removeFrom = recipes;
        return recipes.next().toBukkitRecipe();
    } else {
        net.minecraft.server.ItemStack item;
        if (smeltingCustom.hasNext()) {
            removeFrom = smeltingCustom;
            item = smeltingCustom.next();
        } else {
            removeFrom = smeltingVanilla;
            item = smeltingVanilla.next();
        }

        CraftItemStack stack = CraftItemStack.asCraftMirror(RecipesFurnace.getInstance().getResult(item));

        return new CraftFurnaceRecipe(stack, CraftItemStack.asCraftMirror(item));
    }
}
CraftServer.java 文件源码 项目:Craftbukkit 阅读 20 收藏 0 点赞 0 评论 0
@Override
public List<Recipe> getRecipesFor(ItemStack result) {
    Validate.notNull(result, "Result cannot be null");

    List<Recipe> results = new ArrayList<Recipe>();
    Iterator<Recipe> iter = recipeIterator();
    while (iter.hasNext()) {
        Recipe recipe = iter.next();
        ItemStack stack = recipe.getResult();
        if (stack.getType() != result.getType()) {
            continue;
        }
        if (result.getDurability() == -1 || result.getDurability() == stack.getDurability()) {
            results.add(recipe);
        }
    }
    return results;
}
NetherPortalBlock.java 文件源码 项目:BelovedBlocks 阅读 29 收藏 0 点赞 0 评论 0
@Override
public Iterable<Recipe> getCraftingRecipes()
{
    ShapedRecipe portalRecipe = new ShapedRecipe(makeItem(getAmountPerCraft()));

    portalRecipe.shape("BOB", "PCP", "OPO");

    Dye purpleDye = new Dye(Material.INK_SACK);
    purpleDye.setColor(DyeColor.PURPLE);

    portalRecipe.setIngredient('B', Material.BLAZE_POWDER);
    portalRecipe.setIngredient('O', Material.OBSIDIAN);
    portalRecipe.setIngredient('P', Material.ENDER_PEARL);
    portalRecipe.setIngredient('C', purpleDye.toItemStack(1).getData());

    return Collections.singletonList((Recipe) portalRecipe);
}
Saw.java 文件源码 项目:BelovedBlocks 阅读 16 收藏 0 点赞 0 评论 0
@Override
public Iterable<Recipe> getCraftingRecipes()
{
    ArrayList<Recipe> recipes = new ArrayList<>();

    ShapedRecipe baseRecipe = CraftingRecipes.shaped(makeItem(1), Material.STICK, Material.IRON_INGOT);

    recipes.add(CraftingRecipes.shaped(baseRecipe, "BBA", "   ", "   "));
    recipes.add(CraftingRecipes.shaped(baseRecipe, "   ", "BBA", "   "));
    recipes.add(CraftingRecipes.shaped(baseRecipe, "   ", "   ", "BBA"));
    recipes.add(CraftingRecipes.shaped(baseRecipe, "ABB", "   ", "   "));
    recipes.add(CraftingRecipes.shaped(baseRecipe, "   ", "ABB", "   "));
    recipes.add(CraftingRecipes.shaped(baseRecipe, "   ", "   ", "ABB"));

    return recipes;
}
RecipeIterator.java 文件源码 项目:Tweakkit-Server 阅读 22 收藏 0 点赞 0 评论 0
public Recipe next() {
    if (recipes.hasNext()) {
        removeFrom = recipes;
        return recipes.next().toBukkitRecipe();
    } else {
        net.minecraft.server.ItemStack item;
        if (smeltingCustom.hasNext()) {
            removeFrom = smeltingCustom;
            item = smeltingCustom.next();
        } else {
            removeFrom = smeltingVanilla;
            item = smeltingVanilla.next();
        }

        CraftItemStack stack = CraftItemStack.asCraftMirror(RecipesFurnace.getInstance().getResult(item));

        return new CraftFurnaceRecipe(stack, CraftItemStack.asCraftMirror(item));
    }
}
AutoBuilder.java 文件源码 项目:sensibletoolbox 阅读 31 收藏 0 点赞 0 评论 0
@Override
public Recipe getRecipe() {
    ShapedRecipe recipe = new ShapedRecipe(toItemStack());
    ToughMachineFrame mf = new ToughMachineFrame();
    IntegratedCircuit ic = new IntegratedCircuit();
    registerCustomIngredients(mf, ic);
    recipe.shape("OCO", "DFP", "RGR");
    recipe.setIngredient('O', Material.OBSIDIAN);
    recipe.setIngredient('C', ic.getMaterialData());
    recipe.setIngredient('D', Material.DISPENSER);
    recipe.setIngredient('F', mf.getMaterialData());
    recipe.setIngredient('P', Material.DIAMOND_PICKAXE);
    recipe.setIngredient('R', Material.REDSTONE);
    recipe.setIngredient('G', Material.GOLD_INGOT);
    return recipe;
}
Smelter.java 文件源码 项目:sensibletoolbox 阅读 30 收藏 0 点赞 0 评论 0
@Override
public void addCustomRecipes(CustomRecipeManager crm) {
    // add a corresponding smelter recipe for every known vanilla furnace recipe
    Iterator<Recipe> iter = Bukkit.recipeIterator();
    while (iter.hasNext()) {
        Recipe r = iter.next();
        if (r instanceof FurnaceRecipe) {
            FurnaceRecipe fr = (FurnaceRecipe) r;
            if (RecipeUtil.isVanillaSmelt(fr.getInput().getType())) {
                crm.addCustomRecipe(new SimpleCustomRecipe(this, fr.getInput(), fr.getResult(), getProcessingTime(fr.getInput())));
            }
        }
    }

    // add a processing recipe for any STB item which reports itself as smeltable
    for (String key : SensibleToolbox.getItemRegistry().getItemIds()) {
        BaseSTBItem item = SensibleToolbox.getItemRegistry().getItemById(key);
        if (item.getSmeltingResult() != null) {
            ItemStack stack = item.toItemStack();
            crm.addCustomRecipe(new SimpleCustomRecipe(this, stack, item.getSmeltingResult(), getProcessingTime(stack)));
        }
    }
}
ListRecipesCommandExecutor.java 文件源码 项目:CustomRecipes 阅读 25 收藏 0 点赞 0 评论 0
public ListRecipesCommandExecutor(Function<String, ? extends List<? extends Recipe>> recipesByTypeMapper,
        Map<String, Function<? super Recipe, ? extends ItemStack>> recipeToItemMap,
        Map<String, BiConsumer<? super Recipe, ? super CommandSender>> recipeToCommandSenderDiplayMap) {
    this.recipesByTypeMapper = recipesByTypeMapper;
    this.recipeToItemMap = recipeToItemMap;
    this.recipeToCommandSenderDiplayMap = recipeToCommandSenderDiplayMap;
}
ListRecipesCommandExecutor.java 文件源码 项目:CustomRecipes 阅读 26 收藏 0 点赞 0 评论 0
private boolean listPlayer(Player player, String recipeType, List<? extends Recipe> recipes) {
    Function<? super Recipe, ? extends ItemStack> representationFunction = recipeToItemMap.get(recipeType);
    if (representationFunction == null) {
        player.sendMessage(ChatColor.RED + "No representation function found for this type of recipe. Trying chat messages..");
        return listSender(player, recipeType, recipes);
    }

    List<? extends ItemStack> representations = recipes.stream().map(representationFunction).collect(Collectors.toList());
    player.openInventory(new ListRecipesInventoryHolder(recipeType, representations).getInventory());

    return true;
}
ListRecipesCommandExecutor.java 文件源码 项目:CustomRecipes 阅读 24 收藏 0 点赞 0 评论 0
private boolean listSender(CommandSender sender, String recipeType, List<? extends Recipe> recipes) {
    BiConsumer<? super Recipe, ? super CommandSender> recipeDisplayFunction = recipeToCommandSenderDiplayMap.get(recipeType);
    if (recipeDisplayFunction == null) {
        sender.sendMessage(ChatColor.RED + "No display function found for this type of recpie.");
        return true;
    }

    recipes.forEach(recipe -> recipeDisplayFunction.accept(recipe, sender));

    return true;
}
CraftInventoryCrafting.java 文件源码 项目:Uranium 阅读 19 收藏 0 点赞 0 评论 0
public Recipe getRecipe() {
    net.minecraft.item.crafting.IRecipe recipe = ((net.minecraft.inventory.InventoryCrafting)getInventory()).currentRecipe;
    // Cauldron start - handle custom recipe classes without Bukkit API equivalents
    try {
        return recipe == null ? null : recipe.toBukkitRecipe();
    } catch (AbstractMethodError ex) {
        // No Bukkit wrapper provided
        return new CustomModRecipe(recipe);
    }
    // Cauldron end
}


问题


面经


文章

微信
公众号

扫码关注公众号