/** Find recipes excluding one or more recipe types */
  public static ItemStack findMatchingRecipeExcluding(
      InventoryCrafting inv, World world, Class... excluding) {
    int i = 0;
    ItemStack itemstack = null;
    ItemStack itemstack1 = null;
    int j;
    List recipes = CraftingManager.getInstance().getRecipeList();

    for (j = 0; j < inv.getSizeInventory(); ++j) {
      ItemStack itemstack2 = inv.getStackInSlot(j);

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

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

        ++i;
      }
    }

    if (i == 2
        && itemstack.getItem() == itemstack1.getItem()
        && itemstack.stackSize == 1
        && itemstack1.stackSize == 1
        && itemstack.getItem().isRepairable()) {
      Item item = itemstack.getItem();
      int j1 = item.getMaxDamage() - itemstack.getItemDamage(); // getItemDamageForDisplay
      int k = item.getMaxDamage() - itemstack1.getItemDamage();
      int l = j1 + k + item.getMaxDamage() * 5 / 100;
      int i1 = item.getMaxDamage() - l;

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

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

        // 1.1.1 Botania fix (try catch)
        try {
          if ((!Arrays.asList(excluding).contains(irecipe.getClass()))
              && irecipe.matches(inv, world)) {
            return irecipe.getCraftingResult(inv);
          }
        } catch (Exception e) {
        }
      }

      return null;
    }
  }
 public int compareRecipes(IRecipe par1IRecipe, IRecipe par2IRecipe) {
   return par1IRecipe instanceof ShapelessRecipes && par2IRecipe instanceof ShapedRecipes
       ? 1
       : (par2IRecipe instanceof ShapelessRecipes && par1IRecipe instanceof ShapedRecipes
           ? -1
           : (par2IRecipe.getRecipeSize() < par1IRecipe.getRecipeSize()
               ? -1
               : (par2IRecipe.getRecipeSize() > par1IRecipe.getRecipeSize() ? 1 : 0)));
 }
예제 #3
0
 public static void removeAnyRecipe(ItemStack resultItem) {
   List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
   for (int i = 0; i < recipes.size(); i++) {
     IRecipe tmpRecipe = recipes.get(i);
     ItemStack recipeResult = tmpRecipe.getRecipeOutput();
     if (ItemStack.areItemStacksEqual(resultItem, recipeResult)) {
       recipes.remove(i--);
     }
   }
 }
예제 #4
0
  public ItemStack findMatchingRecipe(InventoryCrafting par1InventoryCrafting, World par2World) {
    int var3 = 0;
    ItemStack var4 = null;
    ItemStack var5 = null;

    for (int var6 = 0; var6 < par1InventoryCrafting.getSizeInventory(); ++var6) {
      ItemStack var7 = par1InventoryCrafting.getStackInSlot(var6);

      if (var7 != null) {
        if (var3 == 0) {
          var4 = var7;
        }

        if (var3 == 1) {
          var5 = var7;
        }

        ++var3;
      }
    }

    if (var3 == 2
        && var4.itemID == var5.itemID
        && var4.stackSize == 1
        && var5.stackSize == 1
        && Item.itemsList[var4.itemID].isRepairable()) {
      Item var13 = Item.itemsList[var4.itemID];
      int var14 = var13.getMaxDamage() - var4.getItemDamageForDisplay();
      int var8 = var13.getMaxDamage() - var5.getItemDamageForDisplay();
      int var9 = var14 + var8 + var13.getMaxDamage() * 5 / 100;
      int var10 = var13.getMaxDamage() - var9;

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

      return new ItemStack(var4.itemID, 1, var10);
    } else {
      Iterator var11 = this.recipes.iterator();
      IRecipe var12;

      do {
        if (!var11.hasNext()) {
          return null;
        }

        var12 = (IRecipe) var11.next();
      } while (!var12.matches(par1InventoryCrafting, par2World));

      return var12.getCraftingResult(par1InventoryCrafting);
    }
  }
 protected void drawAuxData(int posX, int posY) {
   // ChromaBookData.drawCastingRecipe(fontRendererObj, ri, this.getActiveRecipe(), subpage, posX,
   // posY);
   IRecipe ir = this.getActiveRecipe();
   ItemStack[] arr = ReikaRecipeHelper.getPermutedRecipeArray(ir);
   for (int i = 0; i < arr.length; i++) {
     ItemStack is = arr[i];
     if (is != null) {
       int x = posX + 54 + (i % 3) * 18;
       int y = posY + 10 + (i / 3) * 18;
       api.drawItemStackWithTooltip(itemRender, fontRendererObj, is, x, y);
     }
   }
   api.drawItemStackWithTooltip(
       itemRender, fontRendererObj, ir.getRecipeOutput(), posX + 7, posY + 5);
 }
