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


Java Chest.getBlockInventory方法代碼示例

本文整理匯總了Java中org.bukkit.block.Chest.getBlockInventory方法的典型用法代碼示例。如果您正苦於以下問題:Java Chest.getBlockInventory方法的具體用法?Java Chest.getBlockInventory怎麽用?Java Chest.getBlockInventory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.bukkit.block.Chest的用法示例。


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

示例1: getBlockInventory

import org.bukkit.block.Chest; //導入方法依賴的package包/類
/**
 * Gets the single block inventory for a potentially double chest.
 * Handles people who have an old version of Bukkit.
 * This should be replaced with {@link org.bukkit.block.Chest#getBlockInventory()}
 * in a few months (now = March 2012) // note from future dev - lol
 *
 * @param chest The chest to get a single block inventory for
 * @return The chest's inventory
 */
private Inventory getBlockInventory(Chest chest) {
    try {
        return chest.getBlockInventory();
    } catch (Throwable t) {
        if (chest.getInventory() instanceof DoubleChestInventory) {
            DoubleChestInventory inven = (DoubleChestInventory) chest.getInventory();
            if (inven.getLeftSide().getHolder().equals(chest)) {
                return inven.getLeftSide();
            } else if (inven.getRightSide().getHolder().equals(chest)) {
                return inven.getRightSide();
            } else {
                return inven;
            }
        } else {
            return chest.getInventory();
        }
    }
}
 
開發者ID:boy0001,項目名稱:FastAsyncWorldedit,代碼行數:28,代碼來源:BukkitWorld.java

示例2: getVanillaInventoryFor

import org.bukkit.block.Chest; //導入方法依賴的package包/類
/**
 * Get the vanilla inventory for the given block.
 *
 * @param target the block containing the target inventory
 * @return the block's inventory, or null if the block does not have one
 */
public static Inventory getVanillaInventoryFor(Block target) {
    switch (target.getType()) {
        case CHEST:
            Chest c = (Chest) target.getState();
            if (c.getInventory().getHolder() instanceof DoubleChest) {
                DoubleChest dc = (DoubleChest) c.getInventory().getHolder();
                return dc.getInventory();
            } else {
                return c.getBlockInventory();
            }
        case DISPENSER:
        case HOPPER:
        case DROPPER:
        case FURNACE:
        case BREWING_STAND:
        case BURNING_FURNACE:
            return ((InventoryHolder) target.getState()).getInventory();
        // any other vanilla inventory types ?
        default:
            return null;
    }
}
 
開發者ID:desht,項目名稱:sensibletoolbox,代碼行數:29,代碼來源:VanillaInventoryUtils.java

示例3: handleItemsReshuffle

import org.bukkit.block.Chest; //導入方法依賴的package包/類
public void handleItemsReshuffle(MazePlugin _plugin, ItemStack[] items)
{
    //Synchronous item reshuffle
    World w = _plugin.getServer().getWorld(world);
    BlockMeta meta;
    Block b;
    ArrayList<Integer> emptyslotidx = new ArrayList<Integer>();
    for(ItemStack item : items)
    {
        if(item != null)
        {
            do {
                emptyslotidx.clear();
                emptyslotidx.trimToSize();
                meta = chestmeta.get(random.nextInt(chestmeta.size()));
                b = w.getBlockAt(meta.x,meta.y,meta.z);
                BlockState state = b.getState();
                if(!(state instanceof Chest))
                {
                    continue;
                }
                Chest c = (Chest) state;
                Inventory i = c.getBlockInventory();
                ItemStack[] contents = i.getContents();
                for(int j = 0; j < 27; j++) {
                    if (contents[j] == null) {
                        emptyslotidx.add(j);
                    } else if (contents[j].getType() == Material.AIR)
                    {
                        emptyslotidx.add(j);
                    }
                }
                if(emptyslotidx.size() > 0)
                {
                    i.setItem(emptyslotidx.get(0),item);
                }
            }while (b.getType() != Material.CHEST || emptyslotidx.size() <= 0);
        }
    }
}
 
開發者ID:loveyanbei,項目名稱:MazePlugin,代碼行數:41,代碼來源:Abstract2DMaze.java

