Java 类net.minecraft.server.ItemStack 实例源码

项目:CraftBukkit    文件:CraftEventFactory.java   
public static void handleEditBookEvent(EntityPlayer player, ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.itemInHandIndex;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.itemInHandIndex, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getItemInHand()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == Items.WRITTEN_BOOK);
    player.world.getServer().getPluginManager().callEvent(editBookEvent);
    ItemStack itemInHand = player.inventory.getItem(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == Items.BOOK_AND_QUILL) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.setItem(Items.WRITTEN_BOOK);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        Slot slot = player.activeContainer.getSlot(player.inventory, itemInHandIndex);
        player.playerConnection.sendPacket(new PacketPlayOutSetSlot(player.activeContainer.windowId, slot.rawSlotIndex, itemInHand));
    }
}
项目:ProjectAres    文件:NMSHacks.java   
public static void showFakeItems(Plugin plugin, Player viewer, Location location, org.bukkit.inventory.ItemStack item, int count, Duration duration) {
    if(count <= 0) return;

    final EntityPlayer nmsPlayer = ((CraftPlayer) viewer).getHandle();
    final int[] entityIds = new int[count];

    for(int i = 0; i < count; i++) {
        final EntityItem entity = new EntityItem(nmsPlayer.getWorld(), location.getX(), location.getY(), location.getZ(), CraftItemStack.asNMSCopy(item));

        entity.motX = randomEntityVelocity();
        entity.motY = randomEntityVelocity();
        entity.motZ = randomEntityVelocity();

        sendPacket(viewer, new PacketPlayOutSpawnEntity(entity, ENTITY_TYPE_IDS.get(org.bukkit.entity.Item.class)));
        sendPacket(viewer, new PacketPlayOutEntityMetadata(entity.getId(), entity.getDataWatcher(), true));

        entityIds[i] = entity.getId();
    }

    scheduleEntityDestroy(plugin, viewer.getUniqueId(), duration, entityIds);
}
项目:CraftBukkit    文件:CraftJukebox.java   
@Override
public void setPlaying(Material record) {
    if (record == null || CraftMagicNumbers.getItem(record) == null) {
        record = Material.AIR;
        jukebox.setRecord(null);
    } else {
        jukebox.setRecord(new ItemStack(CraftMagicNumbers.getItem(record), 1));
    }
    jukebox.update();
    if (record == Material.AIR) {
        world.getHandle().setData(getX(), getY(), getZ(), 0, 3);
    } else {
        world.getHandle().setData(getX(), getY(), getZ(), 1, 3);
    }
    world.playEffect(getLocation(), Effect.RECORD_PLAY, record.getId());
}
项目:CraftBukkit    文件:CraftEventFactory.java   
private static PlayerEvent getPlayerBucketEvent(boolean isFilling, EntityHuman who, int clickedX, int clickedY, int clickedZ, int clickedFace, ItemStack itemstack, net.minecraft.server.Item item) {
    Player player = (who == null) ? null : (Player) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asNewCraftStack(item);
    Material bucket = CraftMagicNumbers.getMaterial(itemstack.getItem());

    CraftWorld craftWorld = (CraftWorld) player.getWorld();
    CraftServer craftServer = (CraftServer) player.getServer();

    Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
    BlockFace blockFace = CraftBlock.notchToBlockFace(clickedFace);

    PlayerEvent event = null;
    if (isFilling) {
        event = new PlayerBucketFillEvent(player, blockClicked, blockFace, bucket, itemInHand);
        ((PlayerBucketFillEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
    } else {
        event = new PlayerBucketEmptyEvent(player, blockClicked, blockFace, bucket, itemInHand);
        ((PlayerBucketEmptyEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
    }

    craftServer.getPluginManager().callEvent(event);

    return event;
}
项目:CraftBukkit    文件:CraftEventFactory.java   
public static EntityDeathEvent callEntityDeathEvent(EntityLiving victim, List<org.bukkit.inventory.ItemStack> drops) {
    CraftLivingEntity entity = (CraftLivingEntity) victim.getBukkitEntity();
    EntityDeathEvent event = new EntityDeathEvent(entity, drops, victim.getExpReward());
    CraftWorld world = (CraftWorld) entity.getWorld();
    Bukkit.getServer().getPluginManager().callEvent(event);

    victim.expToDrop = event.getDroppedExp();

    for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
        if (stack == null || stack.getType() == Material.AIR || stack.getAmount() == 0) continue;

        world.dropItemNaturally(entity.getLocation(), stack);
    }

    return event;
}
项目:CraftBukkit    文件:CraftEventFactory.java   
public static PlayerDeathEvent callPlayerDeathEvent(EntityPlayer victim, List<org.bukkit.inventory.ItemStack> drops, String deathMessage, boolean keepInventory) {
    CraftPlayer entity = victim.getBukkitEntity();
    PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage);
    event.setKeepInventory(keepInventory);
    org.bukkit.World world = entity.getWorld();
    Bukkit.getServer().getPluginManager().callEvent(event);

    victim.keepLevel = event.getKeepLevel();
    victim.newLevel = event.getNewLevel();
    victim.newTotalExp = event.getNewTotalExp();
    victim.expToDrop = event.getDroppedExp();
    victim.newExp = event.getNewExp();

    if (event.getKeepInventory()) {
        return event;
    }

    for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
        if (stack == null || stack.getType() == Material.AIR) continue;

        world.dropItemNaturally(entity.getLocation(), stack);
    }

    return event;
}
项目:Craftbukkit    文件:InventoryWrapper.java   
@Override
public ItemStack splitStack(int i, int j) {
    // Copied from CraftItemStack
    ItemStack stack = getItem(i);
    ItemStack result;
    if (stack == null) {
        return null;
    }
    if (stack.count <= j) {
        this.setItem(i, null);
        result = stack;
    } else {
        result = CraftItemStack.copyNMSStack(stack, j);
        stack.count -= j;
    }
    this.update();
    return result;
}
项目:Craftbukkit    文件:InventoryWrapper.java   
@Override
public ItemStack splitWithoutUpdate(int i) {
    // Copied from CraftItemStack
    ItemStack stack = getItem(i);
    ItemStack result;
    if (stack == null) {
        return null;
    }
    if (stack.count <= 1) {
        this.setItem(i, null);
        result = stack;
    } else {
        result = CraftItemStack.copyNMSStack(stack, 1);
        stack.count -= 1;
    }
    return result;
}
项目:Almura-Server    文件:CraftEventFactory.java   
private static PlayerEvent getPlayerBucketEvent(boolean isFilling, EntityHuman who, int clickedX, int clickedY, int clickedZ, int clickedFace, ItemStack itemstack, net.minecraft.server.Item item) {
    Player player = (who == null) ? null : (Player) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asNewCraftStack(item);
    Material bucket = Material.getMaterial(itemstack.id);

    CraftWorld craftWorld = (CraftWorld) player.getWorld();
    CraftServer craftServer = (CraftServer) player.getServer();

    Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
    BlockFace blockFace = CraftBlock.notchToBlockFace(clickedFace);

    PlayerEvent event = null;
    if (isFilling) {
        event = new PlayerBucketFillEvent(player, blockClicked, blockFace, bucket, itemInHand);
        ((PlayerBucketFillEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
    } else {
        event = new PlayerBucketEmptyEvent(player, blockClicked, blockFace, bucket, itemInHand);
        ((PlayerBucketEmptyEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
    }

    craftServer.getPluginManager().callEvent(event);

    return event;
}
项目:Almura-Server    文件:CraftEventFactory.java   
public static EntityDeathEvent callEntityDeathEvent(EntityLiving victim, List<org.bukkit.inventory.ItemStack> drops) {
    CraftLivingEntity entity = (CraftLivingEntity) victim.getBukkitEntity();
    EntityDeathEvent event = new EntityDeathEvent(entity, drops, victim.getExpReward());
    org.bukkit.World world = entity.getWorld();
    Bukkit.getServer().getPluginManager().callEvent(event);

    victim.expToDrop = event.getDroppedExp();

    for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
        if (stack == null || stack.getType() == Material.AIR) continue;

        world.dropItemNaturally(entity.getLocation(), stack);
    }

    return event;
}
项目:Almura-Server    文件:CraftEventFactory.java   
public static PlayerDeathEvent callPlayerDeathEvent(EntityPlayer victim, List<org.bukkit.inventory.ItemStack> drops, String deathMessage) {
    CraftPlayer entity = victim.getBukkitEntity();
    PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage);
    org.bukkit.World world = entity.getWorld();
    Bukkit.getServer().getPluginManager().callEvent(event);

    victim.keepLevel = event.getKeepLevel();
    victim.newLevel = event.getNewLevel();
    victim.newTotalExp = event.getNewTotalExp();
    victim.expToDrop = event.getDroppedExp();
    victim.newExp = event.getNewExp();

    for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
        if (stack == null || stack.getType() == Material.AIR) continue;

        world.dropItemNaturally(entity.getLocation(), stack);
    }

    return event;
}
项目:Almura-Server    文件:CraftEventFactory.java   
public static void handleEditBookEvent(EntityPlayer player, ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.itemInHandIndex;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.itemInHandIndex, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getItemInHand()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.id == Item.WRITTEN_BOOK.id);
    player.world.getServer().getPluginManager().callEvent(editBookEvent);
    ItemStack itemInHand = player.inventory.getItem(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand.id == Item.BOOK_AND_QUILL.id) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.id = Item.WRITTEN_BOOK.id;
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        Slot slot = player.activeContainer.a((IInventory) player.inventory, itemInHandIndex);
        player.playerConnection.sendPacket(new Packet103SetSlot(player.activeContainer.windowId, slot.g, itemInHand));
    }
}
项目:Tweakkit-Server    文件:CraftJukebox.java   
@Override
public void setPlaying(Material record) {
    if (record == null || CraftMagicNumbers.getItem(record) == null) {
        record = Material.AIR;
        jukebox.setRecord(null);
    } else {
        jukebox.setRecord(new ItemStack(CraftMagicNumbers.getItem(record), 1));
    }
    jukebox.update();
    if (record == Material.AIR) {
        world.getHandle().setData(getX(), getY(), getZ(), 0, 3);
    } else {
        world.getHandle().setData(getX(), getY(), getZ(), 1, 3);
    }
    world.playEffect(getLocation(), Effect.RECORD_PLAY, record.getId());
}
项目:Tweakkit-Server    文件:CraftEventFactory.java   
private static PlayerEvent getPlayerBucketEvent(boolean isFilling, EntityHuman who, int clickedX, int clickedY, int clickedZ, int clickedFace, ItemStack itemstack, net.minecraft.server.Item item) {
    Player player = (who == null) ? null : (Player) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asNewCraftStack(item);
    Material bucket = CraftMagicNumbers.getMaterial(itemstack.getItem());

    CraftWorld craftWorld = (CraftWorld) player.getWorld();
    CraftServer craftServer = (CraftServer) player.getServer();

    Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
    BlockFace blockFace = CraftBlock.notchToBlockFace(clickedFace);

    PlayerEvent event = null;
    if (isFilling) {
        event = new PlayerBucketFillEvent(player, blockClicked, blockFace, bucket, itemInHand);
        ((PlayerBucketFillEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
    } else {
        event = new PlayerBucketEmptyEvent(player, blockClicked, blockFace, bucket, itemInHand);
        ((PlayerBucketEmptyEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
    }

    craftServer.getPluginManager().callEvent(event);

    return event;
}
项目:Tweakkit-Server    文件:CraftEventFactory.java   
public static EntityDeathEvent callEntityDeathEvent(EntityLiving victim, List<org.bukkit.inventory.ItemStack> drops) {
    CraftLivingEntity entity = (CraftLivingEntity) victim.getBukkitEntity();
    EntityDeathEvent event = new EntityDeathEvent(entity, drops, victim.getExpReward());
    CraftWorld world = (CraftWorld) entity.getWorld();
    Bukkit.getServer().getPluginManager().callEvent(event);

    victim.expToDrop = event.getDroppedExp();

    for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
        if (stack == null || stack.getType() == Material.AIR || stack.getAmount() == 0) continue;

        world.dropItemNaturally(entity.getLocation(), stack);
    }

    return event;
}
项目:Tweakkit-Server    文件:CraftEventFactory.java   
public static PlayerDeathEvent callPlayerDeathEvent(EntityPlayer victim, List<org.bukkit.inventory.ItemStack> drops, String deathMessage, boolean keepInventory) {
    CraftPlayer entity = victim.getBukkitEntity();
    PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage);
    event.setKeepInventory(keepInventory);
    org.bukkit.World world = entity.getWorld();
    Bukkit.getServer().getPluginManager().callEvent(event);

    victim.keepLevel = event.getKeepLevel();
    victim.newLevel = event.getNewLevel();
    victim.newTotalExp = event.getNewTotalExp();
    victim.expToDrop = event.getDroppedExp();
    victim.newExp = event.getNewExp();

    if (event.getKeepInventory()) {
        return event;
    }

    for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
        if (stack == null || stack.getType() == Material.AIR) continue;

        world.dropItemNaturally(entity.getLocation(), stack);
    }

    return event;
}
项目:Tweakkit-Server    文件:CraftEventFactory.java   
public static void handleEditBookEvent(EntityPlayer player, ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.itemInHandIndex;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.itemInHandIndex, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getItemInHand()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == Items.WRITTEN_BOOK);
    player.world.getServer().getPluginManager().callEvent(editBookEvent);
    ItemStack itemInHand = player.inventory.getItem(itemInHandIndex);

    // If they've got the same item in their hand, it'll need to be updated.
    if (itemInHand != null && itemInHand.getItem() == Items.BOOK_AND_QUILL) {
        if (!editBookEvent.isCancelled()) {
            CraftItemStack.setItemMeta(itemInHand, editBookEvent.getNewBookMeta());
            if (editBookEvent.isSigning()) {
                itemInHand.setItem(Items.WRITTEN_BOOK);
            }
        }

        // Client will have updated its idea of the book item; we need to overwrite that
        Slot slot = player.activeContainer.getSlot(player.inventory, itemInHandIndex);
        player.playerConnection.sendPacket(new PacketPlayOutSetSlot(player.activeContainer.windowId, slot.rawSlotIndex, itemInHand));
    }
}
项目:SpigotSource    文件:InventoryWrapper.java   
@Override
public ItemStack splitStack(int i, int j) {
    // Copied from CraftItemStack
    ItemStack stack = getItem(i);
    ItemStack result;
    if (stack == null) {
        return null;
    }
    if (stack.count <= j) {
        this.setItem(i, null);
        result = stack;
    } else {
        result = CraftItemStack.copyNMSStack(stack, j);
        stack.count -= j;
    }
    this.update();
    return result;
}
项目:SpigotSource    文件:InventoryWrapper.java   
@Override
public ItemStack splitWithoutUpdate(int i) {
    // Copied from CraftItemStack
    ItemStack stack = getItem(i);
    ItemStack result;
    if (stack == null) {
        return null;
    }
    if (stack.count <= 1) {
        this.setItem(i, null);
        result = stack;
    } else {
        result = CraftItemStack.copyNMSStack(stack, 1);
        stack.count -= 1;
    }
    return result;
}
项目:Craft-city    文件:CraftEventFactory.java   
private static PlayerEvent getPlayerBucketEvent(boolean isFilling, EntityHuman who, int clickedX, int clickedY, int clickedZ, int clickedFace, ItemStack itemstack, net.minecraft.server.Item item) {
    Player player = (who == null) ? null : (Player) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asNewCraftStack(item);
    Material bucket = Material.getMaterial(itemstack.id);

    CraftWorld craftWorld = (CraftWorld) player.getWorld();
    CraftServer craftServer = (CraftServer) player.getServer();

    Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
    BlockFace blockFace = CraftBlock.notchToBlockFace(clickedFace);

    PlayerEvent event = null;
    if (isFilling) {
        event = new PlayerBucketFillEvent(player, blockClicked, blockFace, bucket, itemInHand);
        ((PlayerBucketFillEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
    } else {
        event = new PlayerBucketEmptyEvent(player, blockClicked, blockFace, bucket, itemInHand);
        ((PlayerBucketEmptyEvent) event).setCancelled(!canBuild(craftWorld, player, clickedX, clickedZ));
    }

    craftServer.getPluginManager().callEvent(event);

    return event;
}
项目:Craft-city    文件:CraftEventFactory.java   
public static EntityDeathEvent callEntityDeathEvent(EntityLiving victim, List<org.bukkit.inventory.ItemStack> drops) {
    CraftLivingEntity entity = (CraftLivingEntity) victim.getBukkitEntity();
    EntityDeathEvent event = new EntityDeathEvent(entity, drops, victim.getExpReward());
    org.bukkit.World world = entity.getWorld();
    Bukkit.getServer().getPluginManager().callEvent(event);

    victim.expToDrop = event.getDroppedExp();

    for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
        if (stack == null || stack.getType() == Material.AIR) continue;

        world.dropItemNaturally(entity.getLocation(), stack);
    }

    return event;
}
项目:Craft-city    文件:CraftEventFactory.java   
public static PlayerDeathEvent callPlayerDeathEvent(EntityPlayer victim, List<org.bukkit.inventory.ItemStack> drops, String deathMessage) {
    CraftPlayer entity = victim.getBukkitEntity();
    PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage);
    org.bukkit.World world = entity.getWorld();
    Bukkit.getServer().getPluginManager().callEvent(event);

    victim.keepLevel = event.getKeepLevel();
    victim.newLevel = event.getNewLevel();
    victim.newTotalExp = event.getNewTotalExp();
    victim.expToDrop = event.getDroppedExp();
    victim.newExp = event.getNewExp();

    for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
        if (stack == null || stack.getType() == Material.AIR) continue;

        world.dropItemNaturally(entity.getLocation(), stack);
    }

    return event;
}
项目:ProjectAres    文件:PacketTracer.java   
@Override
public PacketTracer a(ItemStack stack) {
    value("ItemStack", stack);
    try {
        mute = true;
        super.a(stack);
    } finally {
        mute = false;
    }
    return this;
}
项目:ProjectAres    文件:NMSHacks.java   
public void wearHelmet(Player viewer, org.bukkit.inventory.ItemStack helmet) {
    if(!Objects.equals(this.helmet, helmet)) {
        this.helmet = helmet.clone();
        helmetPacket = entityHelmetPacket(entityId(), helmet);
    }
    sendPacket(viewer, helmetPacket);
}
项目:ProjectAres    文件:NMSHacks.java   
/**
 * Test if the given tool is capable of "efficiently" mining the given block.
 *
 * Derived from CraftBlock.itemCausesDrops()
 */
