當前位置: 首頁>>代碼示例>>Java>>正文


Java CraftingInventory類代碼示例

本文整理匯總了Java中org.bukkit.inventory.CraftingInventory的典型用法代碼示例。如果您正苦於以下問題:Java CraftingInventory類的具體用法?Java CraftingInventory怎麽用?Java CraftingInventory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CraftingInventory類屬於org.bukkit.inventory包,在下文中一共展示了CraftingInventory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: matrixMatch

import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
private boolean matrixMatch(CraftingInventory craftingInventory, int maxColumns, int maxRows, boolean mirrored) {
	for (int c = 0; c < 3; c++) {
		for (int r = 0; r < 3; r++) {
			int colNum = c - maxColumns;
			int rowNum = r - maxRows;
			CraftingIngredient choiceIngredient = InventoryUtils::isEmptyStack;
			if (colNum >= 0 && rowNum >= 0 && colNum < width && rowNum < heigth) {
				if (mirrored) {
					choiceIngredient = ingredients.get(width - 1 - colNum + rowNum * width);
				} else {
					choiceIngredient = ingredients.get(colNum + rowNum * width);
				}
			}
			
			if (!choiceIngredient.isIngredient(craftingInventory.getItem(colNum + rowNum * width))) {
				return false;
			}
		}
	}
	return true;
}
 
開發者ID:Jannyboy11,項目名稱:CustomRecipes,代碼行數:22,代碼來源:SimpleShapedRecipe.java

示例2: getLeftOverItems

import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public List<? extends ItemStack> getLeftOverItems(CraftingInventory craftingInventory) {
    ItemStack[] matrix = craftingInventory.getMatrix();
    List<ItemStack> leftOver = new ArrayList<>(matrix.length);
    
    for (int i = 0; i < matrix.length; i++) {
        ItemStack itemStack = matrix[i];
        
        if (InventoryUtils.isEmptyStack(itemStack)) {
            leftOver.add(null);
            continue;
        }
        
        ItemStack clone = itemStack.clone();
        MaterialData craftingResult = InventoryUtils.getSingleIngredientResult(itemStack.getData());
        if (craftingResult.getItemType() != Material.AIR) {
            clone.setData(craftingResult);
            leftOver.add(clone);           
            continue;
        }
    }
    
    craftingInventory.setContents(leftOver.toArray(new ItemStack[matrix.length]));
    return leftOver;
}
 
開發者ID:Jannyboy11,項目名稱:CustomRecipes,代碼行數:29,代碼來源:SimpleCraftingRecipe.java

示例3: matches

import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public boolean matches(CraftingInventory craftingInventory, World world) {
	final List<ChoiceIngredient> ingredients = new ArrayList<>(this.ingredients);
	final List<ItemStack> contents = Arrays.asList(craftingInventory.getMatrix())
			.stream().filter(i -> !InventoryUtils.isEmptyStack(i))
			.collect(Collectors.toList());
	
	for (ItemStack stack : contents) {
		boolean match = false;
		for (int ingredientIndex = 0; ingredientIndex < ingredients.size(); ingredientIndex++) {
			ChoiceIngredient ingredient = ingredients.get(ingredientIndex);
			if (ingredient.isIngredient(stack)) {
				ingredients.remove(ingredientIndex);
				match = true;
				break;
			}
		}
		
		//there was no matching ingredient for the current ItemStack
		if (!match) return false;
	}
	
	//return true if there are no unused ingredients left over
	return ingredients.isEmpty();
}
 
開發者ID:Jannyboy11,項目名稱:CustomRecipes,代碼行數:29,代碼來源:SimpleShapelessRecipe.java

示例4: onPrepareCraft

import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
@EventHandler
public void onPrepareCraft(PrepareItemCraftEvent e)
{
	CraftingInventory inv = e.getInventory();
	ItemStack result = inv.getResult();
	if(result != null && result.getType() != Material.GLASS_BOTTLE)
	{
		List<ItemStack> bottles = Arrays.asList(inv.getMatrix());
		Iterator<ItemStack> it = bottles.iterator();
		
		while(it.hasNext())
		{
			ItemStack bottle = it.next();
			if(bottle == null) continue;
			if(bottle.getType().equals(Material.POTION))
			{
				if(!checkWaterBottle(bottle))
				{
					inv.setResult(null);
					return;
				}
			}
		}
	}
}
 
開發者ID:FattyMieo,項目名稱:SurvivalPlus,代碼行數:26,代碼來源:WaterBottleCrafting.java