示例4: fill

import org.bukkit.block.Chest; //導入方法依賴的package包/類
/**
 * Fill the chest randomly with items
 * 
 * @param items The items to fill the chest with
 * 
 * @return Whether the chest successfully filled (or successfully blocked
 *         from being inactive)
 */
public boolean fill(ItemStack... items) {
	if (!active)
		return true;
	Block block = loc.getBlock();
	int j = 0; // represents items stored, temporary solution for basic random selection
	if (block != null && block.getState() instanceof Chest) {
		Chest chest = (Chest) block.getState();
		Inventory inv = chest.getBlockInventory();
		inv.clear();
		for (ItemStack i : items) {
			// TODO: Add better random chance functionality, basic selection for now
			if (r.nextInt(2) != 0 || j++ > r.nextInt(items.length / 3) + 2)
				continue;
			int slot = 0;
			do {
				if (inv.firstEmpty() == -1) // inventory full
					return false;
				slot = r.nextInt(inv.getSize());
			} while (inv.getItem(slot) != null && inv.getItem(slot).getType().equals(i.getType()));
			ItemStack it = inv.getItem(slot);
			if (it != null && it.getType().equals(i.getType())) {
				int amount = it.getAmount() + i.getAmount();
				if (amount > it.getMaxStackSize())
					amount = it.getMaxStackSize();
				it.setAmount(amount);
			} else
				inv.setItem(slot, i);
		}
		return true;
	} else
		return false;
}
 
開發者ID:DonkeyCore,項目名稱:MinigameManager,代碼行數:41,代碼來源:RandomizedChest.java

示例5: fillChest

import org.bukkit.block.Chest; //導入方法依賴的package包/類
public static void fillChest(Block block) {
	int min, max;
	min = main.cfg.getInt("items.min");
	max = main.cfg.getInt("items.max");
	if (block.getState() instanceof Chest) {
		Chest chest = (Chest) block.getState();
		Inventory inv = chest.getBlockInventory();
		for (int i = 0; i < CSCoreLib.randomizer().nextInt(max - min) + min; i++) {
			inv.setItem(CSCoreLib.randomizer().nextInt(inv.getSize()), createItem(LootType.RANDOM));
		}
	}
}
 
開發者ID:TheBusyBiscuit,項目名稱:MagicLoot3,代碼行數:13,代碼來源:ItemManager.java

示例6: createChest

import org.bukkit.block.Chest; //導入方法依賴的package包/類
/**
 * Creates a chest at <code>location</code> filled with <code>items</code>.
 *
 * @param location the location at which to create the chest.
 * @param items    the ArrayList of items to fill the chest with.
 */
public static void createChest(Location location, ArrayList<ItemStack> items) {
    // Create the chest
    location.getBlock().setType(Material.CHEST);

    // Get the chest's inventory
    Chest chest = (Chest) location.getBlock().getState();
    Inventory inventory = chest.getBlockInventory();

    // Add the items randomly
    for (ItemStack item : items) {
        inventory.setItem((new Random().nextInt(inventory.getSize() - 1) + 1), item);
    }
}
 
開發者ID:DemigodsRPG,項目名稱:Stoa,代碼行數:20,代碼來源:ItemUtil.java

示例7: createChest

import org.bukkit.block.Chest; //導入方法依賴的package包/類
/**
 * Creates a chest at <code>location</code> filled with <code>items</code>.
 *
 * @param location the location at which to create the chest.
 * @param items    the ArrayList of items to fill the chest with.
 */
public static void createChest(Location location, List<ItemStack> items) {
    // Create the chest
    location.getBlock().setType(Material.CHEST);

    // Get the chest's inventory
    Chest chest = (Chest) location.getBlock().getState();
    Inventory inventory = chest.getBlockInventory();

    // Add the items randomly
    for (ItemStack item : items) {
        inventory.setItem((new Random().nextInt(inventory.getSize() - 1) + 1), item);
    }
}
 
開發者ID:DemigodsRPG,項目名稱:DemigodsRPG,代碼行數:20,代碼來源:ItemUtil.java

