CraftEventFactory.java 文件源码

java
阅读 19 收藏 0 点赞 0 评论 0

项目:Cauldron-Old 作者:
public static void handleEditBookEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.item.ItemStack newBookItem) {
    int itemInHandIndex = player.inventory.currentItem;

    PlayerEditBookEvent editBookEvent = new PlayerEditBookEvent(player.getBukkitEntity(), player.inventory.currentItem, (BookMeta) CraftItemStack.getItemMeta(player.inventory.getCurrentItem()), (BookMeta) CraftItemStack.getItemMeta(newBookItem), newBookItem.getItem() == net.minecraft.init.Items.written_book);
    player.worldObj.getServer().getPluginManager().callEvent(editBookEvent);
    net.minecraft.item.ItemStack itemInHand = player.inventory.getStackInSlot(itemInHandIndex);

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

        // Client will have updated its idea of the book item; we need to overwrite that
        net.minecraft.inventory.Slot slot = player.openContainer.getSlotFromInventory((net.minecraft.inventory.IInventory) player.inventory, itemInHandIndex);
        player.playerNetServerHandler.sendPacket(new net.minecraft.network.play.server.S2FPacketSetSlot(player.openContainer.windowId, slot.slotNumber, itemInHand));
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号