private void dropBlocks(World world, int x, int y, int z) {
    Block drop = world.getBlock(x, y, z);
    if (drop == Blocks.air) return;
    int dropmeta = world.getBlockMetadata(x, y, z);
    ItemStack sapling = tree.getSapling();
    Block logID = tree.getTreeType().getLogID();

    Collection<ItemStack> drops = this.getDrops(world, x, y, z, drop, dropmeta);
    if (drop == logID && logID != null) {
      if (rand.nextInt(3) == 0) {
        drops.add(
            ReikaItemHelper.getSizedItemStack(ItemStacks.sawdust.copy(), 1 + rand.nextInt(4)));
      }
    }

    for (ItemStack todrop : drops) {
      if (ReikaItemHelper.matchStacks(todrop, sapling)) {
        if (inv[0] != null && inv[0].stackSize >= inv[0].getMaxStackSize()) {
          if (!this.chestCheck(todrop))
            ReikaItemHelper.dropItem(world, dropx, yCoord - 0.25, dropz, todrop);
        } else ReikaInventoryHelper.addOrSetStack(todrop, inv, 0);
      } else {
        if (!this.chestCheck(todrop))
          ReikaItemHelper.dropItem(world, dropx, yCoord - 0.25, dropz, todrop);
      }
    }
  }
  private void processItem(int i) {
    ItemStack itemstack = RecipesExtractor.getRecipes().getExtractionResult(inv[i]);
    // ReikaJavaLibrary.pConsole("sSmelt :"+(inv[i+4] == null)+"   -
    // "+ReikaItemHelper.matchStacks(inv[i+4], itemstack));
    // ReikaOreHelper ore = i == 0 ? ReikaOreHelper.getFromVanillaOre(inv[i].getItem()) :
    // this.getVanillaOreByItem(inv[i]);
    OreType ore = this.getOreType(inv[i]);
    // ReikaJavaLibrary.pConsole(ore, Side.SERVER);
    int num = this.getSmeltNumber(i, ore, inv[i]);
    if (inv[i + 4] == null) {
      inv[i + 4] = itemstack.copy();
      inv[i + 4].stackSize *= num;
    } else if (ReikaItemHelper.matchStacks(inv[i + 4], itemstack)) inv[i + 4].stackSize += num;

    if (i == 0 && !bedrock && drillTime > 0 && ConfigRegistry.EXTRACTORMAINTAIN.getState()) {
      drillTime--;
    }
    if (i == 3) {
      this.bonusItems(inv[i]);
      RotaryAchievements.EXTRACTOR.triggerAchievement(this.getPlacer());
      if (ore.getRarity() == OreRarity.RARE)
        RotaryAchievements.RAREEXTRACT.triggerAchievement(this.getPlacer());
    }

    inv[i].stackSize--;
    if (i == 1 || i == 2) tank.removeLiquid(125);

    if (inv[i].stackSize <= 0) inv[i] = null;
  }
 private boolean canOperate(ItemStack toMake) {
   if (toMake == null) return false;
   if (power < MINPOWER || omega < MINSPEED) return false;
   if (temperature > this.getFreezingPoint()) return false;
   if (inv[0] == null) return true;
   return ReikaItemHelper.canCombineStacks(toMake, inv[0]);
 }
 @SubscribeEvent
 public void meatGrinding(LivingDropsEvent ev) {
   if (ev.source instanceof GrinderDamage) {
     ItemStack food = ReikaEntityHelper.getFoodItem(ev.entityLiving);
     ev.drops.clear();
     if (food != null) {
       World world = ev.entityLiving.worldObj;
       Random rand = RotaryCraft.rand;
       int num = 4 + rand.nextInt(4) + rand.nextInt(4) + rand.nextInt(4);
       ItemStack is = ReikaItemHelper.getSizedItemStack(food, num);
       ReikaItemHelper.dropItem(
           world, ev.entityLiving.posX, ev.entityLiving.posY, ev.entityLiving.posZ, is);
     }
     ev.setCanceled(true);
   }
 }
 public Fluid getRecipe(ItemStack result) {
   for (Fluid f : recipeList.keySet()) {
     ItemStack is = recipeList.get(f);
     if (ReikaItemHelper.matchStacks(result, is)) return f;
   }
   return null;
 }
 public int getRecipeIndex(ItemStack is) {
   ArrayList<CastingRecipe> li = this.getCraftingRecipes();
   for (int i = 0; i < li.size(); i++) {
     if (ReikaItemHelper.matchStacks(is, li.get(i).getOutput())) return i;
   }
   return 0;
 }
  private boolean canProcess(int i) {
    if (power < machine.getMinPower(i)
        || omega < machine.getMinSpeed(i)
        || torque < machine.getMinTorque(i)) return false;

    if (i == 0 && !bedrock && drillTime <= 0 && ConfigRegistry.EXTRACTORMAINTAIN.getState())
      return false;

    if ((i == 1 || i == 2) && tank.isEmpty()) return false;

    if (inv[i] == null) return false;
    if (inv[i + 4] != null && inv[i + 4].stackSize + 1 >= inv[i + 4].getMaxStackSize())
      return false;
    if (inv[8] != null) {
      if (inv[8].stackSize + 1 > inv[8].getMaxStackSize()) return false;
      if (inv[3] != null) {
        ItemStack bonus = ExtractorBonus.getBonusItemForIngredient(inv[3]);
        if (bonus != null) {
          if (!ReikaItemHelper.matchStacks(bonus, inv[8])) return false;
        }
      }
    }
    OreType ore = this.getOreType(inv[i]);
    if (ore == null) return false;

    ItemStack itemstack = RecipesExtractor.getRecipes().getExtractionResult(inv[i]);
    if (itemstack == null) {
      return false;
    }
    if (inv[i + 4] == null) return true;
    if (!inv[i + 4].isItemEqual(itemstack)) return false;
    if (inv[i + 4].stackSize < this.getInventoryStackLimit()
        && inv[i + 4].stackSize < inv[i + 4].getMaxStackSize()) return true;
    return inv[i + 4].stackSize < itemstack.getMaxStackSize();
  }
 @Override
 public void setDataFromItemStackTag(ItemStack is) {
   isTurbo =
       ReikaItemHelper.matchStacks(is, this.getTile().getCraftedProduct())
           && is.stackTagCompound != null
           && is.stackTagCompound.getBoolean("boosted");
 }
 @Override
 public boolean areConditionsMet() {
   return inv[0] != null
       && ReikaItemHelper.isBlock(inv[0])
       && inv[1] == null
       && overflow.isEmpty();
 }
  @Override
  public void updateEntity(World world, int x, int y, int z, int meta) {
    super.updateTileEntity();
    this.getPowerBelow();
    if (DragonAPICore.debugtest) tank.addLiquid(1000, FluidRegistry.WATER);
    this.testIdle();
    this.throughPut();
    if (world.isRemote) return;
    if (!bedrock) {
      if (ConfigRegistry.EXTRACTORMAINTAIN.getState()) {
        if (drillTime <= 0
            && inv[9] != null
            && ReikaItemHelper.matchStacks(inv[9], ItemStacks.drill)) {
          ReikaInventoryHelper.decrStack(9, inv);
          drillTime = DRILL_LIFE;
        }
      } else {
        drillTime = DRILL_LIFE;
        inv[9] = null;
      }
    }
    boolean[] tickPer = new boolean[4];
    for (int i = 0; i < 4; i++) {
      boolean flag1 = false;

      int n = this.getNumberConsecutiveOperations(i);
      for (int k = 0; k < n; k++) flag1 |= this.doOperation(n > 1, i, tickPer);

      if (flag1) this.markDirty();
    }
    if (ReikaArrayHelper.isAllTrue(tickPer))
      RotaryAchievements.INSANITY.triggerAchievement(this.getPlacer());
  }
 public int getRecipeConsumption(ItemStack result) {
   for (Fluid f : recipeList.keySet()) {
     ItemStack is = recipeList.get(f);
     if (ReikaItemHelper.matchStacks(result, is)) return amounts.get(f);
   }
   return 0;
 }
  @Override
  protected void drawGuiContainerForegroundLayer(int par1, int par2) {
    ReikaTextureHelper.bindFontTexture();

    int j = (width - xSize) / 2;
    int k = (height - ySize) / 2;
    ReikaGuiAPI.instance.drawCenteredStringNoShadow(
        fontRendererObj,
        StatCollector.translateToLocal("chroma.routerfilter"),
        xSize / 2,
        5,
        0xffffff);

    for (int i = 0; i < 9; i++) {
      ItemRule ir = tile.getFilter(i);
      if (ir != null) {
        int x = 8 + i * 18;
        int y = 33;
        ReikaGuiAPI.instance.drawItemStack(
            itemRender, fontRendererObj, ReikaItemHelper.getSizedItemStack(ir.getItem(), 1), x, y);
        GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        ReikaGuiAPI.instance.drawRectFrame(x - 1, y - 1, 18, 18, 0xff000000 | ir.mode.color);
        GL11.glPopAttrib();
      }
    }
  }
  @Override
  public void updateEntity(World world, int x, int y, int z, int meta) {
    super.updateEntity(world, x, y, z, meta);

    if (!world.isRemote && this.getEnergy(CrystalElement.GREEN) >= 200) {
      int n = this.getNumberAttempts();
      for (int i = 0; i < n; i++) {
        Coordinate c = this.getRandomPosition(world, x, y, z);
        CropType crop = this.getCropAt(world, c);
        if (crop != null && crop.isRipe(world, c.xCoord, c.yCoord, c.zCoord)) {
          int fortune = this.getFortune();
          ArrayList<ItemStack> li = crop.getDrops(world, c.xCoord, c.yCoord, c.zCoord, fortune);
          if (fortune < 3) {
            CropMethods.removeOneSeed(crop, li);
          }
          ReikaItemHelper.dropItems(world, c.xCoord + 0.5, c.yCoord + 0.5, c.zCoord + 0.5, li);
          crop.setHarvested(world, c.xCoord, c.yCoord, c.zCoord);
          ReikaSoundHelper.playBreakSound(world, x, y, z, c.getBlock(world));
          this.drainEnergy(CrystalElement.GREEN, 200);
          this.drainEnergy(CrystalElement.PURPLE, 50);
          this.sendParticles(c);
          break;
        }
      }
    }
  }
 private boolean canCraft() {
   if (recipe instanceof FluidRecipe) {
     return this.canExportFluid(((FluidRecipe) recipe).fluid);
   }
   if (inv[1] == null) return true;
   return ReikaItemHelper.matchStacks(inv[1], recipe.output)
       && inv[1].stackSize + recipe.output.stackSize <= inv[1].getMaxStackSize();
 }
 public boolean upgrade() {
   if (bedrock) return false;
   bedrock = true;
   if (inv[9] != null)
     ReikaItemHelper.dropItem(worldObj, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, inv[9]);
   inv[9] = ItemStacks.bedrockdrill.copy();
   return true;
 }
  @Override
  public void updateTemperature(World world, int x, int y, int z, int meta) {
    int Tamb = ReikaWorldHelper.getAmbientTemperatureAt(world, x, y, z);
    if (ReikaWorldHelper.checkForAdjBlock(world, x, y, z, Blocks.snow) != null) Tamb -= 5;
    if (RotaryAux.isNextToWater(world, x, y, z)) Tamb -= 15;
    if (RotaryAux.isNextToIce(world, x, y, z)) Tamb -= 30;

    ItemStack cryo =
        GameRegistry.findItemStack(ModList.THERMALFOUNDATION.modLabel, "dustCryotheum", 1);
    if (ReikaItemHelper.matchStacks(ItemStacks.dryice, inv[1])
        || (cryo != null && ReikaItemHelper.matchStacks(cryo, inv[1]))) {
      Tamb -= 40;
      if (temperature > Tamb + 4 || rand.nextInt(20) == 0) ReikaInventoryHelper.decrStack(1, inv);
    }

    int dT = Tamb - temperature;
    temperature += dT / 4;
  }
 private boolean isValid(ItemStack is) {
   if (ReikaItemHelper.isBlock(is)) return true;
   if (ModList.IC2.isLoaded() && IC2Handler.IC2Stacks.SCRAPBOX.match(is)) return true;
   if (is.getItem().getClass() == lootBagClass) return true;
   if (ModList.MYSTCRAFT.isLoaded() && is.getItem() == MystCraftHandler.getInstance().folderID) {
     return true;
   }
   return false;
 }
 private void updateItem() {
   if (item == null && inv[0] == null) return;
   if ((item == null && inv[0] != null)
       || (item != null && inv[0] == null)
       || !ReikaItemHelper.matchStacks(item.getEntityItem(), inv[0])) {
     item = inv[0] != null ? new InertItem(worldObj, inv[0]) : null;
   }
   this.syncAllData(true);
 }
 private boolean isValidForSlot(int index, ItemStack item) {
   for (int i = 0; i < mappings.length; i++) {
     ItemStack is = mappings[i];
     // ReikaJavaLibrary.pConsole(is);
     if (is != null) {
       if (ReikaItemHelper.matchStacks(item, is)) return false;
     }
   }
   return true;
 }
 private void processItem(World world, int x, int y, int z) {
   if (ReikaItemHelper.isBlock(inv[0])) {
     Block b = Block.getBlockFromItem(inv[0].getItem());
     ArrayList<ItemStack> li =
         b.getDrops(
             world, x, y, z, inv[0].getItemDamage(), this.getEnchantment(Enchantment.fortune));
     li = ReikaItemHelper.collateItemList(li);
     if (!li.isEmpty()) {
       inv[1] = li.remove(0);
       overflow.addAll(li);
     }
   } else if (ModList.IC2.isLoaded() && IC2Handler.IC2Stacks.SCRAPBOX.match(inv[0])) {
     inv[1] = Recipes.scrapboxDrops.getDrop(inv[0], false);
   } else if (ModList.MYSTCRAFT.isLoaded()
       && inv[0].getItem() == MystCraftHandler.getInstance().folderID) {
     List<ItemStack> li = ReikaMystcraftHelper.getPagesInFolder(this.getPlacer(), inv[0], true);
     if (!li.isEmpty()) {
       inv[1] = li.remove(0);
       overflow.addAll(li);
     }
   } else if (inv[0].getItem().getClass() == lootBagClass) {
     ArrayList<ItemStack> li = new ArrayList();
     int n = 8 + rand.nextInt(5);
     for (int i = 0; i < n; i++) {
       try {
         ItemStack is = (ItemStack) generateBagLoot.invoke(null, inv[0].getItemDamage(), rand);
         if (is != null) {
           li.add(is);
         }
       } catch (Exception e) {
         e.printStackTrace();
         this.writeError(e);
       }
     }
     li = ReikaItemHelper.collateItemList(li);
     if (!li.isEmpty()) {
       inv[1] = li.remove(0);
       overflow.addAll(li);
     }
   }
   ReikaInventoryHelper.decrStack(0, inv);
 }
 private void checkAndMatchInventory() {
   ItemStack sapling = null;
   if (tree.isDyeTree()) {
     sapling = new ItemStack(TreeGetter.getSaplingID(), 1, tree.getDyeTreeMeta());
   } else if (tree.getTreeType() != null) {
     sapling = tree.getSapling();
   }
   if (!ReikaItemHelper.matchStacks(inv[0], sapling)) {
     this.dumpInventory();
   }
 }
  @Override
  public final void drop() {
    // ReikaItemHelper.dropItem(worldObj, xCoord+0.5, yCoord+0.5, zCoord+0.5,
    // this.getTile().getCraftedProduct());

    ItemStack is = this.getTile().getCraftedProduct();
    is.stackTagCompound = new NBTTagCompound();
    this.getTagsToWriteToStack(is.stackTagCompound);
    ReikaItemHelper.dropItem(worldObj, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, is);
    this.delete();
  }
 private boolean shouldPlantSapling() {
   if (this.hasEnchantment(Enchantment.infinity)) return true;
   if (treeCopy.isDyeTree()) {
     return inv[0] != null
         && inv[0].stackSize > 0
         && Block.getBlockFromItem(inv[0].getItem()) == TreeGetter.getSaplingID();
   } else if (treeCopy.getTreeType() != null) {
     return inv[0] != null
         && inv[0].stackSize > 0
         && ReikaItemHelper.matchStacks(inv[0], treeCopy.getSapling());
   } else return false;
 }
  @Override
  public void harvestBlock(World world, EntityPlayer ep, int x, int y, int z, int meta) {
    ChromaTiles c = ChromaTiles.getTile(world, x, y, z);
    if (c == null) return;
    if (c == ChromaTiles.PYLON) {

    } else {
      boolean silk = EnchantmentHelper.getSilkTouchModifier(ep);
      TileEntity tile = world.getTileEntity(x, y, z);
      if (silk) {
        ItemStack is = c.getCraftedProduct();
        if (tile instanceof TileEntityAccelerator) {
          TileEntityAccelerator te = (TileEntityAccelerator) tile;
          if (is.stackTagCompound == null) is.stackTagCompound = new NBTTagCompound();
          is.stackTagCompound.setInteger("tier", te.getTier());
        }
        ReikaItemHelper.dropItem(world, x + 0.5, y + 0.5, z + 0.5, is);
      } else {
        ReikaItemHelper.dropItems(world, x + 0.5, y + 0.5, z + 0.5, this.getPieces(world, x, y, z));
      }
    }
  }
  @Override
  public void onDeath(DamageSource src) {
    ChromaSounds.DISCHARGE.playSound(this, 1F, 2F);
    if (!worldObj.isRemote) {
      Entity e = src.getEntity();
      if (e instanceof EntityPlayer) {
        EntityPlayer ep = (EntityPlayer) e;
        if (doDrops && !ReikaPlayerAPI.isFakeOrNotInteractable(ep, posX, posY, posZ, 8)) {
          int looting = EnchantmentHelper.getLootingModifier((EntityPlayer) src.getEntity());
          ReikaItemHelper.dropItem(
              this,
              ReikaItemHelper.getSizedItemStack(
                  ChromaStacks.beaconDust, rand.nextInt(1 + looting * 2)));
          if (looting > 1) {
            if (color.isPrimary()) ReikaItemHelper.dropItem(this, ChromaStacks.purityDust);
            else ReikaItemHelper.dropItem(this, ChromaStacks.auraDust);
          }
        }
        ProgressStage.BALLLIGHTNING.stepPlayerTo(ep);
      }

      this.sendDeathParticles();
    }
  }
 public void throughPut() {
   for (int i = 1; i < 4; i++) {
     if (inv[i + 3] != null) {
       if (inv[i] == null) {
         inv[i] = inv[i + 3];
         inv[i + 3] = null;
       } else if (inv[i].stackSize < inv[i].getMaxStackSize()) {
         if (ReikaItemHelper.matchStacks(inv[i], inv[i + 3])) {
           inv[i].stackSize++;
           ReikaInventoryHelper.decrStack(i + 3, inv);
         }
       }
     }
   }
 }
 private ForgeDirection getSideForItem(ItemStack is) {
   for (int k = 0; k < mappings.length; k++) {
     ItemStack map = mappings[k];
     if (map != null) {
       Item item = is.getItem();
       Item item2 = map.getItem();
       if (item.getHasSubtypes() || item2.getHasSubtypes()) {
         if (ReikaItemHelper.matchStacks(map, is)) return this.getDirection(k);
       } else {
         if (is.getItem() == map.getItem()) return this.getDirection(k);
       }
     }
   }
   return ForgeDirection.DOWN;
 }
 private void dropItems(World world, int x, int y, int z, Collection<ItemStack> li) {
   for (ItemStack is : li) {
     boolean flag = true;
     for (int i = 0; i < 6 && flag; i++) {
       TileEntity te = this.getAdjacentTileEntity(dirs[i]);
       if (te instanceof IInventory) {
         if (ReikaInventoryHelper.addToIInv(is, (IInventory) te)) flag = false;
       }
     }
     if (flag) {
       ReikaItemHelper.dropItem(world, x + 0.5, y + 1.5, z + 0.5, is);
       dropFlag = true;
       this.doDropWarning(world, x, y, z);
     }
   }
 }
 @Override
 public boolean isItemValidForSlot(int slot, ItemStack is) {
   if (slot > 3 && slot < 9) return false;
   if (slot == 0)
     return ReikaBlockHelper.isOre(is)
         || CustomExtractLoader.instance.getEntryFromOreBlock(is) != null;
   if (ItemRegistry.EXTRACTS.matchItem(is)) {
     return slot == 1 + is.getItemDamage() / 8;
   } else if (ItemRegistry.MODEXTRACTS.matchItem(is)) {
     return slot == 1 + is.getItemDamage() % 4;
   } else if (ItemRegistry.CUSTOMEXTRACT.matchItem(is)) {
     return slot == 1 + is.getItemDamage() % 4;
   }
   if (slot == 9)
     return !bedrock
         && ConfigRegistry.EXTRACTORMAINTAIN.getState()
         && ReikaItemHelper.matchStacks(is, ItemStacks.drill);
   return false;
 }
 private void sortItems(World world, int x, int y, int z, List<EntityItem> li) {
   for (EntityItem ei : li) {
     ItemStack is = ei.getEntityItem();
     if (is.stackSize <= 1) ei.setDead();
     else {
       is.stackSize--;
     }
     ForgeDirection dir = this.getSideForItem(is);
     double dx = x + 0.5 + dir.offsetX * 0.75;
     double dy = y + 0.5 + dir.offsetY * 0.75;
     double dz = z + 0.5 + dir.offsetZ * 0.75;
     EntityItem e = new EntityItem(world, dx, dy, dz, ReikaItemHelper.getSizedItemStack(is, 1));
     double v = 0.1;
     e.motionX = dir.offsetX * v;
     e.motionY = dir.offsetY * v;
     e.motionZ = dir.offsetZ * v;
     world.spawnEntityInWorld(e);
   }
 }