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)); } }
private void setupChest(IInventory top, IInventory bottom) { int rows = top.getSize() / 9; int row; int col; // This code copied from ContainerChest int i = (rows - 4) * 18; for (row = 0; row < rows; ++row) { for (col = 0; col < 9; ++col) { this.a(new Slot(top, col + row * 9, 8 + col * 18, 18 + row * 18)); } } for (row = 0; row < 3; ++row) { for (col = 0; col < 9; ++col) { this.a(new Slot(bottom, col + row * 9 + 9, 8 + col * 18, 103 + row * 18 + i)); } } for (col = 0; col < 9; ++col) { this.a(new Slot(bottom, col, 8 + col * 18, 161 + i)); } // End copy from ContainerChest }
private void setupWorkbench(IInventory top, IInventory bottom) { // This code copied from ContainerWorkbench this.a(new Slot(top, 0, 124, 35)); int row; int col; for (row = 0; row < 3; ++row) { for (col = 0; col < 3; ++col) { this.a(new Slot(top, 1 + col + row * 3, 30 + col * 18, 17 + row * 18)); } } for (row = 0; row < 3; ++row) { for (col = 0; col < 9; ++col) { this.a(new Slot(bottom, col + row * 9 + 9, 8 + col * 18, 84 + row * 18)); } } for (col = 0; col < 9; ++col) { this.a(new Slot(bottom, col, 8 + col * 18, 142)); } // End copy from ContainerWorkbench }
private void setupFurnace(IInventory top, IInventory bottom) { // This code copied from ContainerFurnace this.a(new Slot(top, 0, 56, 17)); this.a(new Slot(top, 1, 56, 53)); this.a(new Slot(top, 2, 116, 35)); int row; int col; for (row = 0; row < 3; ++row) { for (col = 0; col < 9; ++col) { this.a(new Slot(bottom, col + row * 9 + 9, 8 + col * 18, 84 + row * 18)); } } for (col = 0; col < 9; ++col) { this.a(new Slot(bottom, col, 8 + col * 18, 142)); } // End copy from ContainerFurnace }
private void setupDispenser(IInventory top, IInventory bottom) { // This code copied from ContainerDispenser int row; int col; for (row = 0; row < 3; ++row) { for (col = 0; col < 3; ++col) { this.a(new Slot(top, col + row * 3, 61 + col * 18, 17 + row * 18)); } } for (row = 0; row < 3; ++row) { for (col = 0; col < 9; ++col) { this.a(new Slot(bottom, col + row * 9 + 9, 8 + col * 18, 84 + row * 18)); } } for (col = 0; col < 9; ++col) { this.a(new Slot(bottom, col, 8 + col * 18, 142)); } // End copy from ContainerDispenser }
private void setupEnchanting(IInventory top, IInventory bottom) { // This code copied from ContainerEnchantTable this.a((new Slot(top, 0, 25, 47))); int row; for (row = 0; row < 3; ++row) { for (int i1 = 0; i1 < 9; ++i1) { this.a(new Slot(bottom, i1 + row * 9 + 9, 8 + i1 * 18, 84 + row * 18)); } } for (row = 0; row < 9; ++row) { this.a(new Slot(bottom, row, 8 + row * 18, 142)); } // End copy from ContainerEnchantTable }
private void setupBrewing(IInventory top, IInventory bottom) { // This code copied from ContainerBrewingStand this.a(new Slot(top, 0, 56, 46)); this.a(new Slot(top, 1, 79, 53)); this.a(new Slot(top, 2, 102, 46)); this.a(new Slot(top, 3, 79, 17)); int i; for (i = 0; i < 3; ++i) { for (int j = 0; j < 9; ++j) { this.a(new Slot(bottom, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for (i = 0; i < 9; ++i) { this.a(new Slot(bottom, i, 8 + i * 18, 142)); } // End copy from ContainerBrewingStand }
private void setupHopper(IInventory top, IInventory bottom) { // This code copied from ContainerHopper byte b0 = 51; int i; for (i = 0; i < top.getSize(); ++i) { this.a(new Slot(top, i, 44 + i * 18, 20)); } for (i = 0; i < 3; ++i) { for (int j = 0; j < 9; ++j) { this.a(new Slot(bottom, j + i * 9 + 9, 8 + j * 18, i * 18 + b0)); } } for (i = 0; i < 9; ++i) { this.a(new Slot(bottom, i, 8 + i * 18, 58 + b0)); } // End copy from ContainerHopper }
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)); } }
private void setupEnchanting(IInventory top, IInventory bottom) { // This code copied from ContainerEnchantTable this.a((new Slot(top, 0, 15, 47))); this.a((new Slot(top, 0, 35, 47))); int row; for (row = 0; row < 3; ++row) { for (int i1 = 0; i1 < 9; ++i1) { this.a(new Slot(bottom, i1 + row * 9 + 9, 8 + i1 * 18, 84 + row * 18)); } } for (row = 0; row < 9; ++row) { this.a(new Slot(bottom, row, 8 + row * 18, 142)); } // End copy from ContainerEnchantTable }
private void setupBrewing(IInventory top, IInventory bottom) { // This code copied from ContainerBrewingStand this.a(new Slot(top, 0, 56, 46)); this.a(new Slot(top, 1, 79, 53)); this.a(new Slot(top, 2, 102, 46)); this.a(new Slot(top, 3, 79, 17)); this.a(new Slot(top, 4, 17, 17)); int i; for (i = 0; i < 3; ++i) { for (int j = 0; j < 9; ++j) { this.a(new Slot(bottom, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for (i = 0; i < 9; ++i) { this.a(new Slot(bottom, i, 8 + i * 18, 142)); } // End copy from ContainerBrewingStand }
private void setupAnvil(IInventory top, IInventory bottom) { // This code copied from ContainerAnvil this.a(new Slot(top, 0, 27, 47)); this.a(new Slot(top, 1, 76, 47)); this.a(new Slot(top, 2, 134, 47)); int i; for (i = 0; i < 3; ++i) { for (int j = 0; j < 9; ++j) { this.a(new Slot(bottom, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for (i = 0; i < 9; ++i) { this.a(new Slot(bottom, i, 8 + i * 18, 142)); } // End copy from ContainerAnvil }