public static boolean canMineBlock(MaterialData blockMaterial, org.bukkit.inventory.ItemStack tool) {
    if(!blockMaterial.getItemType().isBlock()) {
        throw new IllegalArgumentException("Material '" + blockMaterial + "' is not a block");
    }

    net.minecraft.server.Block nmsBlock = CraftMagicNumbers.getBlock(blockMaterial.getItemType());
    net.minecraft.server.Item nmsTool = tool == null ? null : CraftMagicNumbers.getItem(tool.getType());

    return nmsBlock != null && (nmsBlock.getBlockData().getMaterial().isAlwaysDestroyable() ||
                                (nmsTool != null && nmsTool.canDestroySpecialBlock(nmsBlock.getBlockData())));
}
项目:ProjectAres    文件:NMSHacks.java   
static ItemStack asNMS(org.bukkit.inventory.ItemStack bukkit) {
    if(bukkit instanceof CraftItemStack) {
        return ((CraftItemStack) bukkit).getHandle();
    } else {
        return CraftItemStack.asNMSCopy(bukkit);
    }
}
项目:CraftBukkit    文件:CraftJukebox.java   
@Override
public Material getPlaying() {
    ItemStack record = jukebox.getRecord();
    if (record == null) {
        return Material.AIR;
    }
    return CraftMagicNumbers.getMaterial(record.getItem());
}
项目:CraftBukkit    文件:CraftInventoryCustom.java   
public MinecraftInventory(InventoryHolder owner, int size, String title) {
    Validate.notNull(title, "Title cannot be null");
    Validate.isTrue(title.length() <= 32, "Title cannot be longer than 32 characters");
    this.items = new ItemStack[size];
    this.title = title;
    this.viewers = new ArrayList<HumanEntity>();
    this.owner = owner;
    this.type = InventoryType.CHEST;
}
项目:CraftBukkit    文件:CraftInventoryCustom.java   
public ItemStack splitStack(int i, int j) {
    ItemStack stack = this.getItem(i);
    ItemStack result;
    if (stack == null) return null;
    if (stack.count <= j) {
        this.setItem(i, null);
        result = stack;
    } else {
        result = CraftItemStack.copyNMSStack(stack, j);
        stack.count -= j;
    }
    this.update();
    return result;
}
项目:CraftBukkit    文件:CraftInventoryCustom.java   
public ItemStack splitWithoutUpdate(int i) {
    ItemStack stack = this.getItem(i);
    ItemStack result;
    if (stack == null) return null;
    if (stack.count <= 1) {
        this.setItem(i, null);
        result = stack;
    } else {
        result = CraftItemStack.copyNMSStack(stack, 1);
        stack.count -= 1;
    }
    return result;
}
项目:CraftBukkit    文件:CraftEventFactory.java   
/**
 * Player Interact event
 */