예제 #6
0
  @SuppressWarnings("unchecked")
  private void removeRecipes(String toDelete) {
    ItemStack resultItem = new ItemStack((Item) Item.itemRegistry.getObject(toDelete));

    List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();

    for (int i = 0; i < recipes.size(); i++) {
      IRecipe tmpRecipe = recipes.get(i);
      ItemStack recipeResult = tmpRecipe.getRecipeOutput();
      if (resultItem != null && recipeResult != null) resultItem.stackSize = recipeResult.stackSize;

      if (ItemStack.areItemStacksEqual(resultItem, recipeResult)) {
        recipes.remove(i--);
      }
    }
  }
예제 #7
0
  public ItemStack func_82787_a(InventoryCrafting p_82787_1_, World p_82787_2_) {
    int var3 = 0;
    ItemStack var4 = null;
    ItemStack var5 = null;

    int var6;
    for (var6 = 0; var6 < p_82787_1_.func_70302_i_(); ++var6) {
      ItemStack var7 = p_82787_1_.func_70301_a(var6);
      if (var7 != null) {
        if (var3 == 0) {
          var4 = var7;
        }

        if (var3 == 1) {
          var5 = var7;
        }

        ++var3;
      }
    }

    if (var3 == 2
        && var4.field_77993_c == var5.field_77993_c
        && var4.field_77994_a == 1
        && var5.field_77994_a == 1
        && Item.field_77698_e[var4.field_77993_c].func_77645_m()) {
      Item var11 = Item.field_77698_e[var4.field_77993_c];
      int var13 = var11.func_77612_l() - var4.func_77952_i();
      int var8 = var11.func_77612_l() - var5.func_77952_i();
      int var9 = var13 + var8 + var11.func_77612_l() * 5 / 100;
      int var10 = var11.func_77612_l() - var9;
      if (var10 < 0) {
        var10 = 0;
      }

      return new ItemStack(var4.field_77993_c, 1, var10);
    } else {
      for (var6 = 0; var6 < this.field_77597_b.size(); ++var6) {
        IRecipe var12 = (IRecipe) this.field_77597_b.get(var6);
        if (var12.func_77569_a(p_82787_1_, p_82787_2_)) {
          return var12.func_77572_b(p_82787_1_);
        }
      }

      return null;
    }
  }
예제 #8
0
 @Override
 public void renderScreen(GuiScreen guiScreen, int posX, int posY) {
   GuiGardenomiconContent gui = (GuiGardenomiconContent) guiScreen;
   renderCraftingRecipe(gui, recipe);
   renderItem(gui, gui.left + 65, posY + 10, recipe.getRecipeOutput());
   this.mouseX = posX;
   this.mouseY = posY;
 }
예제 #9
0
파일: StatList.java 프로젝트: McSwede/XIV
  /**
   * Initializes statistics related to craftable items. Is only called after both block and item
   * stats have been initialized.
   */
  private static void initCraftableStats() {
    HashSet var0 = Sets.newHashSet();
    Iterator var1 = CraftingManager.getInstance().getRecipeList().iterator();

    while (var1.hasNext()) {
      IRecipe var2 = (IRecipe) var1.next();

      if (var2.getRecipeOutput() != null) {
        var0.add(var2.getRecipeOutput().getItem());
      }
    }

    var1 = FurnaceRecipes.instance().getSmeltingList().values().iterator();

    while (var1.hasNext()) {
      ItemStack var5 = (ItemStack) var1.next();
      var0.add(var5.getItem());
    }

    var1 = var0.iterator();

    while (var1.hasNext()) {
      Item var6 = (Item) var1.next();

      if (var6 != null) {
        int var3 = Item.getIdFromItem(var6);
        String var4 = func_180204_a(var6);

        if (var4 != null) {
          objectCraftStats[var3] =
              (new StatCrafting(
                      "stat.craftItem.",
                      var4,
                      new ChatComponentTranslation(
                          "stat.craftItem",
                          new Object[] {(new ItemStack(var6)).getChatComponent()}),
                      var6))
                  .registerStat();
        }
      }
    }

    replaceAllSimilarBlocks(objectCraftStats);
  }
  public ItemStack getCraftingResult(TileSoulWorkBench soulworkbench) {
    InventoryCrafting InventoryCraftingSoulWorkBench = soulworkbench.getCraftingInventory();

    Iterator var11 = this.recipes.iterator();
    IRecipe var12;

    do {
      if (!var11.hasNext()) {
        // this.nSoulEnergyRequired = 0;
        return null;
      }

      var12 = (IRecipe) var11.next();
    } while (!var12.matches(InventoryCraftingSoulWorkBench, null));

    this.nSoulEnergyRequired = ((SoulWorkBenchShapedRecipes) var12).getCraftingResultSoulEnergy();

    return var12.getCraftingResult(InventoryCraftingSoulWorkBench);
  }
  @Override
  public void loadCraftingRecipes(ItemStack result) {
    List<IRecipe> allrecipes = CraftingManager.getInstance().getRecipeList();
    for (IRecipe irecipe : allrecipes) {
      if (NEIServerUtils.areStacksSameTypeCrafting(irecipe.getRecipeOutput(), result)) {
        CachedShapelessRecipe recipe = null;
        if (irecipe instanceof ShapelessRecipes) {
          recipe = shapelessRecipe((ShapelessRecipes) irecipe);
        } else if (irecipe instanceof ShapelessOreRecipe) {
          recipe = forgeShapelessRecipe((ShapelessOreRecipe) irecipe);
        }

        if (recipe == null) {
          continue;
        }

        arecipes.add(recipe);
      }
    }
  }
