Example #1
0
  public ItemStack[] b(InventoryCrafting inventorycrafting) {
    ItemStack[] aitemstack = new ItemStack[inventorycrafting.getSize()];

    for (int i = 0; i < aitemstack.length; ++i) {
      ItemStack itemstack = inventorycrafting.getItem(i);

      if (itemstack != null && itemstack.getItem().r()) {
        aitemstack[i] = new ItemStack(itemstack.getItem().q());
      }
    }

    return aitemstack;
  }
Example #2
0
  public ItemStack craft(InventoryCrafting inventorycrafting, World world) {
    int i = 0;
    ItemStack itemstack = null;
    ItemStack itemstack1 = null;

    int j;

    for (j = 0; j < inventorycrafting.getSize(); ++j) {
      ItemStack itemstack2 = inventorycrafting.getItem(j);

      if (itemstack2 != null) {
        if (i == 0) {
          itemstack = itemstack2;
        }

        if (i == 1) {
          itemstack1 = itemstack2;
        }

        ++i;
      }
    }

    if (i == 2
        && itemstack.id == itemstack1.id
        && itemstack.count == 1
        && itemstack1.count == 1
        && Item.byId[itemstack.id].usesDurability()) {
      Item item = Item.byId[itemstack.id];
      int k = item.getMaxDurability() - itemstack.j();
      int l = item.getMaxDurability() - itemstack1.j();
      int i1 = k + l + item.getMaxDurability() * 5 / 100;
      int j1 = item.getMaxDurability() - i1;

      if (j1 < 0) {
        j1 = 0;
      }

      return new ItemStack(itemstack.id, 1, j1);
    } else {
      for (j = 0; j < this.recipes.size(); ++j) {
        IRecipe irecipe = (IRecipe) this.recipes.get(j);

        if (irecipe.a(inventorycrafting, world)) {
          return irecipe.a(inventorycrafting);
        }
      }

      return null;
    }
  }
Example #3
0
  public ItemStack a(InventoryCrafting inventorycrafting) {
    ItemStack itemstack = this.b().cloneItemStack();

    if (this.e) {
      for (int i = 0; i < inventorycrafting.getSize(); ++i) {
        ItemStack itemstack1 = inventorycrafting.getItem(i);

        if (itemstack1 != null && itemstack1.hasTag()) {
          itemstack.setTag((NBTTagCompound) itemstack1.getTag().clone());
        }
      }
    }

    return itemstack;
  }
