/**
   * Sets the given item stack to the specified slot in the inventory (can be crafting or armor
   * sections).
   */
  public void setContents(ItemStack par2ItemStack) {
    for (int x = 0; x < 27; x++) {
      if (this.poubelleContents[x] != null
          && this.poubelleContents[x].getItem().shiftedIndex
              == par2ItemStack.getItem().shiftedIndex) {
        int max = this.poubelleContents[x].stackSize + par2ItemStack.stackSize;
        if (par2ItemStack.getItem().getHasSubtypes()) {

        } else if (max > 64) {
          this.poubelleContents[x].stackSize = 64;
          par2ItemStack.stackSize = max - 64;
          this.onInventoryChanged();
        } else {
          this.poubelleContents[x].stackSize += par2ItemStack.stackSize;
          this.onInventoryChanged();
          break;
        }
      } else if (this.poubelleContents[x] == null) {
        this.poubelleContents[x] = par2ItemStack;

        if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit()) {
          par2ItemStack.stackSize = this.getInventoryStackLimit();
        }

        this.onInventoryChanged();
        break;
      }
    }
  }
  /** Called when the player picks up an item from an inventory slot */
  public void onPickupFromSlot(ItemStack par1ItemStack) {
    ModLoader.takenFromCrafting(this.thePlayer, par1ItemStack, this.craftMatrix);
    //        ForgeHooks.onTakenFromCrafting(thePlayer, par1ItemStack, craftMatrix); TODO

    this.func_48434_c(par1ItemStack);

    for (int var2 = 0; var2 < this.craftMatrix.getSizeInventory(); ++var2) {
      ItemStack var3 = this.craftMatrix.getStackInSlot(var2);

      if (var3 != null) {
        this.craftMatrix.decrStackSize(var2, 1);

        if (var3.getItem().hasContainerItem()) {
          ItemStack var4 = new ItemStack(var3.getItem().getContainerItem());

          if (!var3.getItem().doesContainerItemLeaveCraftingGrid(var3)
              || !this.thePlayer.inventory.addItemStackToInventory(var4)) {
            if (this.craftMatrix.getStackInSlot(var2) == null) {
              this.craftMatrix.setInventorySlotContents(var2, var4);
            } else {
              this.thePlayer.dropPlayerItem(var4);
            }
          }
        }
      }
    }
  }
  @Override
  public int execute(
      EAI_Manager manager, EntityLiving entity, IInventory inventory, int slotnum, int maxcol) {
    super.execute(manager, entity, inventory, slotnum, maxcol);

    // 食べ物を持ってたら食べる。次へ進む
    //
    // ロジックをなるだけ壊さないように、検索は後ろから
    for (int i = inventory.getSizeInventory() - 1; i > 0; i--) {
      ItemStack stack = inventory.getStackInSlot(i);
      if (stack != null && stack.getItem() instanceof ItemFood) {
        UtilInventory.decrStackSize(inventory, i, 1); // アイテムを 1 つ減らす
        ItemFood food = (ItemFood) stack.getItem();

        entity.worldObj.playSoundEffect(
            entity.posX,
            entity.posY,
            entity.posZ,
            "random.eat",
            0.5F,
            entity.worldObj.rand.nextFloat() * 0.1F + 0.9F);

        entity.setEating(true);
        entity.setEntityHealth(entity.getHealth() + 1); // HP を 1 回復する
        EasyAIInterface.debugPrint("[EAI_TASK_eatFood] Eat Food " + stack + " " + slotnum);

        return this.returnTrue();
      }
    }
    return this.returnFalse();
  }
  /**
   * Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if
   * the item isn't fuel
   */
  public static int getItemBurnTime(ItemStack par0ItemStack) {
    if (par0ItemStack == null) {
      return 0;
    } else {
      int var1 = par0ItemStack.getItem().shiftedIndex;
      Item var2 = par0ItemStack.getItem();

      if (var1 < 256 && Block.blocksList[var1] != null) {
        Block var3 = Block.blocksList[var1];

        if (var3 == Block.blockSnow) {
          return 300;
        }

        if (var3 == Block.ice) {
          return 800;
        }

        if (var3 == Block.oreRedstone) {
          return 500;
        }
      }

      return var1 == Item.emerald.shiftedIndex ? 1000 : 0;
    }
  }
  @Override
  public void doAction(IInventory matrix, DaemonEnergy energy) {
    int size = DaemonMatrix.MATRIX_SIZE;
    int orb = -1;
    ItemOrb orbItem = null;
    int lastSlot = 0;

    // find 1st orb
    for (; lastSlot < size; lastSlot++) {
      ItemStack stack = matrix.getStackInSlot(lastSlot);
      if (stack != null && stack.getItem() instanceof ItemOrb) {
        orb = lastSlot;
        orbItem = (ItemOrb) stack.getItem();
        break;
      }
    }
    if (orb < 0) return;

    // charge with glass shard if possible
    for (int i = 0; i < size; i++) {
      ItemStack stack = matrix.getStackInSlot(i);
      if (stack != null
          && stack.getItem() instanceof ItemShardGlass
          && stack.getItemDamage() >= ItemShardGlass.DAMAGE_CHARGED) {
        matrix.setInventorySlotContents(i, null);
        orbItem.chargeOrb(matrix.getStackInSlot(orb));
        return;
      }
    }

    // charge with crystal
    for (int i = 0; i < size; i++) {
      ItemStack stack = matrix.getStackInSlot(i);
      if (stack != null && stack.getItem() instanceof ItemCrystal) {
        matrix.setInventorySlotContents(i, null);
        DaemonEnergy de = UtilItem.getDaemonEnergy(matrix.getStackInSlot(orb));
        DaemonEnergy de2 = UtilItem.getDaemonEnergy(stack);
        de.merge(de2);
        UtilItem.setDaemonEnergy(matrix.getStackInSlot(orb), de);
        return;
      }
    }

    for (lastSlot++; lastSlot < size; lastSlot++) {
      ItemStack stack = matrix.getStackInSlot(lastSlot);
      if (stack != null && stack.getItem() instanceof ItemOrb) {
        matrix.setInventorySlotContents(orb, orbItem.mergeOrbs(matrix.getStackInSlot(orb), stack));
        matrix.setInventorySlotContents(lastSlot, null);
        return;
      }
    }
  }
 public int getPercentageCapacity() {
   ItemStack linkCard = getPowerLinkStack();
   if (hasPowerSource()) {
     return ((IPowerLinkItem) linkCard.getItem()).getPercentageCapacity(linkCard, this, worldObj);
   }
   return 0;
 }
 public static void preRender(ItemStack itemStack) {
   if (renderingEnchantment) {
     // rendering custom enchantment -- keep current state
   } else if (itemStack == null) {
     clear();
   } else if (itemStack.getItem() instanceof ItemBlock) {
     clear();
     ctm = CTMUtils18.getInstance();
     ctm.preRenderHeld(
         null, ((ItemBlock) itemStack.getItem()).getBlock(), itemStack.getItemDamage());
   } else {
     ctm = null;
     currentItem = itemStack;
     itemOverride = CITUtils.findItemOverride(itemStack);
   }
 }
 @Override
 public boolean isItemValid(ItemStack itemstack) {
   if (itemstack.getItem().shiftedIndex == item.shiftedIndex) {
     if (damage == -1) return true;
     else return itemstack.getItemDamage() == damage;
   } else return false;
 }
  @Override
  public boolean isItemValid(ItemStack par1ItemStack, int Slot) {

    if (par1ItemStack.getItem() instanceof ItemCardPersonalID) return true;

    return false;
  }
 public int getMaximumPower() {
   ItemStack linkCard = getPowerLinkStack();
   if (hasPowerSource()) {
     return ((IPowerLinkItem) linkCard.getItem()).getMaximumPower(linkCard, this, worldObj);
   }
   return 0;
 }
 public boolean usePower(int powerAmount, boolean simulation) {
   ItemStack linkCard = getPowerLinkStack();
   if (hasPowerSource()) {
     return ((IPowerLinkItem) linkCard.getItem())
         .consumePower(linkCard, powerAmount, simulation, this, worldObj);
   }
   return false;
 }
 public static int getItemBurnTime(ItemStack par1ItemStack) {
   if (par1ItemStack == null) {
     return 0;
   } else {
     int var1 = par1ItemStack.getItem().shiftedIndex;
     if (var1 == Item.redstone.shiftedIndex) return 600;
   }
   return 0;
 }
  /** Called to transfer a stack from one inventory to the other eg. when shift clicking. */
  @Override
  public ItemStack transferStackInSlot(int par1) {
    ItemStack var2 = null;
    Slot var3 = (Slot) this.inventorySlots.get(par1);

    if (var3 != null && var3.getHasStack()) {
      ItemStack var4 = var3.getStack();
      var2 = var4.copy();

      if (par1 != 0 && par1 != 1) {
        if (var4.getItem() instanceof ItemElectric) {
          if (((ItemElectric) var4.getItem()).canProduceElectricity()) {
            if (!this.mergeItemStack(var4, 1, 2, false)) {
              return null;
            }
          } else {
            if (!this.mergeItemStack(var4, 0, 1, false)) {
              return null;
            }
          }
        } else if (par1 >= 30 && par1 < 38 && !this.mergeItemStack(var4, 3, 30, false)) {
          return null;
        }
      } else if (!this.mergeItemStack(var4, 3, 38, false)) {
        return null;
      }

      if (var4.stackSize == 0) {
        var3.putStack((ItemStack) null);
      } else {
        var3.onSlotChanged();
      }

      if (var4.stackSize == var2.stackSize) {
        return null;
      }

      var3.onPickupFromSlot(var4);
    }

    return var2;
  }
  protected void func_48434_c(ItemStack par1ItemStack) {
    par1ItemStack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.field_48436_g);
    this.field_48436_g = 0;

    if (Util.isWooden(par1ItemStack)
        || Util.isStone(par1ItemStack)
        || Util.isIron(par1ItemStack)
        || Util.isGold(par1ItemStack)
        || Util.isDiamond(par1ItemStack)) {
      ItemCrossbow item = (ItemCrossbow) par1ItemStack.getItem();
      //            this.thePlayer.addStat(mod_CrossbowMod.createCrossbow, 1); TODO
    }
  }
  @Override
  public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer) {
    if (mod_TFC.proxy.isRemote()) {
      return true;
    } else {
      if ((TileEntityTerraLogPile) world.getBlockTileEntity(i, j, k) != null) {
        TileEntityTerraLogPile te;
        te = (TileEntityTerraLogPile) world.getBlockTileEntity(i, j, k);
        ItemStack is = entityplayer.getCurrentEquippedItem();

        if (is != null && is.getItem().shiftedIndex == TFCItems.Logs.shiftedIndex) {
          return false;
        } else {
          entityplayer.openGui(mod_TFC.instance, mod_TFC.logPileGuiId, world, i, j, k);
        }
        return true;
      } else {
        return false;
      }
    }
  }
 public static short getFuelValueFor(ItemStack itemstack) {
   if (itemstack == null) {
     return 0;
   }
   int i = itemstack.getItem().shiftedIndex;
   if (i < 256 && Block.blocksList[i].blockMaterial == Material.wood) {
     return 300;
   }
   if (i == Item.stick.shiftedIndex) {
     return 100;
   }
   if (i == Item.coal.shiftedIndex) {
     return 1600;
   }
   if (i == Item.bucketLava.shiftedIndex) {
     return 2000;
   }
   if (i == Block.sapling.blockID) {
     return 100;
   } else {
     return (short) ModLoader.addAllFuel(i, itemstack.getItemDamage());
   }
 }
 private boolean isItemStackKey(ItemStack stack) {
   return (stack != null && stack.getItem() instanceof ItemKey);
 }
 private boolean isItemStackLock(ItemStack stack) {
   return (stack != null && stack.getItem() instanceof ItemLock);
 }
  @Override
  public boolean iteratePattern(TileEntity tile, IBox box, ItemStack stackToPlace) {
    int xMin = (int) box.pMin().x;
    int yMin = (int) box.pMin().y;
    int zMin = (int) box.pMin().z;

    int xMax = (int) box.pMax().x;
    int zMax = (int) box.pMax().z;

    int sizeX = xMax - xMin + 1;
    int sizeZ = zMax - zMin + 1;

    boolean[][] blockedColumns = new boolean[sizeX][sizeZ];

    for (int i = 0; i < blockedColumns.length; ++i) {
      for (int j = 0; j < blockedColumns[0].length; ++j) {
        blockedColumns[i][j] = false;
      }
    }

    boolean found = false;
    int lastX = Integer.MAX_VALUE, lastY = Integer.MAX_VALUE, lastZ = Integer.MAX_VALUE;

    for (int y = yMin - 1; y >= 0; --y) {
      found = false;
      for (int x = xMin; x <= xMax; ++x) {
        for (int z = zMin; z <= zMax; ++z) {
          if (!BlockUtil.canChangeBlock(tile.worldObj, x, y, z)) {
            return true;
          }
          if (!blockedColumns[x - xMin][z - zMin]) {
            if (!BlockUtil.isSoftBlock(tile.worldObj, x, y, z)) {
              blockedColumns[x - xMin][z - zMin] = true;
            } else {
              found = true;
              lastX = x;
              lastY = y;
              lastZ = z;
            }
          }
        }
      }

      if (!found) {
        break;
      }
    }

    if (lastX != Integer.MAX_VALUE && stackToPlace != null) {
      stackToPlace
          .getItem()
          .onItemUse(
              stackToPlace,
              CoreProxy.proxy.getBuildCraftPlayer(tile.worldObj),
              tile.worldObj,
              lastX,
              lastY - 1,
              lastZ,
              1,
              0.0f,
              0.0f,
              0.0f);
    }

    if (lastX != Integer.MAX_VALUE) {
      return false;
    }

    return !empty(xMin, yMin, zMin, xMax, 64 * 2, zMax, tile.worldObj);
  }
 public boolean hasPowerSource() {
   ItemStack linkCard = getPowerLinkStack();
   if (linkCard != null && linkCard.getItem() instanceof IPowerLinkItem) return true;
   return false;
 }