예제 #12
0
 @Override
 public List<Object> getInputs(IRecipe recipe) {
   List<Object> ingredients = null;
   if (recipeClass != null
       && recipeClass.isInstance(recipe)
       && inputField != null
       && checkItemEquals != null) {
     try {
       Object[] input = (Object[]) inputField.get(recipe);
       ingredients = new ArrayList<Object>(Arrays.asList(input));
     } catch (Exception e) {
       Ref.LOGGER.warn("[Mekanism Recipe Scan] " + recipe.getClass().getName() + " failed!", e);
       return null;
     }
   }
   return ingredients;
 }
  @Override
  public void onCrafting(EntityPlayer player, ItemStack item, IInventory craftMatrix) {

    if (craftMatrix instanceof InventoryCrafting) {

      EntityPlayerMP fp;
      if (player instanceof EntityPlayerMP) fp = (EntityPlayerMP) player;
      else fp = BukkitContainer.MOD_PLAYER;

      InventoryCrafting inv = (InventoryCrafting) craftMatrix;
      Iterator<IRecipe> irec = (Iterator<IRecipe>) CraftingManager.getInstance().recipes.iterator();
      IRecipe targ = null;
      while (irec.hasNext()) {
        IRecipe r = irec.next();
        if (r.matches(inv, player.worldObj)) {
          targ = r;
          break;
        }
      }

      if (targ == null) return;

      Recipe recipe = new BukkitRecipe(targ);

      InventoryView what =
          new CraftInventoryView(
              CraftPlayerCache.getCraftPlayer(fp),
              new CraftInventoryCrafting(inv, player.inventory),
              inv.eventHandler);

      // Should be slot of crafting container, will only be trouble if ever have crafting table with
      // more than one slot
      CraftItemEvent ev = new CraftItemEvent(recipe, what, SlotType.CRAFTING, 0, false, false);

      Bukkit.getPluginManager().callEvent(ev);
      if (ev.isCancelled()) {
        // Believe it is too late to do this, this just clears the workbench which has already
        // happened
        // if (!(inv.eventHandler instanceof ContainerWorkbench)) return;
        // ContainerWorkbench cc = (ContainerWorkbench) inv.eventHandler;
        // InventoryCraftResult iv = (InventoryCraftResult) cc.craftResult;
        // iv.setInventorySlotContents(0, null);

        int itemsToRemove = item.stackSize > 0 ? item.stackSize : 1;

        // Is item in hand (single craft)
        if ((player.inventory.getItemStack() != null)
            && (player.inventory.getItemStack().getItem().itemID == item.getItem().itemID)) {
          itemsToRemove = itemsToRemove - player.inventory.getItemStack().stackSize;
          player.inventory.setItemStack(null); // Remove it
          ((EntityPlayerMP) player).updateHeldItem();
        }

        // If item not removed from hand, or not all crafted were removed from hand
        if (itemsToRemove > 0) {
          for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
            if (player.inventory.getStackInSlot(i) != null
                && player.inventory.getStackInSlot(i).getItem().itemID == item.getItem().itemID) {
              int stackSize = ((InventoryPlayer) player.inventory).getStackInSlot(i).stackSize;
              if (stackSize < itemsToRemove) {
                ((InventoryPlayer) player.inventory).decrStackSize(i, stackSize);
                itemsToRemove = itemsToRemove - stackSize;
              } else {
                ((InventoryPlayer) player.inventory).decrStackSize(i, itemsToRemove);
                itemsToRemove = 0;
              }

              if (itemsToRemove == 0) break;
            }
          }
        }

        if (itemsToRemove == 0) // Assume we couldn't remove item, so dont give back ingredients
        {
          // Add ingredients back
          for (int i = 0; i < inv.getSizeInventory(); i++) {
            if (inv.getStackInSlot(i) != null && inv.getStackInSlot(i).stackSize != 0) {
              ItemStack putBack = inv.getStackInSlot(i).copy();
              putBack.stackSize = 1;
              player.inventory.addItemStackToInventory(putBack);
            }
          }
        }
      }
    }
  }
 private ItemStack getRecipeOutput() {
   if (internalInventoryCrafting == null || currentRecipe == null) {
     return null;
   }
   return currentRecipe.getCraftingResult(internalInventoryCrafting);
 }
 private boolean hasIngredients() {
   return currentRecipe != null && currentRecipe.matches(internalInventoryCrafting, worldObj);
 }
