本文整理汇总了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();
}
}
}
示例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;
}
}
示例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);
}
}
}
示例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;
}
示例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));
}
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
}
示例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;
}
示例10: NmsProxyTileChest
import org.bukkit.block.Chest; //导入方法依赖的package包/类
public NmsProxyTileChest(final Chest chest) {
this.inv = chest.getBlockInventory();
}
示例11: getChest
import org.bukkit.block.Chest; //导入方法依赖的package包/类
public Inventory getChest() {
chest = (Chest) Bukkit.getWorld("Survival").getBlockAt(59, 71, 171).getState();
return chest.getBlockInventory();
}