public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, ItemStack itemstack) {
    if (action != Action.LEFT_CLICK_AIR && action != Action.RIGHT_CLICK_AIR) {
        throw new AssertionError(String.format("%s performing %s with %s", who, action, itemstack));
    }
    return callPlayerInteractEvent(who, action, 0, 256, 0, 0, itemstack);
}
项目:CraftBukkit    文件:CraftEventFactory.java   
public static PlayerInteractEvent callPlayerInteractEvent(EntityHuman who, Action action, int clickedX, int clickedY, int clickedZ, int clickedFace, ItemStack itemstack) {
    Player player = (who == null) ? null : (Player) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);

    CraftWorld craftWorld = (CraftWorld) player.getWorld();
    CraftServer craftServer = (CraftServer) player.getServer();

    Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
    BlockFace blockFace = CraftBlock.notchToBlockFace(clickedFace);

    if (clickedY > 255) {
        blockClicked = null;
        switch (action) {
        case LEFT_CLICK_BLOCK:
            action = Action.LEFT_CLICK_AIR;
            break;
        case RIGHT_CLICK_BLOCK:
            action = Action.RIGHT_CLICK_AIR;
            break;
        }
    }

    if (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0) {
        itemInHand = null;
    }

    PlayerInteractEvent event = new PlayerInteractEvent(player, action, itemInHand, blockClicked, blockFace);
    craftServer.getPluginManager().callEvent(event);

    return event;
}
项目:CraftBukkit    文件:CraftEventFactory.java   
/**
 * EntityShootBowEvent
 */