예제 #16
0
 /** @param recipe a vanilla crafting recipe. */
 public ResearchPage(IRecipe recipe) {
   this.type = PageType.NORMAL_CRAFTING;
   this.recipe = recipe;
   this.recipeOutput = recipe.getRecipeOutput();
 }
예제 #17
0
  @SuppressWarnings("unchecked")
  public void generateRecyclingRecipes() {

    Collections.addAll(blacklist, Config.alloyFurnaceBlacklist);
    List<Item> blacklist = new ArrayList<Item>();
    for (String configString : this.blacklist) {
      Item item = GameData.getItemRegistry().getObject(configString);
      if (item != null) {
        blacklist.add(item);
      } else {
        BluePower.log.info(
            "Config entry \""
                + configString
                + "\" not an existing item/block name! Will not be added to the blacklist");
      }
    }

    List<IRecipe> registeredRecipes = new ArrayList<IRecipe>();
    for (ItemStack recyclingItem : bufferedRecyclingItems) {
      List<IRecipe> recipes = CraftingManager.getInstance().getRecipeList();
      for (IRecipe recipe : recipes) {
        try {
          int recyclingAmount = 0;
          if (recipe instanceof ShapedRecipes) {
            ShapedRecipes shaped = (ShapedRecipes) recipe;
            if (shaped.recipeItems != null) {
              for (ItemStack input : shaped.recipeItems) {
                if (input != null && ItemStackUtils.isItemFuzzyEqual(input, recyclingItem)) {
                  recyclingAmount++;
                }
              }
            }
          } else if (recipe instanceof ShapelessRecipes) {
            ShapelessRecipes shapeless = (ShapelessRecipes) recipe;
            if (shapeless.recipeItems != null) {
              for (ItemStack input : (List<ItemStack>) shapeless.recipeItems) {
                if (input != null && ItemStackUtils.isItemFuzzyEqual(input, recyclingItem)) {
                  recyclingAmount++;
                }
              }
            }
          } else if (recipe instanceof ShapedOreRecipe) {
            ShapedOreRecipe shapedOreRecipe = (ShapedOreRecipe) recipe;
            if (shapedOreRecipe.getInput() != null) {
              for (Object input : shapedOreRecipe.getInput()) {
                if (input != null) {
                  List<ItemStack> itemList;
                  if (input instanceof ItemStack) {
                    itemList = new ArrayList<ItemStack>();
                    itemList.add((ItemStack) input);
                  } else {
                    itemList = (List<ItemStack>) input;
                  }
                  for (ItemStack item : itemList) {
                    if (item != null && ItemStackUtils.isItemFuzzyEqual(item, recyclingItem)) {
                      recyclingAmount++;
                      break;
                    }
                  }
                }
              }
            }
          } else if (recipe instanceof ShapelessOreRecipe) {
            ShapelessOreRecipe shapeless = (ShapelessOreRecipe) recipe;
            for (Object input : shapeless.getInput()) {
              if (input != null) {
                List<ItemStack> itemList;
                if (input instanceof ItemStack) {
                  itemList = new ArrayList<ItemStack>();
                  itemList.add((ItemStack) input);
                } else {
                  itemList = (List<ItemStack>) input;
                }
                for (ItemStack item : itemList) {
                  if (item != null && ItemStackUtils.isItemFuzzyEqual(item, recyclingItem)) {
                    recyclingAmount++;
                    break;
                  }
                }
              }
            }
          }
          if (recyclingAmount > 0 && !registeredRecipes.contains(recipe)) {
            if (blacklist.contains(recipe.getRecipeOutput().getItem())) {
              BluePower.log.info(
                  "Skipped adding item/block "
                      + recipe.getRecipeOutput().getDisplayName()
                      + " to the Alloy Furnace recipes.");
              continue;
            }
            registeredRecipes.add(recipe);
            addRecipe(
                new ItemStack(
                    recyclingItem.getItem(), recyclingAmount, recyclingItem.getItemDamage()),
                recipe.getRecipeOutput());
          }
        } catch (Throwable e) {
          BluePower.log.error(
              "Error when generating an Alloy Furnace recipe for item "
                  + recyclingItem.getDisplayName()
                  + ", recipe output: "
                  + recipe.getRecipeOutput().getDisplayName());
          e.printStackTrace();
        }
      }
    }
  }
  @Override
  public void serverPacketData(INetworkInfo manager, AppEngPacket packet, EntityPlayer player) {
    EntityPlayerMP pmp = (EntityPlayerMP) player;
    Container con = pmp.openContainer;

    if (con instanceof IContainerCraftingPacket) {
      IContainerCraftingPacket cct = (IContainerCraftingPacket) con;
      IGridNode node = cct.getNetworkNode();
      if (node != null) {
        IGrid grid = node.getGrid();
        if (grid == null) {
          return;
        }

        IStorageGrid inv = grid.getCache(IStorageGrid.class);
        IEnergyGrid energy = grid.getCache(IEnergyGrid.class);
        ISecurityGrid security = grid.getCache(ISecurityGrid.class);
        IInventory craftMatrix = cct.getInventoryByName("crafting");
        IInventory playerInventory = cct.getInventoryByName("player");

        Actionable realForFake = cct.useRealItems() ? Actionable.MODULATE : Actionable.SIMULATE;

        if (inv != null && this.recipe != null && security != null) {
          InventoryCrafting testInv = new InventoryCrafting(new ContainerNull(), 3, 3);
          for (int x = 0; x < 9; x++) {
            if (this.recipe[x] != null && this.recipe[x].length > 0) {
              testInv.setInventorySlotContents(x, this.recipe[x][0]);
            }
          }

          IRecipe r = Platform.findMatchingRecipe(testInv, pmp.worldObj);

          if (r != null && security.hasPermission(player, SecurityPermissions.EXTRACT)) {
            ItemStack is = r.getCraftingResult(testInv);

            if (is != null) {
              IMEMonitor<IAEItemStack> storage = inv.getItemInventory();
              IItemList all = storage.getStorageList();
              IPartitionList<IAEItemStack> filter = ItemViewCell.createFilter(cct.getViewCells());

              for (int x = 0; x < craftMatrix.getSizeInventory(); x++) {
                ItemStack patternItem = testInv.getStackInSlot(x);

                ItemStack currentItem = craftMatrix.getStackInSlot(x);
                if (currentItem != null) {
                  testInv.setInventorySlotContents(x, currentItem);
                  ItemStack newItemStack =
                      r.matches(testInv, pmp.worldObj) ? r.getCraftingResult(testInv) : null;
                  testInv.setInventorySlotContents(x, patternItem);

                  if (newItemStack == null || !Platform.isSameItemPrecise(newItemStack, is)) {
                    IAEItemStack in = AEItemStack.create(currentItem);
                    if (in != null) {
                      IAEItemStack out =
                          realForFake == Actionable.SIMULATE
                              ? null
                              : Platform.poweredInsert(energy, storage, in, cct.getSource());
                      if (out != null) {
                        craftMatrix.setInventorySlotContents(x, out.getItemStack());
                      } else {
                        craftMatrix.setInventorySlotContents(x, null);
                      }

                      currentItem = craftMatrix.getStackInSlot(x);
                    }
                  }
                }

                // True if we need to fetch an item for the recipe
                if (patternItem != null && currentItem == null) {
                  // Grab from network by recipe
                  ItemStack whichItem =
                      Platform.extractItemsByRecipe(
                          energy,
                          cct.getSource(),
                          storage,
                          player.worldObj,
                          r,
                          is,
                          testInv,
                          patternItem,
                          x,
                          all,
                          realForFake,
                          filter);

                  // If that doesn't get it, grab exact items from network (?)
                  // TODO see if this code is necessary
                  if (whichItem == null) {
                    for (int y = 0; y < this.recipe[x].length; y++) {
                      IAEItemStack request = AEItemStack.create(this.recipe[x][y]);
                      if (request != null) {
                        if (filter == null || filter.isListed(request)) {
                          request.setStackSize(1);
                          IAEItemStack out =
                              Platform.poweredExtraction(energy, storage, request, cct.getSource());
                          if (out != null) {
                            whichItem = out.getItemStack();
                            break;
                          }
                        }
                      }
                    }
                  }

                  // If that doesn't work, grab from the player's inventory
                  if (whichItem == null && playerInventory != null) {
                    whichItem = extractItemFromPlayerInventory(player, realForFake, patternItem);
                  }

                  craftMatrix.setInventorySlotContents(x, whichItem);
                }
              }
              con.onCraftMatrixChanged(craftMatrix);
            }
          }
        }
      }
    }
  }
  public void craftOrGetItem(final PacketPatternSlot packetPatternSlot) {
    if (packetPatternSlot.slotItem != null && this.getCellInventory() != null) {
      final IAEItemStack out = packetPatternSlot.slotItem.copy();
      InventoryAdaptor inv = new AdaptorPlayerHand(this.getPlayerInv().player);
      final InventoryAdaptor playerInv =
          InventoryAdaptor.getAdaptor(this.getPlayerInv().player, ForgeDirection.UNKNOWN);

      if (packetPatternSlot.shift) {
        inv = playerInv;
      }

      if (inv.simulateAdd(out.getItemStack()) != null) {
        return;
      }

      final IAEItemStack extracted =
          Platform.poweredExtraction(
              this.getPowerSource(), this.getCellInventory(), out, this.getActionSource());
      final EntityPlayer p = this.getPlayerInv().player;

      if (extracted != null) {
        inv.addItems(extracted.getItemStack());
        if (p instanceof EntityPlayerMP) {
          this.updateHeld((EntityPlayerMP) p);
        }
        this.detectAndSendChanges();
        return;
      }

      final InventoryCrafting ic = new InventoryCrafting(new ContainerNull(), 3, 3);
      final InventoryCrafting real = new InventoryCrafting(new ContainerNull(), 3, 3);

      for (int x = 0; x < 9; x++) {
        ic.setInventorySlotContents(
            x,
            packetPatternSlot.pattern[x] == null
                ? null
                : packetPatternSlot.pattern[x].getItemStack());
      }

      final IRecipe r = Platform.findMatchingRecipe(ic, p.worldObj);

      if (r == null) {
        return;
      }

      final IMEMonitor<IAEItemStack> storage = this.getPatternTerminal().getItemInventory();
      final IItemList<IAEItemStack> all = storage.getStorageList();

      final ItemStack is = r.getCraftingResult(ic);

      for (int x = 0; x < ic.getSizeInventory(); x++) {
        if (ic.getStackInSlot(x) != null) {
          final ItemStack pulled =
              Platform.extractItemsByRecipe(
                  this.getPowerSource(),
                  this.getActionSource(),
                  storage,
                  p.worldObj,
                  r,
                  is,
                  ic,
                  ic.getStackInSlot(x),
                  x,
                  all,
                  Actionable.MODULATE,
                  ItemViewCell.createFilter(this.getViewCells()));
          real.setInventorySlotContents(x, pulled);
        }
      }

      final IRecipe rr = Platform.findMatchingRecipe(real, p.worldObj);

      if (rr == r && Platform.isSameItemPrecise(rr.getCraftingResult(real), is)) {
        final SlotCrafting sc = new SlotCrafting(p, real, this.cOut, 0, 0, 0);
        sc.onPickupFromSlot(p, is);

        for (int x = 0; x < real.getSizeInventory(); x++) {
          final ItemStack failed = playerInv.addItems(real.getStackInSlot(x));

          if (failed != null) {
            p.dropPlayerItemWithRandomChoice(failed, false);
          }
        }

        inv.addItems(is);
        if (p instanceof EntityPlayerMP) {
          this.updateHeld((EntityPlayerMP) p);
        }
        this.detectAndSendChanges();
      } else {
        for (int x = 0; x < real.getSizeInventory(); x++) {
          final ItemStack failed = real.getStackInSlot(x);
          if (failed != null) {
            this.getCellInventory()
                .injectItems(
                    AEItemStack.create(failed),
                    Actionable.MODULATE,
                    new MachineSource(this.getPatternTerminal()));
          }
        }
      }
    }
  }