Example #4
0
  @Override
  public boolean a(InventoryCrafting inventorycrafting, World world) {
    a = null;
    int i = 0;
    int j = 0;
    int k = 0;
    int l = 0;
    int i1 = 0;
    int j1 = 0;

    for (int k1 = 0; k1 < inventorycrafting.getSize(); ++k1) {
      ItemStack itemstack = inventorycrafting.getItem(k1);

      if (itemstack != null) {
        if (itemstack.getItem() == Items.SULPHUR) {
          ++j;
        } else if (itemstack.getItem() == Items.FIREWORKS_CHARGE) {
          ++l;
        } else if (itemstack.getItem() == Items.INK_SACK) {
          ++k;
        } else if (itemstack.getItem() == Items.PAPER) {
          ++i;
        } else if (itemstack.getItem() == Items.GLOWSTONE_DUST) {
          ++i1;
        } else if (itemstack.getItem() == Items.DIAMOND) {
          ++i1;
        } else if (itemstack.getItem() == Items.FIREBALL) {
          ++j1;
        } else if (itemstack.getItem() == Items.FEATHER) {
          ++j1;
        } else if (itemstack.getItem() == Items.GOLD_NUGGET) {
          ++j1;
        } else {
          if (itemstack.getItem() != Items.SKULL) return false;

          ++j1;
        }
      }
    }

    i1 += k + j1;
    if (j <= 3 && i <= 1) {
      NBTTagCompound nbttagcompound;
      NBTTagCompound nbttagcompound1;

      if (j >= 1 && i == 1 && i1 == 0) {
        a = new ItemStack(Items.FIREWORKS);
        if (l > 0) {
          nbttagcompound = new NBTTagCompound();
          nbttagcompound1 = new NBTTagCompound();
          NBTTagList nbttaglist = new NBTTagList();

          for (int l1 = 0; l1 < inventorycrafting.getSize(); ++l1) {
            ItemStack itemstack1 = inventorycrafting.getItem(l1);

            if (itemstack1 != null
                && itemstack1.getItem() == Items.FIREWORKS_CHARGE
                && itemstack1.hasTag()
                && itemstack1.getTag().hasKeyOfType("Explosion", 10)) {
              nbttaglist.add(itemstack1.getTag().getCompound("Explosion"));
            }
          }

          nbttagcompound1.set("Explosions", nbttaglist);
          nbttagcompound1.setByte("Flight", (byte) j);
          nbttagcompound.set("Fireworks", nbttagcompound1);
          a.setTag(nbttagcompound);
        }

        return true;
      } else if (j == 1 && i == 0 && l == 0 && k > 0 && j1 <= 1) {
        a = new ItemStack(Items.FIREWORKS_CHARGE);
        nbttagcompound = new NBTTagCompound();
        nbttagcompound1 = new NBTTagCompound();
        byte b0 = 0;
        ArrayList arraylist = new ArrayList();

        for (int i2 = 0; i2 < inventorycrafting.getSize(); ++i2) {
          ItemStack itemstack2 = inventorycrafting.getItem(i2);

          if (itemstack2 != null) {
            if (itemstack2.getItem() == Items.INK_SACK) {
              arraylist.add(Integer.valueOf(ItemDye.c[itemstack2.getData()]));
            } else if (itemstack2.getItem() == Items.GLOWSTONE_DUST) {
              nbttagcompound1.setBoolean("Flicker", true);
            } else if (itemstack2.getItem() == Items.DIAMOND) {
              nbttagcompound1.setBoolean("Trail", true);
            } else if (itemstack2.getItem() == Items.FIREBALL) {
              b0 = 1;
            } else if (itemstack2.getItem() == Items.FEATHER) {
              b0 = 4;
            } else if (itemstack2.getItem() == Items.GOLD_NUGGET) {
              b0 = 2;
            } else if (itemstack2.getItem() == Items.SKULL) {
              b0 = 3;
            }
          }
        }

        int[] aint = new int[arraylist.size()];

        for (int j2 = 0; j2 < aint.length; ++j2) {
          aint[j2] = ((Integer) arraylist.get(j2)).intValue();
        }

        nbttagcompound1.setIntArray("Colors", aint);
        nbttagcompound1.setByte("Type", b0);
        nbttagcompound.set("Explosion", nbttagcompound1);
        a.setTag(nbttagcompound);
        return true;
      } else if (j == 0 && i == 0 && l == 1 && k > 0 && k == i1) {
        ArrayList arraylist1 = new ArrayList();

        for (int k2 = 0; k2 < inventorycrafting.getSize(); ++k2) {
          ItemStack itemstack3 = inventorycrafting.getItem(k2);

          if (itemstack3 != null) {
            if (itemstack3.getItem() == Items.INK_SACK) {
              arraylist1.add(Integer.valueOf(ItemDye.c[itemstack3.getData()]));
            } else if (itemstack3.getItem() == Items.FIREWORKS_CHARGE) {
              a = itemstack3.cloneItemStack();
              a.count = 1;
            }
          }
        }

        int[] aint1 = new int[arraylist1.size()];

        for (int l2 = 0; l2 < aint1.length; ++l2) {
          aint1[l2] = ((Integer) arraylist1.get(l2)).intValue();
        }

        if (a != null && a.hasTag()) {
          NBTTagCompound nbttagcompound2 = a.getTag().getCompound("Explosion");

          if (nbttagcompound2 == null) return false;
          else {
            nbttagcompound2.setIntArray("FadeColors", aint1);
            return true;
          }
        } else return false;
      } else return false;
    } else return false;
  }
  @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);
      }
    }
  }