示例8: handleItemsReshuffle

import org.bukkit.block.Chest; //導入方法依賴的package包/類
public void handleItemsReshuffle(MazePlugin _plugin, ItemStack[] items)
{
    //Synchronous item reshuffle
    World w = _plugin.getServer().getWorld(world);
    BlockMeta meta;
    Block b;
    ArrayList<Integer> emptyslotidx = new ArrayList<Integer>();
    for(ItemStack item : items)
    {
        if(item != null)
        {
            do {
                meta = chestmeta.get(random.nextInt(chestmeta.size()));
                emptyslotidx.clear();
                emptyslotidx.trimToSize();
                b = w.getBlockAt(meta.x,meta.y,meta.z);
                BlockState state = b.getState();
                if(!(state instanceof Chest))
                {
                    continue;
                }
                Chest c = (Chest)state;
                Inventory i = c.getBlockInventory();
                ItemStack[] contents = i.getContents();
                for(int j = 0; j < 27; j++) {
                    if (contents[j] == null) {
                        emptyslotidx.add(j);
                    } else if (contents[j].getType() == Material.AIR)
                    {
                        emptyslotidx.add(j);
                    }
                }

                if(emptyslotidx.size() > 0)
                {
                    i.setItem(emptyslotidx.get(0),item);
                };
            }while (b.getType() != Material.CHEST || emptyslotidx.size() <= 0);
        }
    }
}
 
開發者ID:loveyanbei,項目名稱:MazePlugin,代碼行數:42,代碼來源:Abstract3DMaze.java

示例9: getChestWorth

import org.bukkit.block.Chest; //導入方法依賴的package包/類
/**
 * Calculates the chest worth of a chunk.
 *
 * @param chunk     the chunk.
 * @param materials the material totals to add to.
 * @param spawners  the spawner totals to add to.
 * @return the chunk worth in materials.
 */
private double getChestWorth(Chunk chunk, Map<Material, Integer> materials, Map<EntityType, Integer> spawners) {
    int count;
    double worth = 0;
    double materialPrice;
    EntityType spawnerType;

    for (BlockState blockState : chunk.getTileEntities()) {
        if (!(blockState instanceof Chest)) {
            continue;
        }

        Chest chest = (Chest) blockState;

        for (ItemStack item : chest.getBlockInventory()) {
            if (item == null) continue;

            int stackSize = item.getAmount();

            switch (item.getType()) {
                case MOB_SPAWNER:
                    stackSize *= plugin.getSpawnerStackerHook().getStackSize(item);
                    spawnerType = plugin.getSpawnerStackerHook().getSpawnedType(item);
                    double price = plugin.getSettings().getSpawnerPrice(spawnerType);
                    materialPrice = price * stackSize;
                    break;
                default:
                    materialPrice = plugin.getSettings().getBlockPrice(item.getType()) * stackSize;
                    spawnerType = null;
                    break;
            }

            worth += materialPrice;

            if (materialPrice != 0) {
                if (spawnerType == null) {
                    count = materials.getOrDefault(item.getType(), 0);
                    materials.put(item.getType(), count + stackSize);
                } else {
                    count = spawners.getOrDefault(spawnerType, 0);
                    spawners.put(spawnerType, count + stackSize);
                }
            }
        }
    }

    return worth;
}
 
開發者ID:novucs,項目名稱:factions-top,代碼行數:56,代碼來源:WorthManager.java

示例10: NmsProxyTileChest

import org.bukkit.block.Chest; //導入方法依賴的package包/類
public NmsProxyTileChest(final Chest chest) {
    this.inv = chest.getBlockInventory();
}
 
開發者ID:Ribesg,項目名稱:Pure,代碼行數:4,代碼來源:NmsProxyTileChest.java

示例11: getChest

import org.bukkit.block.Chest; //導入方法依賴的package包/類
public Inventory getChest() {
	chest = (Chest) Bukkit.getWorld("Survival").getBlockAt(59, 71, 171).getState();
	return chest.getBlockInventory();
}
 
開發者ID:Esaych,項目名稱:DDCustomPlugin,代碼行數:5,代碼來源:StaffVotes.java


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