예제 #20
0
  @Override
  public void updateEntity() {
    super.updateEntity();

    if (getEnergy() >= getRequiredEnergy() && getEnergy() > 0) {
      ItemStack input = this.getStackInSlot(0);

      if (input == null) {
        return;
      }

      EntityPlayer internalPlayer = getInternalPlayer().get();

      if (craftSlot == null) {
        craftSlot = new SlotCrafting(internalPlayer, crafting, this, 1, 0, 0);
      }

      if (input.getItem() instanceof ItemPackage) {
        // Try a recipe made out of the package's contents
        NBTTagCompound tag = NBTUtils.getItemData(input);
        for (int i = 0; i < 9; i++) {
          if (tag.hasKey("item" + i)) {
            ItemStack is = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("item" + i));
            if (is != null) {
              crafting.setInventorySlotContents(i, is);
            } else {
              return;
            }
          } else {
            crafting.setInventorySlotContents(i, null);
          }
        }
      } else {
        // Try a shapeless recipe made from just that item
        ItemStack input2 = input.copy();
        input2.stackSize = 1;
        crafting.setInventorySlotContents(0, input2);
        for (int i = 1; i < 9; i++) {
          crafting.setInventorySlotContents(i, null);
        }
      }

      IRecipe recipe = crafting.findRecipe();
      ItemStack result = recipe != null ? recipe.getCraftingResult(crafting).copy() : null;

      addEnergy(-getRequiredEnergy());

      if (result != null) {
        craftSlot.onPickupFromSlot(internalPlayer, result);
        handleLeftoverItems(crafting);
        handleLeftoverItems(internalPlayer.inventory);

        for (int i = 1; i <= 4; i++) {
          ItemStack inside = inv.getStackInSlot(i);

          if (inside == null || inside.stackSize <= 0) {
            inv.setInventorySlotContents(i, result.copy());
            result.stackSize = 0;
            break;
          } else if (StackHelper.canStacksMerge(inside, result)) {
            result.stackSize -= StackHelper.mergeStacks(result, inside, true);

            if (result.stackSize == 0) {
              break;
            }
          }
        }

        if (result.stackSize > 0) {
          EntityItem entityitem =
              new EntityItem(worldObj, xCoord + 0.5, yCoord + 0.7, zCoord + 0.5, result.copy());

          worldObj.spawnEntityInWorld(entityitem);
          result.stackSize = 0;
        }
        decrStackSize(0, 1);
      } else {
        ItemStack outputSlot = getStackInSlot(1);
        if (outputSlot == null) {
          setInventorySlotContents(1, getStackInSlot(0));
          setInventorySlotContents(0, null);
        }
      }
    }
  }
