当前位置: 首页>>代码示例>>Java>>正文


Java BaseItemStack类代码示例

本文整理汇总了Java中com.sk89q.worldedit.blocks.BaseItemStack的典型用法代码示例。如果您正苦于以下问题:Java BaseItemStack类的具体用法?Java BaseItemStack怎么用?Java BaseItemStack使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BaseItemStack类属于com.sk89q.worldedit.blocks包,在下文中一共展示了BaseItemStack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: makeSpongeStack

import com.sk89q.worldedit.blocks.BaseItemStack; //导入依赖的package包/类
@Override
public ItemStack makeSpongeStack(BaseItemStack baseItemStack) {
    final ItemType itemType = ItemRegistryModule.get().getTypeByInternalId(baseItemStack.getType())
            .orElseThrow(() -> new IllegalStateException("Invalid item type: " + baseItemStack.getType()));
    final LanternItemStack itemStack = new LanternItemStack(itemType, baseItemStack.getAmount());
    final ObjectStore<LanternItemStack> store = ObjectStoreRegistry.get().get(LanternItemStack.class)
            .orElseThrow(() -> new IllegalStateException("Unable to access the LanternItemStack store."));
    final DataView view = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
    view.set(DATA_VALUE, baseItemStack.getData());
    store.deserialize(itemStack, view);
    final Map<Integer, Integer> enchantments = baseItemStack.getEnchantments();
    if (!enchantments.isEmpty()) {
        itemStack.offer(Keys.ITEM_ENCHANTMENTS, enchantments.entrySet().stream()
                .map(entry -> {
                    final Enchantment enchantment = EnchantmentRegistryModule.get().getByInternalId(entry.getKey())
                            .orElseThrow(() -> new IllegalStateException("Invalid enchantment type: " + entry.getKey()));
                    return new ItemEnchantment(enchantment, entry.getValue());
                })
                .collect(Collectors.toList()));
    }
    return itemStack;
}
 
开发者ID:LanternPowered,项目名称:LanternWorldEdit,代码行数:23,代码来源:LanternImplAdapter.java

示例2: toBaseItem

import com.sk89q.worldedit.blocks.BaseItemStack; //导入依赖的package包/类
private BaseItem toBaseItem(ItemStack item) {
    if (item == null) return new BaseItemStack(0, 0);
    int id = item.getTypeId();
    short data;
    if (id < 256) {
        data = item.getData().getData();
    } else {
        data = item.getDurability();
    }
    BaseItemStack baseItem = new BaseItemStack(id, item.getAmount(), data);
    ItemUtil itemUtil = Fawe.<FaweBukkit>imp().getItemUtil();
    if (itemUtil != null && item.hasItemMeta()) {
        baseItem.setNbtData(itemUtil.getNBT(item));
    }
    return baseItem;
}
 
开发者ID:boy0001,项目名称:FastAsyncWorldedit,代码行数:17,代码来源:BukkitPlayerBlockBag.java

示例3: toItemStack

import com.sk89q.worldedit.blocks.BaseItemStack; //导入依赖的package包/类
private ItemStack toItemStack(BaseItem item) {
    if (item == null) return null;
    final int id = item.getType();
    final int damage = item.getData();
    int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
    ItemStack bukkitItem;
    if (id < 256) {
        bukkitItem = new ItemStack(id, amount, (short) 0, (byte) damage);
    } else {
        bukkitItem = new ItemStack(id, amount, (short) damage);
    }
    ItemUtil itemUtil = Fawe.<FaweBukkit>imp().getItemUtil();
    if (itemUtil != null && item.hasNBTData()) {
        bukkitItem = itemUtil.setNBT(bukkitItem, item.getNbtData());
    }
    return bukkitItem;
}
 
开发者ID:boy0001,项目名称:FastAsyncWorldedit,代码行数:18,代码来源:BukkitPlayerBlockBag.java

示例4: simulateBlockMine