示例5: onPrepareCrowbarCraft

import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPrepareCrowbarCraft(PrepareItemCraftEvent event) {
    CraftingInventory inventory = event.getInventory();
    if (event.isRepair() && event.getRecipe().getResult().getType() == Crowbar.CROWBAR_TYPE) {
        int endFrameUses = 0;
        int spawnerUses = 0;
        boolean changed = false;

        ItemStack[] matrix = inventory.getMatrix();
        for (ItemStack ingredient : matrix) {
            Optional<Crowbar> crowbarOptional = Crowbar.fromStack(ingredient);
            if (crowbarOptional.isPresent()) {
                Crowbar crowbar = crowbarOptional.get();
                spawnerUses += crowbar.getSpawnerUses();
                endFrameUses += crowbar.getEndFrameUses();
                changed = true;
            }
        }

        // Finally update the result.
        if (changed) {
            inventory.setResult(new Crowbar(spawnerUses, endFrameUses).getItemIfPresent());
        }
    }
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:26,代碼來源:CrowbarListener.java

示例6: onInventoryClick

import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent e) {
    HumanEntity human = e.getWhoClicked();
    if (human instanceof Player && e.getInventory() instanceof CraftingInventory) {
        final Player player = (Player) human;
        if (e.getCurrentItem() != null) {
            if (ArmorType.isArmor(e.getCurrentItem().getTypeId())) {
                sendDelayedArmorUpdate(player);
                return;
            }
        }
        if (e.getRawSlot() >= 5 && e.getRawSlot() <= 8) {
            sendDelayedArmorUpdate(player);
        }
    }
}
 
開發者ID:MylesIsCool,項目名稱:ViaVersion,代碼行數:17,代碼來源:ArmorListener.java

示例7: matches

import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public boolean matches(CraftingInventory craftingInventory, World world) {
	int width, heigth;
	
	//check boundaries for the crafting inventory
	InventoryType type = craftingInventory.getType();
	switch(type) {
		case CRAFTING:
			width = heigth = 2;
			break;
		case WORKBENCH:
			width = heigth = 3;
			break;
		default: return false; //unknown crafting inventory type.
	}
	
	for (int w = 0; w <= width - this.width; w++) {
		for (int h = 0; h <= heigth - this.heigth; h++) {
			if (matrixMatch(craftingInventory, w, h, true)) {
				return true;
			}
			if (matrixMatch(craftingInventory, w, h, false)) {
				return true;
			}
		}
	}
			
       return false;
}
 
開發者ID:Jannyboy11,項目名稱:CustomRecipes,代碼行數:33,代碼來源:SimpleShapedRecipe.java

示例8: matches

import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
@Override
public boolean matches(CraftingInventory craftingInventory, World world) {
	CraftWorld cWorld = (CraftWorld) world;
	
	WorldServer nmsWorld = cWorld.getHandle();
	InventoryCrafting nmsCraftingInventory = getNmsCraftingInventory(craftingInventory);

	return nmsRecipe.a(nmsCraftingInventory, nmsWorld);
}
 
開發者ID:Jannyboy11,項目名稱:CustomRecipes,代碼行數:10,代碼來源:CRCraftingRecipe.java

示例9: getLeftOverItems

import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
@Override
public List<CraftItemStack> getLeftOverItems(CraftingInventory craftingInventory) {
	InventoryCrafting nmsCraftingInventory = getNmsCraftingInventory(craftingInventory);
	return nmsRecipe.b(nmsCraftingInventory).stream()
			.map(CraftItemStack::asCraftMirror)
			.collect(Collectors.toList());
}
 
開發者ID:Jannyboy11,項目名稱:CustomRecipes,代碼行數:8,代碼來源:CRCraftingRecipe.java

示例10: onCraftItem

import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
private static void onCraftItem(Recipe recipe, CraftingInventory inventory)
{
    if (recipe.getResult().getType() == Material.WOOD_SWORD
            || recipe.getResult().getType() == Material.STONE_SWORD
            || recipe.getResult().getType() == Material.IRON_SWORD
            || recipe.getResult().getType() == Material.GOLD_SWORD
            || recipe.getResult().getType() == Material.DIAMOND_SWORD)
        inventory.setResult(new ItemStack(Material.AIR));
}
 
開發者ID:SamaGames,項目名稱:SurvivalAPI,代碼行數:10,代碼來源:NoSwordModule.java

示例11: onCraftItem