예제 #21
0
  @SuppressWarnings("unchecked")
  @SideOnly(Side.CLIENT)
  public void renderCraftingRecipe(IGuiLexiconEntry gui, IRecipe recipe) {
    if (recipe instanceof ExtremeShapedRecipe) {
      ExtremeShapedRecipe shaped = (ExtremeShapedRecipe) recipe;

      for (int y = 0; y < shaped.recipeHeight; y++)
        for (int x = 0; x < shaped.recipeWidth; x++)
          renderItemAtLudicrousGridPos(
              gui, x, y, shaped.recipeItems[y * shaped.recipeWidth + x], true);
    } else if (recipe instanceof ExtremeShapedOreRecipe) {
      oreDictRecipe = true;
    } else if (recipe instanceof ExtremeShapelessRecipe) {
      shapelessRecipe = true;
    } else if (recipe instanceof ShapelessOreRecipe) {
      ShapelessOreRecipe shapeless = (ShapelessOreRecipe) recipe;

      drawGrid:
      {
        for (int y = 0; y < 3; y++)
          for (int x = 0; x < 3; x++) {
            int index = y * 3 + x;

            if (index >= shapeless.getRecipeSize()) break drawGrid;

            Object input = shapeless.getInput().get(index);
            if (input != null)
              renderItemAtLudicrousGridPos(
                  gui,
                  x,
                  y,
                  input instanceof ItemStack
                      ? (ItemStack) input
                      : ((ArrayList<ItemStack>) input).get(0),
                  true);
          }
      }

      shapelessRecipe = true;
      oreDictRecipe = true;
    }
    /*if(recipe instanceof ShapedRecipes) {
    	ShapedRecipes shaped = (ShapedRecipes)recipe;

    	for(int y = 0; y < shaped.recipeHeight; y++)
    		for(int x = 0; x < shaped.recipeWidth; x++)
    			renderItemAtGridPos(gui, 1 + x, 1 + y, shaped.recipeItems[y * shaped.recipeWidth + x], true);
    } else if(recipe instanceof ShapedOreRecipe) {
    	ShapedOreRecipe shaped = (ShapedOreRecipe) recipe;
    	int width = (Integer) ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, shaped, 4);
    	int height = (Integer) ReflectionHelper.getPrivateValue(ShapedOreRecipe.class, shaped, 5);

    	for(int y = 0; y < height; y++)
    		for(int x = 0; x < width; x++) {
    			Object input = shaped.getInput()[y * width + x];
    			if(input != null)
    				renderItemAtGridPos(gui, 1 + x, 1 + y, input instanceof ItemStack ? (ItemStack) input : ((ArrayList<ItemStack>) input).get(0), true);
    		}

    	oreDictRecipe = true;
    } else if(recipe instanceof ShapelessRecipes) {
    	ShapelessRecipes shapeless = (ShapelessRecipes) recipe;

    	drawGrid : {
    		for(int y = 0; y < 3; y++)
    			for(int x = 0; x < 3; x++) {
    				int index = y * 3 + x;

    				if(index >= shapeless.recipeItems.size())
    					break drawGrid;

    				renderItemAtGridPos(gui, 1 + x, 1 + y, (ItemStack) shapeless.recipeItems.get(index), true);
    			}
    	}

    	shapelessRecipe = true;
    } else if(recipe instanceof ShapelessOreRecipe) {
    	ShapelessOreRecipe shapeless = (ShapelessOreRecipe) recipe;

    	drawGrid : {
    		for(int y = 0; y < 3; y++)
    			for(int x = 0; x < 3; x++) {
    				int index = y * 3 + x;

    				if(index >= shapeless.getRecipeSize())
    					break drawGrid;

    				Object input = shapeless.getInput().get(index);
    				if(input != null)
    					renderItemAtGridPos(gui, 1 + x, 1 + y, input instanceof ItemStack ? (ItemStack) input : ((ArrayList<ItemStack>) input).get(0), true);
    			}
    	}

    	shapelessRecipe = true;
    	oreDictRecipe = true;
    }*/

    renderItemAtLudicrousGridPos(gui, 4, -1, recipe.getRecipeOutput(), false);
  }
