public void a(IInventory iinventory) {
    // CraftBukkit start
    CraftingManager.getInstance().lastCraftView = getBukkitView();
    ItemStack craftResult = CraftingManager.getInstance().craft(this.craftInventory);
    this.resultInventory.setItem(0, craftResult);
    if (super.listeners.size() < 1) {
      return;
    }

    EntityPlayer player =
        (EntityPlayer) super.listeners.get(0); // TODO: Is this _always_ correct? Seems like it.
    player.netServerHandler.sendPacket(
        new Packet103SetSlot(player.activeContainer.windowId, 0, craftResult));
    // CraftBukkit end
  }
Example #2
0
  private int a(EntityAnimal entityanimal, EntityAnimal entityanimal1) {
    int i = this.b(entityanimal);
    int j = this.b(entityanimal1);
    this.e.getItem(0).setData(i);
    this.e.getItem(1).setData(j);
    ItemStack itemstack =
        CraftingManager.getInstance().craft(this.e, ((EntitySheep) entityanimal).world);
    int k;
    if (itemstack != null && itemstack.getItem().id == Item.INK_SACK.id) {
      k = itemstack.getData();
    } else {
      k = this.world.random.nextBoolean() ? i : j;
    }

    return k;
  }
  @Override
  public void a(Packet102WindowClick packet) {
    if (this.player.dead) return;

    if (this.player.activeContainer.windowId == packet.a
        && this.player.activeContainer.c(this.player)) {
      Inventory inventory = getActiveInventory();
      CraftPlayer player = (CraftPlayer) this.player.getBukkitEntity();
      ItemStack before = ItemStack.b(packet.e);
      ItemStack cursorBefore = this.player.inventory.l();
      SpoutCraftItemStack slot = SpoutCraftItemStack.fromItemStack(before);
      SpoutCraftItemStack cursor = SpoutCraftItemStack.fromItemStack(cursorBefore);
      InventorySlotType type = getActiveInventorySlotType(packet.b);
      boolean clickSuccessful = true;
      final int windowId = packet.a;

      // alert of a newly opened inventory
      if (!activeInventory) {
        activeInventory = true;
        InventoryOpenEvent event =
            new InventoryOpenEvent(player, inventory, getDefaultInventory(), activeLocation);
        Bukkit.getServer().getPluginManager().callEvent(event);
        if (event.isCancelled()) {
          this.player.D();
          activeInventory = false;
          activeLocation = null;
          return;
        }
      }

      // Fire InventoryChange or InventoryCraft event
      if (packet.b != -999) {
        if (inventory instanceof CraftingInventory) {
          CraftingInventory crafting = (CraftingInventory) inventory;
          InventoryCrafting recipe = null;
          if (inventory instanceof SpoutCraftingInventory) {
            recipe = ((SpoutCraftingInventory) crafting).getMatrixHandle();
          } else {
            recipe = (InventoryCrafting) ((SpoutCraftInventoryPlayer) crafting).getMatrixHandle();
          }

          SpoutCraftItemStack craftResult =
              SpoutCraftItemStack.fromItemStack(CraftingManager.getInstance().craft(recipe));
          SpoutCraftItemStack[] recipeContents = new SpoutCraftItemStack[recipe.getSize()];
          for (int i = 0; i < recipe.getSize(); i++) {
            org.bukkit.inventory.ItemStack temp = crafting.getMatrix()[i];
            recipeContents[i] = SpoutCraftItemStack.getCraftItemStack(temp);
          }

          SpoutCraftItemStack[][] matrix = null;
          if (recipe.getSize() == 4) {
            matrix =
                new SpoutCraftItemStack[][] {
                  Arrays.copyOfRange(recipeContents, 0, 2), Arrays.copyOfRange(recipeContents, 2, 4)
                };
          } else if (recipe.getSize() == 9) {
            matrix =
                new SpoutCraftItemStack[][] {
                  Arrays.copyOfRange(recipeContents, 0, 3),
                  Arrays.copyOfRange(recipeContents, 3, 6),
                  Arrays.copyOfRange(recipeContents, 6, 9)
                };
          }
          // Clicking to grab the crafting result
          if (type == InventorySlotType.RESULT) {
            InventoryCraftEvent craftEvent =
                new InventoryCraftEvent(
                    this.getPlayer(),
                    crafting,
                    this.activeLocation,
                    type,
                    packet.b,
                    matrix,
                    craftResult,
                    cursor,
                    packet.c == 0,
                    packet.f);
            Bukkit.getServer().getPluginManager().callEvent(craftEvent);
            craftEvent.getInventory().setResult(craftEvent.getResult());
            cursor = SpoutCraftItemStack.getCraftItemStack(craftEvent.getCursor());
            if (craftEvent.isCancelled()) {
              craftEvent.getInventory().setMatrix(recipeContents);
              setCursorSlot(cursor != null ? cursor.getHandle() : null);
              clickSuccessful = false;
            }
          }
        }
      }

      if (clickSuccessful) {
        clickSuccessful = handleInventoryClick(packet, type, slot, cursor, inventory);
      }

      if (clickSuccessful) {
        this.player.netServerHandler.sendPacket(new Packet106Transaction(windowId, packet.d, true));
        this.player.h = true;
        this.player.activeContainer.a();
        this.player.D();
        this.player.h = false;
      } else {
        this.getEntityList()
            .a(Integer.valueOf(this.player.activeContainer.windowId), Short.valueOf(packet.d));
        this.player.netServerHandler.sendPacket(
            new Packet106Transaction(windowId, packet.d, false));
        this.player.activeContainer.a(this.player, false);
        ArrayList<ItemStack> arraylist = new ArrayList<ItemStack>();

        for (int i = 0; i < this.player.activeContainer.e.size(); ++i) {
          arraylist.add(((Slot) this.player.activeContainer.e.get(i)).getItem());
        }

        this.player.a(this.player.activeContainer, arraylist);
      }
    }
  }