import com.sk89q.worldedit.blocks.BaseItemStack; //导入依赖的package包/类
@Override
default void simulateBlockMine(Vector pt) {
    BaseBlock block = getLazyBlock(pt);
    BaseItemStack stack = BlockType.getBlockDrop(block.getId(), (short) block.getData());

    if (stack != null) {
        final int amount = stack.getAmount();
        if (amount > 1) {
            dropItem(pt, new BaseItemStack(stack.getType(), 1, stack.getData()), amount);
        } else {
            dropItem(pt, stack, amount);
        }
    }

    try {
        setBlock(pt, new BaseBlock(BlockID.AIR));
    } catch (WorldEditException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:boy0001,项目名称:FastAsyncWorldedit,代码行数:21,代码来源:SimpleWorld.java

示例5: dropItem

import com.sk89q.worldedit.blocks.BaseItemStack; //导入依赖的package包/类
@Override
public void dropItem(Vector pt, BaseItemStack item) {
    World world = getWorld();
    ItemStack bukkitItem = new ItemStack(item.getType(), item.getAmount(),
            item.getData());
    world.dropItemNaturally(BukkitUtil.toLocation(world, pt), bukkitItem);
}
 
开发者ID:boy0001,项目名称:FastAsyncWorldedit,代码行数:8,代码来源:BukkitWorld.java

示例6: dropItem

import com.sk89q.worldedit.blocks.BaseItemStack; //导入依赖的package包/类
@Override
public void dropItem(Vector pt, BaseItemStack item) {
    Level world = getLevel();
    Item nukkitItem = new Item(item.getType(), item.getAmount(),
            item.getData());
    world.dropItem(NukkitUtil.toLocation(world, pt), nukkitItem);
}
 
开发者ID:boy0001,项目名称:FastAsyncWorldedit,代码行数:8,代码来源:NukkitWorld.java

示例7: toVanilla

import com.sk89q.worldedit.blocks.BaseItemStack; //导入依赖的package包/类
public static ItemStack toVanilla(BaseItemStack item) {
    ItemStack ret = new ItemStack(Item.getItemById(item.getType()), item.getAmount(), item.getData());
    for(Map.Entry<Integer, Integer> entry : item.getEnchantments().entrySet()){
        ret.addEnchantment(net.minecraft.enchantment.Enchantment.getEnchantmentById(entry.getKey()), entry.getValue());
    }

    return ret;
}
 
开发者ID:nailed,项目名称:nailed,代码行数:9,代码来源:NailedWorldEditPlatform.java

示例8: dropItem

import com.sk89q.worldedit.blocks.BaseItemStack; //导入依赖的package包/类
@Override
public void dropItem(Vector position, BaseItemStack item) {
    checkNotNull(position);
    checkNotNull(item);

    if (item.getType() == 0) {
        return;
    }

    EntityItem entity = new EntityItem(getWorld(), position.getX(), position.getY(), position.getZ(), NailedWorldEditPlatform.toVanilla(item));
    entity.setPickupDelay(10);
    getWorld().spawnEntityInWorld(entity);
}
 
开发者ID:nailed,项目名称:nailed,代码行数:14,代码来源:WorldEditWorld.java

示例9: fetchItem

import com.sk89q.worldedit.blocks.BaseItemStack; //导入依赖的package包/类
@Override
public void fetchItem(BaseItem item) throws BlockBagException {
    final int id = item.getType();
    final int damage = item.getData();
    int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
    assert(amount == 1);
    boolean usesDamageValue = ItemType.usesDamageValue(id);

    if (id == BlockID.AIR) {
        throw new IllegalArgumentException("Can't fetch air block");
    }

    loadInventory();

    boolean found = false;

    for (int slot = 0; slot < items.length; ++slot) {
        ItemStack forgeItem = items[slot];

        if (forgeItem == null) {
            continue;
        }
        int itemId = Item.getIdFromItem(forgeItem.getItem());
        if (itemId != id) {
            // Type id doesn't fit
            continue;
        }

        if (usesDamageValue && forgeItem.getItemDamage() != damage) {
            // Damage value doesn't fit.
            continue;
        }

        int currentAmount = forgeItem.stackSize;
        if (currentAmount < 0) {
            // Unlimited
            return;
        }

        changed = true;

        if (currentAmount > 1) {
            forgeItem.stackSize--;
            found = true;
        } else {
            items[slot] = null;
            found = true;
        }

        break;
    }

    if (!found) {
        throw new OutOfBlocksException();
    }
}
 
开发者ID:boy0001,项目名称:FastAsyncWorldedit,代码行数:57,代码来源:ForgePlayerBlockBag.java

示例10: storeItem

import com.sk89q.worldedit.blocks.BaseItemStack; //导入依赖的package包/类
@Override
public void storeItem(BaseItem item) throws BlockBagException {
    final int id = item.getType();
    final int damage = item.getData();
    int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
    assert(amount <= 64);
    boolean usesDamageValue = ItemType.usesDamageValue(id);

    if (id == BlockID.AIR) {
        throw new IllegalArgumentException("Can't store air block");
    }

    loadInventory();

    int freeSlot = -1;

    for (int slot = 0; slot < items.length; ++slot) {
        ItemStack forgeItem = items[slot];

        if (forgeItem == null) {
            // Delay using up a free slot until we know there are no stacks
            // of this item to merge into

            if (freeSlot == -1) {
                freeSlot = slot;
            }
            continue;
        }

        int itemId = Item.getIdFromItem(forgeItem.getItem());
        if (itemId != id) {
            // Type id doesn't fit
            continue;
        }

        if (usesDamageValue && forgeItem.getItemDamage() != damage) {
            // Damage value doesn't fit.
            continue;
        }

        int currentAmount = forgeItem.stackSize;
        if (currentAmount < 0) {
            // Unlimited
            return;
        }
        if (currentAmount >= 64) {
            // Full stack
            continue;
        }

        changed = true;

        int spaceLeft = 64 - currentAmount;
        if (spaceLeft >= amount) {
            forgeItem.stackSize += amount;
            return;
        }

        forgeItem.stackSize = (64);
        amount -= spaceLeft;
    }

    if (freeSlot > -1) {
        changed = true;
        items[freeSlot] = new ItemStack(Item.getItemById(id), amount);
        return;
    }

    throw new OutOfSpaceException(id);
}
 
开发者ID:boy0001,项目名称:FastAsyncWorldedit,代码行数:71,代码来源:ForgePlayerBlockBag.java

示例11: fetchItem

import com.sk89q.worldedit.blocks.BaseItemStack; //导入依赖的package包/类
@Override
public void fetchItem(BaseItem item) throws BlockBagException {
    final int id = item.getType();
    final int damage = item.getData();
    int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
    assert(amount == 1);
    boolean usesDamageValue = ItemType.usesDamageValue(id);

    if (id == BlockID.AIR) {
        throw new IllegalArgumentException("Can't fetch air block");
    }

    loadInventory();

    boolean found = false;

    for (int slot = 0; slot < items.length; ++slot) {
        ItemStack bukkitItem = items[slot];

        if (bukkitItem == null) {
            continue;
        }

        if (bukkitItem.getTypeId() != id) {
            // Type id doesn't fit
            continue;
        }

        if (usesDamageValue && bukkitItem.getDurability() != damage) {
            // Damage value doesn't fit.
            continue;
        }

        int currentAmount = bukkitItem.getAmount();
        if (currentAmount < 0) {
            // Unlimited
            return;
        }

        if (currentAmount > 1) {
            bukkitItem.setAmount(currentAmount - 1);
            found = true;
        } else {
            bukkitItem.setAmount(0);
            items[slot] = null;
            found = true;
        }

        break;
    }

    if (!found) {
        throw new OutOfBlocksException();
    }
}
 
开发者ID:boy0001,项目名称:FastAsyncWorldedit,代码行数:56,代码来源:BukkitPlayerBlockBag.java

示例12: storeItem

import com.sk89q.worldedit.blocks.BaseItemStack; //导入依赖的package包/类
@Override
public void storeItem(BaseItem item) throws BlockBagException {
    final int id = item.getType();
    final int damage = item.getData();
    int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
    assert(amount <= 64);
    boolean usesDamageValue = ItemType.usesDamageValue(id);

    if (id == BlockID.AIR) {
        throw new IllegalArgumentException("Can't store air block");
    }

    loadInventory();

    int freeSlot = -1;

    for (int slot = 0; slot < items.length; ++slot) {
        ItemStack bukkitItem = items[slot];

        if (bukkitItem == null) {
            // Delay using up a free slot until we know there are no stacks
            // of this item to merge into

            if (freeSlot == -1) {
                freeSlot = slot;
            }
            continue;
        }

        if (bukkitItem.getTypeId() != id) {
            // Type id doesn't fit
            continue;
        }

        if (usesDamageValue && bukkitItem.getDurability() != damage) {
            // Damage value doesn't fit.
            continue;
        }

        int currentAmount = bukkitItem.getAmount();
        if (currentAmount < 0) {
            // Unlimited
            return;
        }
        if (currentAmount >= 64) {
            // Full stack
            continue;
        }

        int spaceLeft = 64 - currentAmount;
        if (spaceLeft >= amount) {
            bukkitItem.setAmount(currentAmount + amount);
            return;
        }

        bukkitItem.setAmount(64);
        amount -= spaceLeft;
    }

    if (freeSlot > -1) {
        items[freeSlot] = new ItemStack(id, amount);
        return;
    }

    throw new OutOfSpaceException(id);
}
 
开发者ID:boy0001,项目名称:FastAsyncWorldedit,代码行数:67,代码来源:BukkitPlayerBlockBag.java

示例13: fetchItem

import com.sk89q.worldedit.blocks.BaseItemStack; //导入依赖的package包/类
@Override
public void fetchItem(BaseItem item) throws BlockBagException {
    final int id = item.getType();
    final int damage = item.getData();
    int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
    assert(amount == 1);
    boolean usesDamageValue = ItemType.usesDamageValue(id);

    if (id == BlockID.AIR) {
        throw new IllegalArgumentException("Can't fetch air block");
    }

    loadInventory();

    boolean found = false;

    for (int slot = 0; slot < items.length; ++slot) {
        ItemStack forgeItem = items[slot];

        if (forgeItem == null) {
            continue;
        }
        int itemId = Item.getIdFromItem(forgeItem.getItem());
        if (itemId != id) {
            // Type id doesn't fit
            continue;
        }

        if (usesDamageValue && forgeItem.getItemDamage() != damage) {
            // Damage value doesn't fit.
            continue;
        }

        int currentAmount = forgeItem.getCount();
        if (currentAmount < 0) {
            // Unlimited
            return;
        }

        changed = true;

        if (currentAmount > 1) {
            forgeItem.setCount(forgeItem.getCount() - 1);;
            found = true;
        } else {
            items[slot] = null;
            found = true;
        }

        break;
    }

    if (!found) {
        throw new OutOfBlocksException();
    }
}
 
开发者ID:boy0001,项目名称:FastAsyncWorldedit,代码行数:57,代码来源:ForgePlayerBlockBag.java

示例14: storeItem

import com.sk89q.worldedit.blocks.BaseItemStack; //导入依赖的package包/类
@Override
public void storeItem(BaseItem item) throws BlockBagException {
    final int id = item.getType();
    final int damage = item.getData();
    int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
    assert(amount <= 64);
    boolean usesDamageValue = ItemType.usesDamageValue(id);

    if (id == BlockID.AIR) {
        throw new IllegalArgumentException("Can't store air block");
    }

    loadInventory();

    int freeSlot = -1;

    for (int slot = 0; slot < items.length; ++slot) {
        ItemStack forgeItem = items[slot];

        if (forgeItem == null) {
            // Delay using up a free slot until we know there are no stacks
            // of this item to merge into

            if (freeSlot == -1) {
                freeSlot = slot;
            }
            continue;
        }

        int itemId = Item.getIdFromItem(forgeItem.getItem());
        if (itemId != id) {
            // Type id doesn't fit
            continue;
        }

        if (usesDamageValue && forgeItem.getItemDamage() != damage) {
            // Damage value doesn't fit.
            continue;
        }

        int currentAmount = forgeItem.getCount();
        if (currentAmount < 0) {
            // Unlimited
            return;
        }
        if (currentAmount >= 64) {
            // Full stack
            continue;
        }

        changed = true;

        int spaceLeft = 64 - currentAmount;
        if (spaceLeft >= amount) {
            forgeItem.setCount(forgeItem.getCount() + amount);
            return;
        }

        forgeItem.setCount(64);
        amount -= spaceLeft;
    }

    if (freeSlot > -1) {
        changed = true;
        items[freeSlot] = new ItemStack(Item.getItemById(id), amount);
        return;
    }

    throw new OutOfSpaceException(id);
}
 
开发者ID:boy0001,项目名称:FastAsyncWorldedit,代码行数:71,代码来源:ForgePlayerBlockBag.java

示例15: fetchItem

import com.sk89q.worldedit.blocks.BaseItemStack; //导入依赖的package包/类
@Override
public void fetchItem(BaseItem item) throws BlockBagException {
    final int id = item.getType();
    final int damage = item.getData();
    int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
    assert(amount == 1);
    boolean usesDamageValue = ItemType.usesDamageValue(id);

    if (id == BlockID.AIR) {
        throw new IllegalArgumentException("Can't fetch air block");
    }

    loadInventory();

    boolean found = false;

    for (Map.Entry<Integer, Item> entry : items.entrySet()) {
        int slot = entry.getKey();
        Item nukkitItem = entry.getValue();
        if (nukkitItem == null) {
            continue;
        }
        if (nukkitItem.getId() != id) {
            // Type id doesn't fit
            continue;
        }
        if (usesDamageValue && nukkitItem.getDamage() != damage) {
            // Damage value doesn't fit.
            continue;
        }

        int currentCount = nukkitItem.getCount();
        if (currentCount < 0) {
            // Unlimited
            return;
        }

        if (currentCount > 1) {
            nukkitItem.setCount(currentCount - 1);
            found = true;
        } else {
            items.remove(slot);
            found = true;
        }

        break;
    }

    if (!found) {
        throw new OutOfBlocksException();
    }
}
 
开发者ID:boy0001,项目名称:FastAsyncWorldedit,代码行数:53,代码来源:NukkitPlayerBlockBag.java


注:本文中的com.sk89q.worldedit.blocks.BaseItemStack类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。