예제 #22
0
 public BukkitRecipe(IRecipe recipe) {
   this.result = new CraftItemStack(recipe.getRecipeOutput());
 }
  private boolean getDeconstructionRecipe() {
    ItemStack checkStack = getStackInSlot(0);
    ArrayList<ItemStack> recipeItems = new ArrayList<ItemStack>();
    if (checkStack == null) return false;
    if (checkStack.getItem() == ItemsCommonProxy.spell) {
      int numStages = SpellUtils.instance.numStages(checkStack);

      for (int i = 0; i < numStages; ++i) {
        ISpellShape shape = SpellUtils.instance.getShapeForStage(checkStack, i);
        Object[] componentParts = shape.getRecipeItems();
        if (componentParts != null) {
          for (Object o : componentParts) {
            ItemStack stack = objectToItemStack(o);
            if (stack != null) {
              if (stack.getItem() == ItemsCommonProxy.bindingCatalyst) {
                stack.setItemDamage(
                    ((Binding) SkillManager.instance.getSkill("Binding"))
                        .getBindingType(checkStack));
              }
              recipeItems.add(stack.copy());
            }
          }
        }
        ISpellComponent[] components = SpellUtils.instance.getComponentsForStage(checkStack, i);
        for (ISpellComponent component : components) {
          componentParts = component.getRecipeItems();
          if (componentParts != null) {
            for (Object o : componentParts) {
              ItemStack stack = objectToItemStack(o);
              if (stack != null) {
                if (stack.getItem() == ItemsCommonProxy.crystalPhylactery) {
                  ItemsCommonProxy.crystalPhylactery.setSpawnClass(
                      stack,
                      ((Summon) SkillManager.instance.getSkill("Summon"))
                          .getSummonType(checkStack));
                  ItemsCommonProxy.crystalPhylactery.addFill(stack, 100);
                }
                recipeItems.add(stack.copy());
              }
            }
          }
        }
        ISpellModifier[] modifiers = SpellUtils.instance.getModifiersForStage(checkStack, i);
        for (ISpellModifier modifier : modifiers) {
          componentParts = modifier.getRecipeItems();
          if (componentParts != null) {
            for (Object o : componentParts) {
              ItemStack stack = objectToItemStack(o);
              if (stack != null) recipeItems.add(stack.copy());
            }
          }
        }
      }

      int numShapeGroups = SpellUtils.instance.numShapeGroups(checkStack);
      for (int i = 0; i < numShapeGroups; ++i) {
        int[] parts = SpellUtils.instance.getShapeGroupParts(checkStack, i);
        for (int partID : parts) {
          ISkillTreeEntry entry = SkillManager.instance.getSkill(partID);
          if (entry != null && entry instanceof ISpellPart) {
            Object[] componentParts = ((ISpellPart) entry).getRecipeItems();
            if (componentParts != null) {
              for (Object o : componentParts) {
                ItemStack stack = objectToItemStack(o);
                if (stack != null) {
                  if (stack.getItem() == ItemsCommonProxy.bindingCatalyst) {
                    stack.setItemDamage(
                        ((Binding) SkillManager.instance.getSkill("Binding"))
                            .getBindingType(checkStack));
                  }
                  recipeItems.add(stack.copy());
                }
              }
            }
          }
        }
      }

      deconstructionRecipe = recipeItems.toArray(new ItemStack[recipeItems.size()]);
      return true;
    } else {
      IRecipe recipe = RecipeUtilities.getRecipeFor(checkStack);
      if (recipe == null) return false;
      Object[] recipeParts = RecipeUtilities.getRecipeItems(recipe);
      if (recipeParts != null && checkStack != null && recipe.getRecipeOutput() != null) {
        if (recipe.getRecipeOutput().getItem() == checkStack.getItem()
            && recipe.getRecipeOutput().getItemDamage() == checkStack.getItemDamage()
            && recipe.getRecipeOutput().stackSize > 1) return false;

        for (Object o : recipeParts) {
          ItemStack stack = objectToItemStack(o);
          if (stack != null) {
            stack.stackSize = 1;
            recipeItems.add(stack.copy());
          }
        }
      }
      deconstructionRecipe = recipeItems.toArray(new ItemStack[recipeItems.size()]);
      return true;
    }
  }