import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
private void onCraftItem(Recipe recipe, CraftingInventory inventory)
{
    if (recipe.getResult().getType() == Material.WOOD_SWORD)
        inventory.setResult(new ItemStack(this.getMaterial(Material.WOOD_SWORD)));
    else if (recipe.getResult().getType() == Material.WOOD_PICKAXE)
        inventory.setResult(new ItemStack(this.getMaterial(Material.WOOD_PICKAXE)));
    else if (recipe.getResult().getType() == Material.WOOD_AXE)
        inventory.setResult(new ItemStack(this.getMaterial(Material.WOOD_AXE)));
    else if (recipe.getResult().getType() == Material.WOOD_SPADE)
        inventory.setResult(new ItemStack(this.getMaterial(Material.WOOD_SPADE)));
}
 
開發者ID:SamaGames,項目名稱:SurvivalAPI,代碼行數:12,代碼來源:RapidToolsModule.java

示例12: onPrepareCraft

import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
public void onPrepareCraft(PrepareItemCraftEvent event) {
    if (event.getInventory().getHolder() instanceof Player) {
        CraftingInventory inventory = event.getInventory();
        Player player = (Player) inventory.getHolder();
        if (isBottledExperience(inventory.getResult())) {
            int exp = new ExperienceManager(player).getCurrentExp();
            inventory.setResult(exp > 0 ? createExpBottle(exp) : new ItemStack(Material.AIR, 1));
        }
    }
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:12,代碼來源:BottledExpListener.java

示例13: onPrepareItemCraft

import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
@EventHandler (priority = EventPriority.HIGHEST)
public void onPrepareItemCraft (PrepareItemCraftEvent e) {
	if (e.getViewers().size() < 1) return;

	World world = e.getViewers().get(0).getWorld();
	if(!isEnabled(world)) return;

	CraftingInventory inv = e.getInventory();
	ItemStack result = inv.getResult();
	
	if(result != null && denied.contains(result.getType()))
		inv.setResult(null);
}
 
開發者ID:gvlfm78,項目名稱:BukkitOldCombatMechanics,代碼行數:14,代碼來源:ModuleDisableCrafting.java

示例14: onCraftItem

import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
@EventHandler
public void onCraftItem(CraftItemEvent event) {
    if (event.isCancelled()) return;
    final Player p = (Player) event.getWhoClicked();
    CraftingInventory inventory = event.getInventory();
    for(ItemStack is : inventory.getContents()) {
        if(ArmorStandTool.isTool(is)) {
            event.setCancelled(true);
            //noinspection deprecation
            p.updateInventory();
            return;
        }
    }
}
 
開發者ID:St3venAU,項目名稱:ArmorStandTools,代碼行數:15,代碼來源:MainListener.java

示例15: onInventoryClick

import org.bukkit.inventory.CraftingInventory; //導入依賴的package包/類
/**
 * - Workaround to fix the crafting grid being not updated when the item is
 * taken from the grid.
 * <p>
 * - Used to prevent our blocks to be renamed using an anvil.
 * <p>
 * - Used to allow our tools to be enchanted (ensure the name is kept).
 */
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryClick(final InventoryClickEvent ev)
{
    if (ev.getInventory() instanceof CraftingInventory && ev.getSlot() == 0)
    {
        InventoryUtils.updateInventoryLater(ev.getInventory());
    }

    // Disable Anvil overrides if not using item names.
    else if (ev.getInventory() instanceof AnvilInventory && BBConfig.USE_ITEM_NAMES_FALLBACK.get())
    {
        ItemStack item = ev.getInventory().getItem(0);
        ItemStack result = ev.getInventory().getItem(2);
        if (item == null) return;
        BelovedBlock block = BelovedBlocks.getBelovedBlocksManager().getFromItem(item);
        
        // Items cannot be renamed
        if(block != null)
        {
            ev.getInventory().setItem(2, new ItemStack(Material.AIR, 0));
            return;
        }
        
        BelovedTool tool = BelovedBlocks.getToolsManager().getFromItem(item);
        
        // Players can add enchantments to the tools.
        if(tool != null) 
        {
            ItemUtils.setDisplayName(result, tool.getDisplayName());
            ev.getInventory().setItem(2, result);
        }
    }
}
 
開發者ID:zDevelopers,項目名稱:BelovedBlocks,代碼行數:42,代碼來源:CraftingListener.java


注:本文中的org.bukkit.inventory.CraftingInventory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。