public static EntityShootBowEvent callEntityShootBowEvent(EntityLiving who, ItemStack itemstack, EntityArrow entityArrow, float force) {
    LivingEntity shooter = (LivingEntity) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);
    Arrow arrow = (Arrow) entityArrow.getBukkitEntity();

    if (itemInHand != null && (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0)) {
        itemInHand = null;
    }

    EntityShootBowEvent event = new EntityShootBowEvent(shooter, itemInHand, arrow, force);
    Bukkit.getPluginManager().callEvent(event);

    return event;
}
项目:CraftBukkit    文件:CraftEventFactory.java   
/**
 * BlockDamageEvent
 */
public static BlockDamageEvent callBlockDamageEvent(EntityHuman who, int x, int y, int z, ItemStack itemstack, boolean instaBreak) {
    Player player = (who == null) ? null : (Player) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asCraftMirror(itemstack);

    CraftWorld craftWorld = (CraftWorld) player.getWorld();
    CraftServer craftServer = (CraftServer) player.getServer();

    Block blockClicked = craftWorld.getBlockAt(x, y, z);

    BlockDamageEvent event = new BlockDamageEvent(player, blockClicked, itemInHand, instaBreak);
    craftServer.getPluginManager().callEvent(event);

    return event;
}
项目:CraftBukkit    文件:CraftEventFactory.java   
public static ItemStack callPreCraftEvent(InventoryCrafting matrix, ItemStack result, InventoryView lastCraftView, boolean isRepair) {
    CraftInventoryCrafting inventory = new CraftInventoryCrafting(matrix, matrix.resultInventory);
    inventory.setResult(CraftItemStack.asCraftMirror(result));

    PrepareItemCraftEvent event = new PrepareItemCraftEvent(inventory, lastCraftView, isRepair);
    Bukkit.getPluginManager().callEvent(event);

    org.bukkit.inventory.ItemStack bitem = event.getInventory().getResult();

    return CraftItemStack.asNMSCopy(bitem);
}
项目:Craftbukkit    文件:CraftItemFrame.java   
private void update() {
    EntityItemFrame old = this.getHandle();

    WorldServer world = ((CraftWorld) getWorld()).getHandle();
    BlockPosition position = old.getBlockPosition();
    EnumDirection direction = old.getDirection();
    ItemStack item = old.getItem() != null ? old.getItem().cloneItemStack() : null;

    old.die();

    EntityItemFrame frame = new EntityItemFrame(world,position,direction);
    frame.setItem(item);
    world.addEntity(frame);
    this.entity = frame;
}
项目:Craftbukkit    文件:CraftItemFrame.java   
public void setItem(org.bukkit.inventory.ItemStack item) {
    if (item == null || item.getTypeId() == 0) {
        getHandle().setItem(null);
    } else {
        getHandle().setItem(CraftItemStack.asNMSCopy(item));
    }
}
项目:Craftbukkit    文件:CraftInventoryCustom.java   
public MinecraftInventory(InventoryHolder owner, int size, String title) {
    Validate.notNull(title, "Title cannot be null");
    Validate.isTrue(title.length() <= 32, "Title cannot be longer than 32 characters");
    this.items = new ItemStack[size];
    this.title = title;
    this.viewers = new ArrayList<HumanEntity>();
    this.owner = owner;
    this.type = InventoryType.CHEST;
}
项目:Craftbukkit    文件:CraftInventoryCustom.java   
public ItemStack splitStack(int i, int j) {
    ItemStack stack = this.getItem(i);
    ItemStack result;
    if (stack == null) return null;
    if (stack.count <= j) {
        this.setItem(i, null);
        result = stack;
    } else {
        result = CraftItemStack.copyNMSStack(stack, j);
        stack.count -= j;
    }
    this.update();
    return result;
}
项目:Craftbukkit    文件:CraftInventoryCustom.java   
public ItemStack splitWithoutUpdate(int i) {
    ItemStack stack = this.getItem(i);
    ItemStack result;
    if (stack == null) return null;
    if (stack.count <= 1) {
        this.setItem(i, null);
        result = stack;
    } else {
        result = CraftItemStack.copyNMSStack(stack, 1);
        stack.count -= 1;
    }
    return result;
}